Back to calculator object help

Calculator object


Calculator

Variable class hierarchy description

View class hierarchy diagram

Class VflVarBase

This is the base class of all input and output variables. It provides information about the variables data type and a flag whether data has been assigned.

Elements:

int getId()
Returns the internal variable id number.
virtual TVarDirection getDirection()
Allows determination whether the variable is input or output type. TVarDirection is a global enum defined in the following way: enum TVarDirection {InputVar=0,OutputVar=1};
virtual TVarType type()
Allows determination of the variable type. TVarType is defined in the following way: enum TVarType {Integer=0,Float=1,String=2,IntegerArray=3,FloatArray=4};
virtual bool hasData()
Returns true if the variable contains data. This is especially useful to check whether an input variable contains data. If data is read from a variable not containig data, scalar variables return the default values (for example 0 for integers) and arrays return zero length.
virtual void clear()
Clears assigned data. A call to hasData() following a clear() returns false.
VflVarBase).
VflVar(T d)
Contructor that initializes the variable. Calling hasdata() on a suchlike initialized variable returns true.
VflVar()
Constructor that creates a not assigned variable.
template <class T,TVarType t,TVarDirection dr> VflVar(VflVar& other)
Copy constructor that initializes that creates a copy of other
template <class T,TVarType t,TVarDirection dr>T operator =(VflVar& other)
Assignment operator. Assignes the contents of another VflVar.
template <class T,TVarType t,TVarDirection dr>operator T&()
Returns a reference to the internal data. This allows using VflVar like a normal variable of type T
template <class T,TVarType t,TVarDirection dr>T operator =(const T i)
Assignes a value of type T hasdata = true; data = i; return i; }; void clear() {hasdata = false; data = T();}

Template VflArray

This template defines the basic array variable functions of any data type. The VflArray manages an internal buffer for storing the data. It is defined in the following way: template <class T> class VflArray

Elements:

VflArray()
Default contructor, creates an ampty array.
template <class T> VflArray(const T* d,int alen)
Contructs an array containing alen data elements which are read from the memory location pointed to by d. The data is copied to the internal data buffer.
template <class T> VflArray(const VflArray<T>& other)
Copy constructor. Creates an array by copiing data from other.
virtual ~VflArray();
Destructor. Destroys the internal buffer.
template <class T> void set(const T* d, int alen)
Assigns data to the array deleting the old data. alen data elements are copied form the memory location pointed to by d to the internal buffer.
template <class T> const VflArray<T>& operator = (const VflArray<T>& other)
Assign operator. Assigns copies data from another VflArray. This allows copiing a whole array by writing
ArrayA = ArrayB
int len()
Returns the number of data elements the array contains.
template <class T> T& operator[](int p)
Direct element access. This operator allows storing and reading single data elements indexed by p. The element counting starts at zero like normal C arrays. If a data element is addressed with a number larger than the array size, the array is extended filling new data elements with the default value (for example 0 for integers). This operator allows element access by writing something like
sampleArray[42] = ...;
template <class T> void apply(T (*func)(T))
Calles the function provided by func for each data element of the array passing the data element as parameter. After that the data element is set to the return value of the function.
template <class T> void applyParam(T (*func)(T,T),T v)
The sample like apply but allows passing a second parameter to func.
void setSize(int sz)
Resizes the array to sz. If the new size is greater than the old size new created elements are initialized with the default value of the data type T.
template <class T> operator T*()
Returns a pointer to the internal data array. The pointer must not be deleted.
template <class T> void operator +=(T v)
Adds a scalar of type T to each data element.
template <class T> void operator -=(T v)
Subtracts a scalar of type T from each data element.
template <class T> void operator *=(T v)
Multiplies each data element with a scalar of type T.
template <class T> void operator /=(T v)
Multiplies each data element by a scalar of type T.
template <class T> T minimum()
Returns the minimal value contained in the array or the default value of T when array length is zero.
template <class T> T maximum()
Returns the maximal value contained in the array or the default value of T when array length is zero.
int minpos()
Returns the index position of the minimal value contained in the array or -1 when array length is zero.
int maxpos()
Returns the index position of the maximal value contained in the array or -1 when array length is zero.

Class CharArray

This class inherits from VflArray<char> and extends this with conversion from and to null terminated strings. It is defined in the following way: class CharArray: public VflArray<char>

Elements:

CharArray()
Defalut construnctor. Creates an empty CharArray.
CharArray(const CharArray& other)
Copy constructor. Creates a copy of other.
CharArray(const char* d,int len)
Constructor that initializes from a character array with the length given by len.
CharArray(const char* s)
Constructor that initializes from a null terminated string.
operator char*()
Returns the array contents as a null terminated string. The pointer must not be deleted. Each instance of CharArray manages an own return buffer.
CharArray& operator +=(const CharArray& other)
Appends other to the CharArray.

Class VarString

This template inherits merges properties of character arrays and Vimms input / output variables. It inherits from the template VflVarDir and the class CharArray: class VflVarString: public CharArray,public VflVarBase The class itself defines only a few functions.

Elements:

VflVarString()
Constructor that creates an empty VarString
VflVarString(const char* data,int len)
Constructor that creates a VarString from a character array with the length given by len.
VarVarString(const CharArray& other)
Contructor that initializes from the CharArray other.
bool hasData()
Implements the function hasData() inherited from VflVarBase.
TVarType type()
Implements the function type() inherited from VflVarBase and returns String.
void clear()
Implements the function clear() inherited from VflVarBase and does the same like CharArray::clear()

Variable typedefs

For easy usability the following typedefs are predefined:
typedef VflVar<int,Integer> VflVarInteger; typedef VflVar<double,Float> VflVarFloat; typedef VflVarArray<int,IntegerArray> VflVarIntegerArray; typedef VflVarArray<double,FloatArray> VflVarFloatArray;

Back to the top
Back to calculator object help


The Vimms User Manual