Converter from value::Single to ElementType. More...
#include <keyvalue/key/converter/StdSingle.h>
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_ |
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 class
es 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 typedef
s and methods that must be member of any converter. They will be explained below.
ElementType | : The output type. |
InputType_ | : value::Single; | |
OutputType_ | : ElementType. |
typedef value::Single InputType_ |
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.
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().)
input | : Input data. | |
cache | : A pointer to the previously cached value if there exist any. Otherwise, a null pointer must be given. |
bool isEmpty | ( | ) | const |
Compulsory member: Checks if conversion has finished.
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 behaviour in this case.
LogicError | : (Debug build only) If isEmpty() is true . |
void insert | ( | const ElementType & | element | ) |
Compulsory member: Inserts a new element into the output container.
element | : The element to be inserted into the output container. |
StdSingle< ElementType >::OutputType_ getOutput | ( | ) | const |
Compulsory member: Gets output container.
bool mustUpdate | ( | ) | const |
Compulsory member: Informs if cached value is up to date.
true
if cached value is out of date. Otherwise it returns false
.