plptools
Loading...
Searching...
No Matches
EnumBase::i2sMapper Class Reference

maps integers (typically: enumeration values) to Strings. More...

#include <Enum.h>

Public Member Functions

void add (long, const char *)
 adds a new int -> string mapping Does NOT take over responsibility for the pointer (i.e. More...
 
std::string lookup (long) const
 returns the string representation for this integer. More...
 
long lookup (const char *) const
 returns the integer associated with the given string or -1 if the value is not found (XXX: this should throw an exception). More...
 
bool inRange (long) const
 returns true, if we have an representation for the given integer. More...
 

Private Types

typedef std::multimap< long, const char * > i2s_map_t
 there can be one value, mapping to multiple strings. More...
 

Private Attributes

i2s_map_t stringMap
 just for the record. More...
 

Detailed Description

maps integers (typically: enumeration values) to Strings.

Takes care of the fact, that an Integer may map to multiple strings (sometimes multiple enumeration values represent the same integer).

Provides a means to get the string representation of an integer and vice versa.

Author
Henner Zeller

Definition at line 52 of file Enum.h.

Member Typedef Documentation

◆ i2s_map_t

typedef std::multimap<long, const char*> EnumBase::i2sMapper::i2s_map_t
private

there can be one value, mapping to multiple strings.

Therefore, we need a multimap.

Definition at line 58 of file Enum.h.

Member Function Documentation

◆ add()

void EnumBase::i2sMapper::add ( long  i,
const char *  s 
)

adds a new int -> string mapping Does NOT take over responsibility for the pointer (i.e.

it is not freed), so it is save to add constant strings provided in the program code.

Definition at line 28 of file Enum.cc.

◆ inRange()

bool EnumBase::i2sMapper::inRange ( long  i) const

returns true, if we have an representation for the given integer.

Definition at line 70 of file Enum.cc.

◆ lookup() [1/2]

long EnumBase::i2sMapper::lookup ( const char *  s) const

returns the integer associated with the given string or -1 if the value is not found (XXX: this should throw an exception).

Definition at line 53 of file Enum.cc.

◆ lookup() [2/2]

string EnumBase::i2sMapper::lookup ( long  i) const

returns the string representation for this integer.

If there are multiple strings for this integer, return a comma delimited list.

Definition at line 32 of file Enum.cc.

Member Data Documentation

◆ stringMap

i2s_map_t EnumBase::i2sMapper::stringMap
private

just for the record.

Mapping back a string to the Integer value in question. Since Symbols must be unique, there is only a 1:1 relation as opposed to i2s_map_t. So we can use a normal map here.

Since in the usual application, mapping a string back to its value is not important performance wise (typically in a frontend), so it is implemented as exhaustive search, not as extra map. Saves some bits of memrory ..

Definition at line 73 of file Enum.h.


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