Public Types | Public Member Functions | Private Member Functions

FlagMap< OutputType > Class Template Reference

Maps names to constants. More...

#include <keyvalue/key/map/FlagMap.h>

List of all members.

Public Types

typedef OutputType OutputType_

Public Member Functions

OutputType map (const value::Variant &variant) const
 Performs the mapping.
virtual OutputType get (const string &name) const =0
 Performs the mapping from string to OutputType.

Private Member Functions

virtual string getName () const =0
 Gets Key's name.

Detailed Description

template<typename OutputType>
class keyvalue::key::FlagMap< OutputType >

Maps names to constants.

A string is mapped to a flag (normally an enum). Consider, for instance, key::Device which specifies a logger::Logger type to be build. Users provide a string either "Console", "File" or "Standard". However, inside keyvalue, devices are designated by key::Device::Flag. An error occurs when a string cannot be mapped to a valid output.

Traits derived classes which uses this map must implement a method to perform the mapping. This method has the following signature

OutputType get(const string& name) const;

Parameters:
OutputType : (template parameter) Output type.
Return values:
OutputType_ : Same as OutputType.

Member Function Documentation

OutputType map ( const value::Variant variant  )  const

Performs the mapping.

This method converts the input from value::Variant to string and calls get().

Parameters:
variant : A value::Variant containing the input string to be mapped.
Returns:
The mapping result.
virtual OutputType get ( const string &  name  )  const [pure virtual]

Performs the mapping from string to OutputType.

Must be implemented by derived real keys.

Parameters:
name : The string to be mapped.
Returns:
The mapped value.
virtual string getName (  )  const [private, pure virtual]

Gets Key's name.

Returns:
The Key's name.