PLaSK library
|
Objects of this class allow to parse string value and interpret it as given type. More...
#include <plask/utils/xml/reader.hpp>
Public Member Functions | |
template<typename... Functors> | |
StringInterpreter (Functors... parsers) | |
Construct StringInterpreter which uses given parsers for types returned by this parsers, and boost::lexical_cast for other types. | |
StringInterpreter (StringInterpreter &&)=default | |
StringInterpreter (const StringInterpreter &)=default | |
StringInterpreter & | operator= (StringInterpreter &&)=default |
StringInterpreter & | operator= (const StringInterpreter &)=default |
template<typename RequiredType > | |
RequiredType | get (const std::string &str) const |
Parse given text str, interpret it as type RequiredType . | |
template<typename Functor1 , typename... Functors> | |
void | set (Functor1 parser1, Functors... rest_parsers) |
Set parsers to use (interpret attributes values, etc.) for conversion from std::string to type returned by each parser. | |
template<typename type > | |
void | unset () |
Unset parser to use (interpret attributes values, etc.) for conversion from std::string to given type. | |
Objects of this class allow to parse string value and interpret it as given type.
By default boost::lexical_cast is used to parse, but this can be changed, for each required result type, to custom parser.
Definition at line 47 of file reader.hpp.
|
inline |
Construct StringInterpreter which uses given parsers for types returned by this parsers, and boost::lexical_cast for other types.
parsers | 0 or more custom parsers, functors which can take std::string and return value of some type, or throw exception in case of parsing error |
Definition at line 63 of file reader.hpp.
|
default |
|
default |
|
inline |
Parse given text str, interpret it as type RequiredType
.
For parsing, it uses registered interpreter or boost::lexical_cast.
It throws exception in case of parsing error.
str | text to parse |
str interpreted
as type RequiredType
Definition at line 80 of file reader.hpp.
|
default |
|
default |
Set parsers to use (interpret attributes values, etc.) for conversion from std::string to type returned by each parser.
parser1,rest_parsers | 1 or more functors which can take std::string and return value of some type, or throw exception in case of parsing error |
Definition at line 93 of file reader.hpp.
Unset parser to use (interpret attributes values, etc.) for conversion from std::string to given type.
Default lexical_cast will be used for given type after calling this.
type | type returned by parser to unregister |
Definition at line 105 of file reader.hpp.