powerd++  0.4.4
Public Member Functions | Public Attributes | List of all members
utility::FromChars Struct Reference

A functor for reading numerical values from a string or character array. More...

#include <utility.hpp>

Public Member Functions

template<typename T >
bool operator() (T &dst)
 Retrieve an integral or floating point value from the array. More...
 
 operator bool () const
 Check if unread characters remain. More...
 
 FromChars (char const *const start, char const *const end)
 Range based constructor. More...
 
template<size_t CountV>
 FromChars (char const (&str)[CountV], bool const terminator=true)
 Construct from a character array. More...
 
 FromChars (std::string const &str)
 Construct functor from a string. More...
 

Public Attributes

const char * it
 The next character to read.
 
const char *const end
 The first character of the same array that may not be read, this should usually point to a terminating zero or behind a buffer.
 

Detailed Description

A functor for reading numerical values from a string or character array.

Constructor & Destructor Documentation

◆ FromChars() [1/3]

utility::FromChars::FromChars ( char const *const  start,
char const *const  end 
)
inline

Range based constructor.

Parameters
start,endThe character array range

◆ FromChars() [2/3]

template<size_t CountV>
utility::FromChars::FromChars ( char const (&)  str[CountV],
bool const  terminator = true 
)
inline

Construct from a character array.

Template Parameters
CountVThe number of characters
Parameters
strThe character array to parse from
terminatorIndicates whether the character array has a terminating null character.

◆ FromChars() [3/3]

utility::FromChars::FromChars ( std::string const &  str)
inline

Construct functor from a string.

Note that changing the string during the lifetime of the functor may silently invalidate the functor's state and thus invoke undefined behaviour.

Parameters
strThe string to parse from

Member Function Documentation

◆ operator bool()

utility::FromChars::operator bool ( ) const
inline

Check if unread characters remain.

Return values
falseAll characters have been read
trueCharacters remain to be read

◆ operator()()

template<typename T >
bool utility::FromChars::operator() ( T &  dst)
inline

Retrieve an integral or floating point value from the array.

The operation may fail for multiple reasons:

  • No more characters left to read, in that case the functor will equal false
  • The given characters do not represent a valid value, in that case the functor will equal true
Template Parameters
TThe value type to retrieve
Parameters
dstThe lvalue to assign to
Return values
trueThe numerical value was successfully read from the array
falseThe numerical value could not be read from the array

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