Public Types | Public Member Functions | Private Attributes

StdSingle< ElementType > Class Template Reference

Converter from value::Single to ElementType. More...

#include <keyvalue/key/converter/StdSingle.h>

List of all members.

Public Types

typedef value::Single InputType_
 Compulsory member.
typedef ElementType OutputType_
 Compulsory member.

Public Member Functions

 StdSingle (const InputType_ &input, OutputType_ *cache)
 Compulsory constructor.
bool isEmpty () const
 Compulsory member: Checks if conversion has finished.
value::Variant pop ()
 Compulsory member: Gets next input element.
void insert (const ElementType &element)
 Compulsory member: Inserts a new element into the output container.
OutputType_ getOutput () const
 Compulsory member: Gets output container.
bool mustUpdate () const
 Compulsory member: Informs if cached value is up to date.

Private Attributes

const InputType_input_
OutputType_ *const cache_
OutputType_ output_
bool empty_
bool mustUpdate_

Detailed Description

template<typename ElementType>
class keyvalue::key::StdSingle< ElementType >

Converter from value::Single to ElementType.

Values provided by the end users must be converted to other types before being forwarded to the core library. This converter is used when the input value is a value::Single.

StdSingle together with StdVector and StdMatrix might serve as samples for bridge developers who want to implement their own converters. A few constraints have to be verified. Reading documentation for these three classes before implement any converter is strongly advisable.

These constraints are such that for converters taking value::Single as input there is little (if any) room for other converters. However, converters taking value::Vector or value::Matrix can be tailored to specific core library needs.

The constraints are composed by certain typedefs and methods that must be member of any converter. They will be explained below.

Parameters:
ElementType : The output type.
Return values:
InputType_ : value::Single;
OutputType_ : ElementType.

Member Typedef Documentation

Compulsory member.

typedef ElementType OutputType_

Compulsory member.

Notice that getOutput() returns an OutputType_ object by value. Hence, it is advisable for this type to be cheap-to-copy.


Constructor & Destructor Documentation

StdSingle ( const InputType_ input,
OutputType_ cache 
)

Compulsory constructor.

Internally, the converter must store a copy of the input and a copy of previously cached output (if any). Also, it must compare the new computed output with the cached one to see if anything dependent on the cached output must be updated. (See mustUpdate().)

Parameters:
input : Input data.
cache : A pointer to the previously cached value if there exist any. Otherwise, a null pointer must be given.

Member Function Documentation

bool isEmpty (  )  const

Compulsory member: Checks if conversion has finished.

Returns:
This methods must return true if all elements of input data have been processed. Otherwise, it must returns false.
value::Variant pop (  ) 

Compulsory member: Gets next input element.

There should be at least one element to be popped, that is, isEmpty() must be false. The debug build checks this condition and throws an exception in case of failure. The release build has undefined behavior in this case.

Returns:
A copy of next input element to be processed.
Exceptions:
LogicError : (Debug build only) If isEmpty() is true.
void insert ( const ElementType &  element  ) 

Compulsory member: Inserts a new element into the output container.

Parameters:
element : The element to be inserted into the output container.
StdSingle< ElementType >::OutputType_ getOutput (  )  const

Compulsory member: Gets output container.

Returns:
A copy of output container.
bool mustUpdate (  )  const

Compulsory member: Informs if cached value is up to date.

Returns:
This method returns true if cached value is out of date. Otherwise it returns false.