plptools
Loading...
Searching...
No Matches
Enum.h File Reference
#include "config.h"
#include <assert.h>
#include <map>
#include <string>
#include "plpintl.h"
Include dependency graph for Enum.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  EnumBase
 the Base for the Enum template. More...
 
class  EnumBase::i2sMapper
 maps integers (typically: enumeration values) to Strings. More...
 
class  Enum< E >
 Wrapper class featuring range-checking and string representation of enumerated values. More...
 
struct  Enum< E >::sdata
 

Macros

#define ENUM_DEFINITION_BEGIN(EnumName, initWith)
 Helper macro to construct an enumeration wrapper Enum<E> for a specific enum type. More...
 
#define ENUM_DEFINITION_END(EnumName)   } template Enum< EnumName >::sdata Enum< EnumName >::staticData;
 

Functions

template<typename E >
std::ostreamoperator<< (std::ostream &out, const Enum< E > &e)
 Writes enumeration's string representation. More...
 

Macro Definition Documentation

◆ ENUM_DEFINITION_BEGIN

#define ENUM_DEFINITION_BEGIN (   EnumName,
  initWith 
)
Value:
\
name(#EnumName),defaultValue(initWith) {
sdata()
The constructor of the static data part.

Helper macro to construct an enumeration wrapper Enum<E> for a specific enum type.

It defines the static variable holding the static information and provides the head of its Constructor. You only have to provide the string-mapping additions in the constructor body. This macro behaves much like a function declaration, i.e. you have to start the constructor with { ..

usage example:

// declaration of enumeration; somewhere
class rfsv {
[...]
       enum PSI_ERROR_CODES { E_PSI_GEN_NONE, E_PSI_GEN_FAIL, E_PSI_GEN_ARG };
[...]
};

// definition of the Enum<E> with the appropriate string representations
ENUM_DEFINITION_BEGIN(rfsv::PSI_ERROR_CODES, rfsv::E_PSI_GEN_NONE)
    stringRep.add(rfsv::E_PSI_GEN_NONE, "no error");
    stringRep.add(rfsv::E_PSI_GEN_FAIL, "general");
    stringRep.add(rfsv::E_PSI_GEN_ARG,  "bad argument");
ENUM_DEFINITION_END(rfsv::PSI_ERROR_CODES)
Parameters
EnumNameThe fully qualified Name of the enum type to be wrapped
initWithThe fully qualified Name of the initialization value.
Author
Henner Zeller The definition of the static variable holding the static data for this Enumeration wrapper.

Definition at line 299 of file Enum.h.

◆ ENUM_DEFINITION_END

#define ENUM_DEFINITION_END (   EnumName)    } template Enum< EnumName >::sdata Enum< EnumName >::staticData;

Definition at line 304 of file Enum.h.

Function Documentation

◆ operator<<()

template<typename E >
std::ostream & operator<< ( std::ostream out,
const Enum< E > &  e 
)
inline

Writes enumeration's string representation.

Definition at line 311 of file Enum.h.