Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
Caster Class Reference

Public Member Functions

 Caster ()
 Default constructor. Leaves the type undefined. More...
 
 Caster (const Caster &c)
 Copy constructor. Copies the type.
 
void link (void *p, const std::type_info &t)
 
template<class T >
void link (T *p)
 
template<class T >
void link (T &p)
 
void setType (const std::type_info &t)
 Calls setType<T>() for which typeid(T) = t. More...
 
template<class F >
void setType ()
 Sets pointers to the type-dependent conversion functions.
 
virtual bool requestType (const std::type_info &t)
 Utility for derived classes, which may be able to adapt memory array type as well.
 
void unsetType ()
 calls void setType<void>().
 
const std::type_info & getType () const
 Returns type_info of the current type.
 
bool typeIsSet () const
 
size_t getElementSize () const
 Returns the size of the base type (size of an element, not of element array).
 
template<class T >
void put (void *p, const T &x) const
 Default conversion (for unconventional types). Uses std::stringstream for conversion.
 
template<class T >
void put (const T &x) const
 Write to internal pointer using put(this->ptr, x).
 
void put (void *p, const char *x) const
 
void put (const char *x) const
 Write to internal pointer, calls put(this->ptr, x).
 
template<class T >
get (const void *p) const
 Default implementation throws an error. See specialized implementation below.
 
template<class T >
get () const
 
void translate (const Caster &c, const void *ptrC, void *ptr) const
 Convert from str pointer and Caster.
 
void translate (const Caster &c) const
 Convert from str Caster.
 
bool compare (const void *ptr, const Caster &c, const void *cPtr) const
 
std::istream & fromStream (std::istream &istr, const void *p) const
 
std::ostream & toOStream (std::ostream &ostr, const void *p) const
 Write data to output stream.
 
std::ostream & toOStream (std::ostream &ostr) const
 Write data to output stream.
 
template<>
void link (Caster &c)
 
template<>
void put (void *p, const bool &x) const
 
template<>
void put (void *p, const char &x) const
 
template<>
void put (void *p, const unsigned char &x) const
 
template<>
void put (void *p, const int &x) const
 
template<>
void put (void *p, const unsigned int &x) const
 
template<>
void put (void *p, const long &x) const
 
template<>
void put (void *p, const unsigned long &x) const
 
template<>
void put (void *p, const float &x) const
 
template<>
void put (void *p, const double &x) const
 
template<>
bool get (const void *p) const
 
template<>
char get (const void *p) const
 
template<>
unsigned char get (const void *p) const
 
template<>
short get (const void *p) const
 
template<>
unsigned short get (const void *p) const
 
template<>
int get (const void *p) const
 
template<>
unsigned int get (const void *p) const
 
template<>
long get (const void *p) const
 
template<>
unsigned long get (const void *p) const
 
template<>
float get (const void *p) const
 
template<>
double get (const void *p) const
 

Public Attributes

void * ptr = nullptr
 Future member: enables setting Caster type.
 

Protected Member Functions

template<class F >
void updateType ()
 Sets pointers to the type-dependent conversion functions. More...
 
template<>
void updateType ()
 
template<>
void updateType ()
 
template<>
void updateType ()
 
template<>
void updateType ()
 Forward pointer.
 

Static Protected Member Functions

template<class T , class F >
static void putT (void *p, const T &x)
 Convert input of base type to internally applied base type.
 
template<class T >
static void putToVoidT (void *p, const T &x)
 Void - does nothing, regardless of input type.
 
template<class T >
static void putToStringT (void *p, const T &x)
 A handler for converting input to a std::string. More...
 
template<class T >
static void putToCasterT (void *p, const T &x)
 
template<class T , class F >
static T getT (const void *p)
 The main handler converting input to output. More...
 
template<class T >
static T getFromVoidT (const void *p)
 This default implementation is for integral numeric types, returns zero. Specialisation for floats returns NAN.
 
template<class T >
static T getFromStringT (const void *p)
 The main handler converting input to output.
 
template<class F >
static void translateT (const Caster &c, const void *ptrC, void *ptr)
 Casts from ptrC to ptr. More...
 
template<class F >
static bool compareT (const void *ptr, const Caster &c, const void *cPtr)
 Checks equality through base type casting. More...
 
template<class F >
static std::ostream & toOStreamT (std::ostream &ostr, const void *p)
 Output.
 
template<class F >
static std::ostream & toOStreamFloats (std::ostream &ostr, const void *p)
 
template<class F >
static std::istream & fromStreamT (std::istream &istr, const void *p)
 Output.
 
template<>
void translateT (const Caster &c, const void *ptrC, void *ptr)
 
template<>
void translateT (const Caster &c, const void *ptrC, void *ptr)
 
template<>
double getFromVoidT (const void *p)
 Specialisation for floats returns NAN.
 
template<>
float getFromVoidT (const void *p)
 
template<>
bool compareT (const void *ptr, const Caster &c, const void *cPtr)
 Semantics: no data, hence no bytes to be compared. More...
 
template<>
std::ostream & toOStreamT (std::ostream &ostr, const void *p)
 Append nothing to the stream.
 
template<>
std::ostream & toOStreamT (std::ostream &ostr, const void *p)
 Append 'true' or false to the stream.
 
template<>
std::ostream & toOStreamT (std::ostream &ostr, const void *p)
 Append to the stream.
 
template<>
std::ostream & toOStreamT (std::ostream &ostr, const void *p)
 
template<>
std::ostream & toOStreamT (std::ostream &ostr, const void *p)
 

Protected Attributes

void(* putBool )(void *p, const bool &x)
 
void(* putInt )(void *p, const int &x)
 
void(* putChar )(void *p, const char &x)
 
void(* putUChar )(void *p, const unsigned char &x)
 
void(* putUInt )(void *p, const unsigned int &x)
 
void(* putShort )(void *p, const short &x)
 
void(* putUShort )(void *p, const unsigned short &x)
 
void(* putLong )(void *p, const long &x)
 
void(* putULong )(void *p, const unsigned long &x)
 
void(* putFloat )(void *p, const float &x)
 
void(* putDouble )(void *p, const double &x)
 
char(* getChar )(const void *p)
 
unsigned char(* getUChar )(const void *p)
 
int(* getInt )(const void *p)
 
unsigned int(* getUInt )(const void *p)
 
short(* getShort )(const void *p)
 
unsigned short(* getUShort )(const void *p)
 
long(* getLong )(const void *p)
 
unsigned long(* getULong )(const void *p)
 
float(* getFloat )(const void *p)
 
double(* getDouble )(const void *p)
 
bool(* getBool )(const void *p)
 
void(* translatePtr )(const Caster &c, const void *ptrC, void *ptr)
 Convert from str pointer and Caster.
 
bool(* comparePtr )(const void *, const Caster &c, const void *) = nullptr
 
std::ostream &(* toOStreamPtr )(std::ostream &ostr, const void *p)
 Write to stream.
 
std::istream &(* fromStreamPtr )(std::istream &istr, const void *p) = nullptr
 
const std::type_info * type
 Current type.
 
size_t byteSize
 Size of target memory (target object) in bytes.
 

Detailed Description

Examples
Caster-example.cpp.

Constructor & Destructor Documentation

◆ Caster()

Caster ( )
inline

Default constructor. Leaves the type undefined.

Initially, type is void, which can be indentified with an unset type or a type requiring storage of zero length.

Member Function Documentation

◆ compareT() [1/2]

static bool compareT ( const void *  ptr,
const Caster c,
const void *  cPtr 
)
inlinestaticprotected

Checks equality through base type casting.

Given data of type c.getType() behind pointer ptrC, cast it to type F and store it behind ptr.

◆ compareT() [2/2]

bool compareT ( const void *  ptr,
const Caster c,
const void *  cPtr 
)
inlinestaticprotected

Semantics: no data, hence no bytes to be compared.

Returns
always false .

◆ getT()

static T getT ( const void *  p)
inlinestaticprotected

The main handler converting input to output.

Template Parameters
T- output type
F- internal storage type

◆ putToStringT()

static void putToStringT ( void *  p,
const T &  x 
)
inlinestaticprotected

A handler for converting input to a std::string.

Template Parameters
T- input type

The internal storage type is std::string.

◆ setType()

void setType ( const std::type_info &  t)
inline

Calls setType<T>() for which typeid(T) = t.

Caster implements setType<T>(), hence this utility can be applied.

Examples
Caster-example.cpp.

◆ translateT()

static void translateT ( const Caster c,
const void *  ptrC,
void *  ptr 
)
inlinestaticprotected

Casts from ptrC to ptr.

Given data of type c.getType() behind pointer ptrC, cast it to type F and store it behind ptr.

◆ updateType()

void updateType
protected

Sets pointers to the type-dependent conversion functions.

NEW


The documentation for this class was generated from the following files: