FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
FEAT::StringMapped< ValueType_ > Class Template Reference

String-Mapped class template. More...

#include <string_mapped.hpp>

Public Member Functions

 StringMapped (ValueType_ &value, const std::map< String, ValueType_ > &value_map)
 Constructor. More...
 
bool lookup (const String &str)
 Looks up the value in the map from a given string. More...
 

Private Attributes

ValueType_ & _value
 the value More...
 
const std::map< String, ValueType_ > & _value_map
 the string map More...
 

Friends

std::ostream & operator<< (std::ostream &os, const StringMapped &val)
 Output stream insertion operator. More...
 
std::istream & operator>> (std::istream &is, StringMapped &val)
 Input stream extraction operator. More...
 

Detailed Description

template<typename ValueType_>
class FEAT::StringMapped< ValueType_ >

String-Mapped class template.

This class implements an auxiliary class that can be used to look up a value of a specific type from a map of strings. The primary use of this class is to parse enumeration values from the set of command line arguments by using the SimpleArgParser class.

Template Parameters
ValueType_The type of the value that is to be mapped. Must be copy-assignable.
Author
Peter Zajac

Definition at line 31 of file string_mapped.hpp.

Constructor & Destructor Documentation

◆ StringMapped()

template<typename ValueType_ >
FEAT::StringMapped< ValueType_ >::StringMapped ( ValueType_ &  value,
const std::map< String, ValueType_ > &  value_map 
)
inlineexplicit

Constructor.

Parameters
[in]valueA resident reference to the value to be looked up.
[in]value_mapA resident const reference to the value map to be used for lookup.

Definition at line 49 of file string_mapped.hpp.

Member Function Documentation

◆ lookup()

template<typename ValueType_ >
bool FEAT::StringMapped< ValueType_ >::lookup ( const String str)
inline

Looks up the value in the map from a given string.

This function parses the input string by looking up the corresponding value in the underlying string-value map and saves the corresponding value in this object's variable reference. If the string was not found in the underlying map, the internal value of this object is left unmodified.

Parameters
[in]strThe string that is to be looked up.
Returns
true, if string represents a valid key in the underlying map, or false, if the string was not found in the map.

Definition at line 69 of file string_mapped.hpp.

References FEAT::StringMapped< ValueType_ >::_value, and FEAT::StringMapped< ValueType_ >::_value_map.

Friends And Related Function Documentation

◆ operator<<

template<typename ValueType_ >
std::ostream & operator<< ( std::ostream &  os,
const StringMapped< ValueType_ > &  val 
)
friend

Output stream insertion operator.

Parameters
[in,out]osThe output stream to insert to.
[in]valA rvalue-reference to the string mapped value to insert.
Returns
os

Definition at line 136 of file string_mapped.hpp.

◆ operator>>

template<typename ValueType_ >
std::istream & operator>> ( std::istream &  is,
StringMapped< ValueType_ > &  val 
)
friend

Input stream extraction operator.

Parameters
[in,out]isThe input stream to extract from.
[in]valA rvalue-reference to the string mapped value to extract.
Returns
is

Definition at line 92 of file string_mapped.hpp.

Member Data Documentation

◆ _value

template<typename ValueType_ >
ValueType_& FEAT::StringMapped< ValueType_ >::_value
private

the value

Definition at line 35 of file string_mapped.hpp.

Referenced by FEAT::StringMapped< ValueType_ >::lookup().

◆ _value_map

template<typename ValueType_ >
const std::map<String, ValueType_>& FEAT::StringMapped< ValueType_ >::_value_map
private

the string map

Definition at line 37 of file string_mapped.hpp.

Referenced by FEAT::StringMapped< ValueType_ >::lookup().


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