Loading...
Searching...
No Matches
restinio::impl::overflow_controlled_integer_accumulator_t< T, Multiplier, Extremum_Type > Class Template Reference

Helper class for accumulating integer value during parsing it from string (with check for overflow). More...

`#include <overflow_controlled_integer_accumulator.hpp>`

## Public Member Functions

void | next_digit (T digit) noexcept
| Try to add another digit to the accumulator.
bool | overflow_detected () const noexcept
| Is overflow detected during previous call to next_digit?
T | value () const noexcept
| Get the current accumulator value.

## Private Types

using | extremum_value = overflow_controlled_integer_accumulator_details::extremum_value< T, Extremum_Type >
using | storage_type = typename extremum_value::storage_type
| Type to be used for holding intermediate value.

## Private Attributes

storage_type | m_current {}
| The current value of the accumulator.
bool | m_overflow_detected { false }
| Overflow detection flag.

## Detailed Description

template<typename T, int Multiplier, typename Extremum_Type = check_positive_extremum>
class restinio::impl::overflow_controlled_integer_accumulator_t< T, Multiplier, Extremum_Type >

Helper class for accumulating integer value during parsing it from string (with check for overflow).

Usage example:

int parse_int(string_view_t str) {
overflow_controlled_integer_accumulator_t<int> acc;
for(const auto ch : str) {
if(!is_digit(ch))
throw not_a_digit(ch);
acc.next_digit(ch);
if(acc.overflow_detected())
throw too_big_value();
}
return acc.value();
}
restinio::impl::overflow_controlled_integer_accumulator_t
Helper class for accumulating integer value during parsing it from string (with check for overflow).
Definition: overflow_controlled_integer_accumulator.hpp:136
restinio::impl::overflow_controlled_integer_accumulator_t::next_digit
void next_digit(T digit) noexcept
Try to add another digit to the accumulator.
Definition: overflow_controlled_integer_accumulator.hpp:156
restinio::impl::overflow_controlled_integer_accumulator_t::value
T value() const noexcept
Get the current accumulator value.
Definition: overflow_controlled_integer_accumulator.hpp:183
restinio::impl::overflow_controlled_integer_accumulator_t::overflow_detected
bool overflow_detected() const noexcept
Is overflow detected during previous call to next_digit?
Definition: overflow_controlled_integer_accumulator.hpp:176
restinio::string_view_t
nonstd::string_view string_view_t
Definition: string_view.hpp:19

Note
  Since v.0.6.6 it can be used for parcing not only decinal numbers, but also numbers with base of Multiplier.
  Since v.0.6.6 it can be used for parsing digits of negative decimal numbers. In that case it should be used like that:
  char ch = next_char();
  if('-' == ch) {
  // Digits of negative number should be extracted.
  overflow_controlled_integer_accumulator_t<
  int,
  check_negative_extremum > acc;
  ...
  }
  restinio::impl::check_negative_extremum
  Definition: overflow_controlled_integer_accumulator.hpp:33

Since
  v.0.6.2

Definition at line 135 of file overflow_controlled_integer_accumulator.hpp.

## Member Typedef Documentation

## extremum_value

template<typename T , int Multiplier, typename Extremum_Type = check_positive_extremum>

using restinio::impl::overflow_controlled_integer_accumulator_t< T, Multiplier, Extremum_Type >::extremum_value = overflow_controlled_integer_accumulator_details::extremum_value< T, Extremum_Type >

private

Definition at line 137 of file overflow_controlled_integer_accumulator.hpp.

## storage_type

template<typename T , int Multiplier, typename Extremum_Type = check_positive_extremum>

using restinio::impl::overflow_controlled_integer_accumulator_t< T, Multiplier, Extremum_Type >::storage_type = typename extremum_value::storage_type

private

Type to be used for holding intermediate value.

Definition at line 143 of file overflow_controlled_integer_accumulator.hpp.

## Member Function Documentation

## next_digit()

template<typename T , int Multiplier, typename Extremum_Type = check_positive_extremum>

void restinio::impl::overflow_controlled_integer_accumulator_t< T, Multiplier, Extremum_Type >::next_digit | ( | T | digit | ) |

inline noexcept

Try to add another digit to the accumulator.

Value of the accumulator will be changed only if there is no overflow.

Definition at line 156 of file overflow_controlled_integer_accumulator.hpp.

## overflow_detected()

template<typename T , int Multiplier, typename Extremum_Type = check_positive_extremum>

bool restinio::impl::overflow_controlled_integer_accumulator_t< T, Multiplier, Extremum_Type >::overflow_detected | ( |  | ) | const

inline noexcept

Is overflow detected during previous call to next_digit?

Definition at line 176 of file overflow_controlled_integer_accumulator.hpp.

## value()

template<typename T , int Multiplier, typename Extremum_Type = check_positive_extremum>

T restinio::impl::overflow_controlled_integer_accumulator_t< T, Multiplier, Extremum_Type >::value | ( |  | ) | const

inline noexcept

Get the current accumulator value.

Definition at line 183 of file overflow_controlled_integer_accumulator.hpp.

## Member Data Documentation

## m_current

template<typename T , int Multiplier, typename Extremum_Type = check_positive_extremum>

storage_type restinio::impl::overflow_controlled_integer_accumulator_t< T, Multiplier, Extremum_Type >::m_current {}

private

The current value of the accumulator.

Definition at line 146 of file overflow_controlled_integer_accumulator.hpp.

## m_overflow_detected

template<typename T , int Multiplier, typename Extremum_Type = check_positive_extremum>

bool restinio::impl::overflow_controlled_integer_accumulator_t< T, Multiplier, Extremum_Type >::m_overflow_detected { false }

private

Overflow detection flag.

Definition at line 148 of file overflow_controlled_integer_accumulator.hpp.

The documentation for this class was generated from the following file:

- restinio/impl/overflow_controlled_integer_accumulator.hpp