LexicalToolKit Class Reference

Manager of all lexical converters needed for front-end input/output. More...

#include "keyvalue/frontend/LexicalToolKit.h"

List of all members.

Classes

class  Failure
 This class is thrown when LexicalToolKit::convert() fails. More...
struct  Helper
 Helper class of LexicalToolKit. More...

Public Types

enum  IO { none = 0x0, input = 0x1, output = 0x2, both = 0x3 }
 

Direction of conversion.

More...

Public Member Functions

 LexicalToolKit ()
 Default constructor.
template<typename From , typename To >
void set (IO io, typename Helper< From, To >::Type_ converter=util::Lexical)
 Sets a converter function pointer.
template<typename From , typename To >
bool isEnabled (IO io) const
 Checks if a specific conversion is enabled.
template<typename To , typename From >
To convert (From input) const
 Performs a conversion.

Private Attributes

char endInitList

Detailed Description

Manager of all lexical converters needed for front-end input/output.

This class stores pointers to several lexical conversion functions from/to different types. Possible conversions are:

Those pointers can be changed to customized converters which must have the following signature:

To function(From)

where From and To are the input and output types, resp.

Some conversions might fail (e.g. from string "foo" to any other type) in which case the converter should throw an exception.

Conversions marked with (*) have a quite natural meaning (e.g from string "True" to bool true). For such conversions this class provides default converter (see util::Lexical) that can (if the user wishes so), be chosen (through set()) as the official converter.


Member Enumeration Documentation

enum IO

Direction of conversion.

See documentation of set();


Constructor & Destructor Documentation

LexicalToolKit (  ) 

Default constructor.

By default, all conversion function pointers are null.


Member Function Documentation

void set ( IO  io,
typename Helper< From, To >::Type_  converter = util::Lexical 
) [inline]

Sets a converter function pointer.

Parameters From and To specify, resp., the input and output types of the conversion function pointer to be changed.

A lexical conversion may be need for library input or output. The parameter io defines if the corresponding conversion is set for input, output or both.

This function takes a pointer, converter, to a conversion function. If no pointer is provided, then the default converter (see util::Lexical) is used. If a null pointer is passed, then the corresponding conversion is disabled.

Parameters:
From : (template parameter) the input type;
To : (template parameter) the output type;
converter : Pointer to the conversion function;
io : Direction the conversion is set to.
bool isEnabled ( IO  io  )  const [inline]

Checks if a specific conversion is enabled.

This template function checks if the From to To convertion is enabled in the io direction.

Parameters:
From : (template parameter) the input type;
To : (template parameter) the output type;
io : Conversion direction.
Returns:
This method returns true if the conversion is enabled. Otherwise it returns false.
Exceptions:
LogicError : (Debug build only) if io is invalid.
To convert ( From  input  )  const [inline]

Performs a conversion.

Parameters From and To specify, resp., the input and output types of the required conversion. Notice that, in general, compilers are able to deduce From type and, hence it can be omitted. Therefore a typical use for this method looks like

LexicalToolKit lt;
double x = 3.141592654;
string s = lt.convert<string>(x);

Parameters:
From : (template parameter) the input type;
To : (template parameter) the output type;
input : Value to be converted.
Returns:
The conversion result.
Exceptions:
LogicError : (Debug build only) if the required conversion is disabled.
Failure : If required conversion fails.

Member Data Documentation

char endInitList [private]

Using the X Macro technique in the constructor initialization list will produce a list of members ending in a comma. It cannot be the end of the list, otherwise, together with the following constructor's body open brace will get a syntax error. We need at least one extra member following by an space (not comma).


Generated on Sat Mar 20 15:08:30 2010 for KeyValue by  doxygen 1.6.1