Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Castable Class Reference
Inheritance diagram for Castable:
Inheritance graph
[legend]
Collaboration diagram for Castable:
Collaboration graph
[legend]

Public Member Functions

 Castable (const Castable &c)
 Copy constructor: copies the layout and the pointer to the target.
 
template<class F >
 Castable (F &p)
 Constructor for an object pointing to a variable.
 
template<class F >
 Castable (F *p)
 
virtual bool typeIsSet () const
 
bool empty () const
 Returns true, if string is empty or array size is zero. (In future, semantics may change: 0 for scalars?) More...
 
virtual const std::type_info & getType () const
 Return the storage type (base type) of the referenced variable.
 
bool isValid () const
 Return true, if the pointer is set.
 
virtual bool isLinking () const
 Return true, if the referenced variable is external. Inherited classes - like Variable - may have internal data arrays.
 
virtual bool isVariable () const
 Returns true, if the class contains an own data array. More...
 
bool isCharArrayString () const
 Returns true, if type is C char array and outputSepator is the null char.
 
bool isStlString () const
 Returns true, if type is std::string .
 
bool isString () const
 Returns true, if type is C char array or std::string .
 
virtual size_t getElementCount () const
 Returns the length of the array, the number of elements in this entry. More...
 
size_t getElementSize () const
 Return the size of the current storage type, in bytes. More...
 
virtual size_t getSize () const
 Returns the size in bytes of the target: (elementCount * elementSize) More...
 
CastablesetFill (bool fill=true)
 Set or unset filling (padding) an array if input set is smaller.
 
void clear ()
 Clears strings, or for scalars and arrays, sets all the values to zero. Does not change type.
 
void reset ()
 
std::string getTypeName () const
 Returns the name of the current storage type. More...
 
template<class T >
Castableoperator= (const T &x)
 
Castableoperator= (const char *c)
 
template<class T >
Castableoperator= (const T *x)
 
Castableoperator= (const Castable &c)
 Copies the value referred to by Castable. Notice that if type is unset (void), no operation is performed. More...
 
void assign (const std::string &c)
 
void assign (const char *c)
 
void assign (const Castable &c)
 
template<class T >
void assign (const T *p)
 
template<class T >
void assign (const T &x)
 Copies an arbitrary base type or std::string value.
 
template<typename T >
void assign (std::initializer_list< T > l)
 Copies elements of a list.
 
template<class T >
void assign (const std::list< T > &l)
 Copies elements of a list.
 
template<class T >
void assign (const std::vector< T > &v)
 Copies elements of a vector.
 
template<class T >
void assign (const std::set< T > &s)
 Copies elements of a set.
 
CastableassignCastable (const Castable &c)
 Copy data from Castable. Perhaps copy size and type, too.
 
template<class T >
Castableoperator<< (const T &x)
 
template<class T >
void append (const T &x)
 Appends the string or appends the array by one element.
 
void append (const char *s)
 Appends the string or appends the array by one element.
 
template<class T >
void append (const std::list< T > &l)
 Appends elements of std::list. More...
 
template<class T >
void append (const std::vector< T > &v)
 Appends elements of a vector. More...
 
template<class T >
void append (const std::set< T > &s)
 Appends elements of a set.
 
template<class T >
get (size_t i) const
 
 operator std::string () const
 Conversion to std::string. More...
 
template<class T >
 operator T () const
 
template<class T , size_t N>
 operator UniTuple< T, N > () const
 
bool operator== (const Castable &c) const
 
bool operator== (const char *s) const
 Compare as a character string.
 
bool operator== (const nullptr_t ptr) const
 Experimental. Notice that if type is set, false is returned also for an empty array. More...
 
template<class T >
bool operator== (const T &x) const
 Compares a value to internal data.
 
template<class T , size_t N>
bool operator== (const UniTuple< T, N > &x) const
 
template<class T >
bool operator!= (const T &x) const
 Compares a value to inner data.
 
bool operator!= (const char *x) const
 
template<class T >
bool operator< (const T &x) const
 Compares a value to inner data.
 
template<class T >
bool operator> (const T &x) const
 Compares a value with inner data.
 
template<class T >
bool operator<= (const T &x) const
 Compares a value to inner data.
 
template<class T >
bool operator>= (const T &x) const
 Compares a value with inner data.
 
CastablesetSeparator (char c=',')
 The character used between array elements in output stream. More...
 
void setInputSeparator (char c=',')
 
void setOutputSeparator (char c=',')
 
char getInputSeparator ()
 
char getOutputSeparator ()
 
std::ostream & toStream (std::ostream &ostr=std::cout, char separator='\0') const
 
std::istream & fromStream (std::istream &istr)
 
std::string toStr () const
 
void typeInfo (std::ostream &ostr) const
 Writes a string of type indentifier char and size in bytes, for example [C@8] for unsigned char and [s@16] for signed short int.".
 
virtual void info (std::ostream &ostr=std::cout) const
 Print value, type and element count.
 
template<class T >
void toSequence (T &container, char separator=0) const
 Converts data to a STL Sequence, for example std::set, std::list or std::vector . More...
 
template<class T >
void toMap (T &map, char separator=0, char equalSign='=') const
 
char * getPtr (size_t i=0)
 Returns pointer to the array of chars without validity check. More...
 
const char * getPtr (size_t i=0) const
 
void copyFormat (const Castable &c)
 Copies array layout and formatting: separators, element count, fillArray flag.
 
virtual bool requestType (const std::type_info &t)
 
virtual bool suggestType (const std::type_info &t)
 Request to change in type. For Castable, simply returns true if the current type was requested.
 
void assignString (const std::string &s)
 Input type specific assign operations.
 
template<class T , size_t N>
void assign (const UniTuple< T, N > &tuple)
 
template<class T >
void assignContainer (const T &v, bool append=false)
 Assigns a STL Sequence, element by element.
 
const char * getCharArray () const
 Returns pointer to the array of chars, checks validity first. More...
 

Public Attributes

bool fillArray = false
 If array, assigning a scalar will fill up the current array.
 

Protected Member Functions

virtual void updateSize (size_t elems)
 
template<class F >
void setType ()
 Sets the storage type. If a target value is available, use setPtr() directly. More...
 
virtual void setType (const std::type_info &t)
 Sets the storage type. If a target value is available, use setPtr() directly.
 
virtual bool requestSize (size_t elementCount)
 Request to change the array size. For Castable (and Reference) does nothing and returns false. More...
 
template<class F >
void setPtr (void *p)
 Stores the pointer and its storage type F. Assumes elementCount=1.
 
template<class F >
void setPtr (F &p)
 Stores the pointer and its storage type F.
 
void setPtr (void *p, const std::type_info &t, size_t count=1)
 Sets the data pointer and its explicit type.
 
template<class F , size_t N>
void setPtr (UniTuple< F, N > &tuple)
 Stores the pair as an array of two elements. More...
 
void relink (Castable &c)
 Copies the link and element count.
 
void castElement (size_t i, const Caster &c, void *p) const
 Let Caster c convert my element #i to target *p.
 
template<class T >
void appendToString (const T &x)
 Append to std::string or char array. More...
 
template<class T >
void assignToString (const T &x)
 
void assignToCharArray (const std::string &s)
 
void assignToCharArray (const char *s)
 
template<class T >
void assignToCharArray (const T &s)
 Input anything to char array string. More...
 
void appendToElementArray (const char *s)
 
template<class T >
void appendToElementArray (const T &s)
 

Protected Attributes

Caster caster
 
size_t elementCount
 Pointer to the data variable. More...
 
char inputSeparator
 Element separator usein in reading a char sequence to an (numeric) array.
 
char outputSeparator
 Element separator usein in writing and reading character strings (streams).
 

Detailed Description

Examples
Castable-example.cpp.

Member Function Documentation

◆ append() [1/2]

void append ( const std::list< T > &  l)
inline

Appends elements of std::list.

Castable &operator<<(

◆ append() [2/2]

void append ( const std::vector< T > &  v)
inline

Appends elements of a vector.

return *this;

◆ appendToString()

void appendToString ( const T &  x)
inlineprotected

Append to std::string or char array.

Combines current data and input in stringstream, and replaces contents by sstr.str(). Hence not specialized for input that is already string-like (std::string and char array).

◆ assignToCharArray()

void assignToCharArray ( const T &  s)
inlineprotected

Input anything to char array string.

A specialized version for T=std::string is defined below.

◆ empty()

bool empty ( ) const

Returns true, if string is empty or array size is zero. (In future, semantics may change: 0 for scalars?)

See also
getSize()
getElementCount()
getElementSize()

◆ getCharArray()

const char * getCharArray ( ) const

Returns pointer to the array of chars, checks validity first.

See also
getPtr() Returns pointer to the array of chars, if charArray or std::string
getPtr() which returns pointer directly

checks validity first.

◆ getElementCount()

virtual size_t getElementCount ( ) const
inlinevirtual

Returns the length of the array, the number of elements in this entry.

See also
getElementSize()
getSize()

◆ getElementSize()

size_t getElementSize ( ) const
inline

Return the size of the current storage type, in bytes.

See also
getElementCount().
getSize().

◆ getInputSeparator()

char getInputSeparator ( )
inline

May append elements dynamically, there should be a marker for separating elements is a string.

◆ getOutputSeparator()

char getOutputSeparator ( )
inline

May append elements dynamically, there should be a marker for separating elements is a string.

◆ getPtr()

char* getPtr ( size_t  i = 0)
inline

Returns pointer to the array of chars without validity check.

See also
getCharArray

◆ getSize()

virtual size_t getSize ( ) const
inlinevirtual

Returns the size in bytes of the target: (elementCount * elementSize)

See also
getElementCount().
getElementSize().

◆ getTypeName()

std::string getTypeName ( ) const
inline

Returns the name of the current storage type.

This distinguishes between char array and string.

◆ isVariable()

virtual bool isVariable ( ) const
inlinevirtual

Returns true, if the class contains an own data array.

In a drain::Variable, ptr always points to data array, or to null, if the array is empty. In a drain::FlexibleVariable, ptr can point to owned data array or to an external (base type) variable.

Reimplemented in VariableBase.

◆ operator std::string()

operator std::string ( ) const
inline

◆ operator T()

operator T ( ) const
inline

Conversion from the internal type. Conversion operator. Works well with basic types. Due to g++ error/feature (?), does not work implicitly for std::string. Due to c++ compiler error/feature, does not work implicitly for std::string. For example:

Variable vField;
vField = 1.23;
std::string s = vField; // OK
s = vField; // FAILS, for unknown reason
DRAIN_VARIABLE Variable
Value container supporting dynamic type.
Definition: Variable.h:63

See http://stackoverflow.com/questions/7741531/conversion-operator-template-specialization . The conversion works only if a conversion operator is defined only for std::string (operator std::string()). Adding any str conversions (int, double, ...) causes the compiler to fail.

◆ operator=() [1/2]

Castable& operator= ( const Castable c)
inline

Copies the value referred to by Castable. Notice that if type is unset (void), no operation is performed.

Seems to be obligatory.

◆ operator=() [2/2]

Castable& operator= ( const char *  c)
inline

Obligatory. Many values will be read from command line or text files.

◆ operator==()

bool operator== ( const nullptr_t  ptr) const
inline

Experimental. Notice that if type is set, false is returned also for an empty array.

Semantics.. caster.ptr = nullptr : ? elementCount = 0 : ?

◆ requestSize()

virtual bool requestSize ( size_t  elementCount)
inlineprotectedvirtual

Request to change the array size. For Castable (and Reference) does nothing and returns false.

Does not apply to std::string;

◆ reset()

void reset ( )
inline

Unset the type (set it to void ) and clear @elementCount .

◆ setInputSeparator()

void setInputSeparator ( char  c = ',')
inline

May append elements dynamically, there should be a marker for separating elements is a string.

◆ setOutputSeparator()

void setOutputSeparator ( char  c = ',')
inline

May append elements dynamically, there should be a marker for separating elements is a string.

◆ setPtr()

void setPtr ( UniTuple< F, N > &  tuple)
inlineprotected

Stores the pair as an array of two elements.

The pointer is set to the first. Stores the elements as an array. The pointer is set to the first.

◆ setSeparator()

Castable& setSeparator ( char  c = ',')
inline

The character used between array elements in output stream.

See also
isCharArrayString

◆ setType()

void setType ( )
inlineprotected

Sets the storage type. If a target value is available, use setPtr() directly.

Keep this redirect, because Variable may need virtual setType()

◆ toSequence()

void toSequence ( T &  container,
char  separator = 0 
) const
inline

Converts data to a STL Sequence, for example std::set, std::list or std::vector .

Template Parameters
T- std::set, std::list or std::vector
Parameters
container- sequence in which elements will be assigned
separator- separator char(s) overriding separator chars of the instance; applicable only with strings

The most general container insert method

Member Data Documentation

◆ elementCount

size_t elementCount
protected

Pointer to the data variable.

Size of the current variable


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