Template Class EnumWrapper

Class Documentation

template<typename E>
class EnumWrapper

A helper class to make configuring enums easier with boost::program_options.

This class provides a templated implementation of the instream operator necessary for enums to be read by boost::program_options. Also provided is a macro which will format the map that is required to go from the string representation in the config file to the values of the enum.

Public Types

typedef std::map<std::string, E> MapType

Public Functions

inline E operator()(const std::string &key)

Set and return the value of the wrapped enum, based on the passed string and the set map.

Parameters:

key – a key corresponding to one in the templated map which will set the value of the wrapped enum.

inline operator E() const

Cast the wrapped enum back to a plain one.

Public Static Functions

static inline void setMap(const MapType &inMap)

Set the mapping between strings and enum types

Parameters:

inMap – the mapping to be used.

Friends

friend std::istream &operator>>(std::istream &is, EnumWrapper<E>&)

A templated input operator that uses the defined map to set the value of the wrapped enum.