PLaSK library

Loading...
Searching...
No Matches
Public Member Functions | List of all members
plask::StringInterpreter Class Reference

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.

## Detailed Description

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.

## Constructor & Destructor Documentation

## ◆ StringInterpreter() [1/3]

template<typename... Functors>

plask::StringInterpreter::StringInterpreter | ( | Functors... | parsers | ) |
| inline

Construct StringInterpreter which uses given parsers for types returned by this parsers, and boost::lexical_cast for other types.

Parameters

  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.

## ◆ StringInterpreter() [2/3]

plask::StringInterpreter::StringInterpreter | ( | StringInterpreter && |  | ) |
| default

## ◆ StringInterpreter() [3/3]

plask::StringInterpreter::StringInterpreter | ( | const StringInterpreter & |  | ) |
| default

## Member Function Documentation

## ◆ get()

template<typename RequiredType >

RequiredType plask::StringInterpreter::get | ( | const std::string & | str | ) | const
| 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.

Parameters

  str | text to parse

Returns
  `str interpreted` as type `RequiredType`

Definition at line 80 of file reader.hpp.

## ◆ operator=() [1/2]

StringInterpreter & plask::StringInterpreter::operator= | ( | const StringInterpreter & |  | ) |
| default

## ◆ operator=() [2/2]

StringInterpreter & plask::StringInterpreter::operator= | ( | StringInterpreter && |  | ) |
| default

## ◆ set()

template<typename Functor1 , typename... Functors>

void plask::StringInterpreter::set | ( | Functor1 | parser1,
|  | Functors... | rest_parsers
| ) |  |
| inline

Set parsers to use (interpret attributes values, etc.) for conversion from std::string to type returned by each parser.

Parameters

  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()

template<typename type >

void plask::StringInterpreter::unset | ( |  | ) |
| inline

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.

Template Parameters

  type | type returned by parser to unregister

Definition at line 105 of file reader.hpp.

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

- plask/utils/xml/reader.hpp