Public Types | Public Member Functions | Protected Member Functions | List of all members
VariableBase Class Reference

Base class for variables: Variable, Reference and FlexibleVariable. More...

#include <VariableBase.h>

Inheritance diagram for VariableBase:
Inheritance graph
[legend]
Collaboration diagram for VariableBase:
Collaboration graph
[legend]

Public Types

typedef CastableIterator const_iterator
 
typedef CastableIterator iterator
 

Public Member Functions

virtual bool isLinking () const
 Tells if the pointer points to an external variable.
 
virtual bool isVariable () const
 Tells if internal memory exists. More...
 
virtual bool isLinkable () const
 Tells if the internal pointer can point to an external variable. More...
 
VariableBaseappend ()
 
template<class T , class ... TT>
VariableBaseappend (const T &x, const TT &...rest)
 
template<class T , class ... TT>
VariableBaseset (const T &x, const TT &...rest)
 
virtual void setType (const std::type_info &t)
 Does not change separator chars. More...
 
template<class T >
VariableBaseoperator<< (const T &x)
 Extends the array by one element.
 
const CastableIteratorbegin () const
 Like with std::iterator. More...
 
const CastableIteratorend () const
 Like with std::iterator.
 
virtual bool setSize (size_t elementCount)
 Extends the array to include elementCount elements of current type. More...
 
- Public Member Functions inherited from Castable
 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.
 
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...
 

Protected Member Functions

virtual void updateSize (size_t elementCount)
 
- Protected Member Functions inherited from Castable
template<class F >
void setType ()
 Sets the storage type. If a target value is available, use setPtr() directly. More...
 
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)
 

Additional Inherited Members

- Public Attributes inherited from Castable
bool fillArray = false
 If array, assigning a scalar will fill up the current array.
 
- Protected Attributes inherited from Castable
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

Base class for variables: Variable, Reference and FlexibleVariable.

See also
Variable
Reference
FlexibleVariable

Member Function Documentation

◆ begin()

const CastableIterator& begin ( ) const
inline

Like with std::iterator.

Notice: in the case of std::strings, will iterate through characters.

◆ isLinkable()

virtual bool isLinkable ( ) const
inlinevirtual

Tells if the internal pointer can point to an external variable.

Returns
- true for Reference and FlexibleVariable, and false for Variable.

◆ isVariable()

virtual bool isVariable ( ) const
inlinevirtual

Tells if internal memory exists.

Note. 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.

Returns
- true for drain::Variable and drain::FlexibleVariable, and false for drain::Reference.

Reimplemented from Castable.

◆ setSize()

virtual bool setSize ( size_t  elementCount)
inlinevirtual

Extends the array to include elementCount elements of current type.

Needed for example in reading data directly using a pointer.

◆ setType()

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

Does not change separator chars.

Sets basic type or void. Also std::string is accepted, but handled as request of char array.

Reimplemented from Castable.


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