Data Structures | |
class | Data |
class | DataVariant |
Enumerations | |
enum | CastResults { CastOK, DifferentDatatypes, CouldNotCast, BadCastException, NULLPointerGiven } |
Functions | |
template<class T > | |
CastResults | CastDataVariant (Data *incoming, T &returning) |
Namespace Variant includes two classes to handle various datatypes which come out of an SQLite Database (alternative to BOOST::Variant)
CastResults contains the possible results from CastDataVariant
DifferentDatatypes |
No problems in the dynamic_cast. |
CouldNotCast |
Data and given variable are different types. |
BadCastException |
Cast is not possible. |
NULLPointerGiven |
Cast throws a BadCast Exception. The incoming pointer is NULL |
Definition at line 98 of file datavariant.h.
{ CastOK, DifferentDatatypes, CouldNotCast, BadCastException, NULLPointerGiven };
CastResults Dedupe::Dataholding::Variant::CastDataVariant | ( | Data * | incoming, | |
T & | returning | |||
) |
A free function to get the data from GetData while using only the baseclasspointer. First argument is the baseclasspointer, second argument is the variable where the data is written, if there were no cast errors.
Definition at line 114 of file datavariant.h.
References Dedupe::Dataholding::Variant::DataVariant< T >::GetData().
{ //Make sure, the incoming pointer is not NULL if( incoming == NULL ) return NULLPointerGiven; /*Make sure, holded data and the returning variable are frome the same type */ if( incoming->GetType() != typeid( T ) ) return DifferentDatatypes; //Define the pointer here, cause the cast is in a different scope DataVariant<T> *ptr = NULL; //catch bad_cast exceptions and return an BadCastExecption error try { ptr = dynamic_cast <Dedupe::Dataholding::Variant::DataVariant<T> *>(incoming); } catch (std::bad_cast& bc) { return BadCastException; } if( ptr == NULL ) return CouldNotCast; //write the data to the returning varible returning = ptr->GetData(); return CastOK; }