STK++ 1.0

STK::Variable< TYPE > Class Template Reference

Variable is an implementation of the Base class IVariable using The Array1D class for storing the data. More...

#include <STK_Variable.h>

Inheritance diagram for STK::Variable< TYPE >:

List of all members.

Public Member Functions

 Variable (const Range &I=Range(), String const &name=Arithmetic< String >::NA())
 Default constructor.
 Variable (Range const &I, TYPE const &v, String const &name=Arithmetic< String >::NA())
 Misc constructor.
 Variable (Variable const &V, bool ref=false)
 Copy ctor.
 Variable (Variable const &V, Range const &I, Integer col)
 Reference constructor.
virtual ~Variable ()
 Virtual destructor.
TYPE & elt (Integer const &pos)
 access to one element.
TYPE const & elt (Integer const &pos) const
 access to one element const.
Variable elt (Range const &J) const
 access to many elements.
Variableoperator= (Variable const &V)
 Operator = : overwrite the Variable with V.
Variableoperator= (TYPE const &v)
 Operator = : overwrite the Variable with the value v.
virtual Variableclone (bool ref=false) const
 clone return a ptr on a copy of the Object.
void pushBackNAValues (Integer const &n=1)
 push back n NA values.
virtual Integer importString (const _VarStringType &V, std::ios_base &(*f)(std::ios_base &)=std::dec)
 overwrite the Variable by converting the strings contained in V into the Type.
virtual Variable const & exportString (Variable< String > &V, std::ios_base &(*f)(std::ios_base &)=std::dec) const
 Overwrite the variable V by converting the data into strings.
virtual Variableoperator<< (const Variable< String > &V)
 Operator << : overwrite the IVariable by converting the strings contained in V into the Type.
virtual Variable const & operator>> (Variable< String > &V) const
 Operator >> : convert the Variable V into strings.

Private Types

typedef IArrayBase< TYPE * > _IArrayBaseType
 Type for the Base reference Class.
typedef RecursiveArray1D< TYPE,
Variable< TYPE > > 
_IArray1DType
 Type for the IArray1DBase Class.

Friends

ostreamoperator<< (ostream &s, const Variable< TYPE > &V)
 ostream for Variable.

Detailed Description

template<class TYPE>
class STK::Variable< TYPE >

Variable is an implementation of the Base class IVariable using The Array1D class for storing the data.

It implement all purely virtual methods defined in the IVariableBase and IVariable base classes.

Definition at line 55 of file STK_Variable.h.


Member Typedef Documentation

template<class TYPE>
typedef IArrayBase<TYPE*> STK::Variable< TYPE >::_IArrayBaseType [private]

Type for the Base reference Class.

Reimplemented from STK::RecursiveArray1D< TYPE, Variable< TYPE > >.

Definition at line 59 of file STK_Variable.h.

template<class TYPE>
typedef RecursiveArray1D<TYPE, Variable<TYPE> > STK::Variable< TYPE >::_IArray1DType [private]

Type for the IArray1DBase Class.

Reimplemented from STK::RecursiveArray1D< TYPE, Variable< TYPE > >.

Definition at line 61 of file STK_Variable.h.


Constructor & Destructor Documentation

template<class TYPE>
STK::Variable< TYPE >::Variable ( const Range I = Range(),
String const &  name = Arithmetic<String>::NA() 
) [inline]

Default constructor.

Parameters:
I: range of the data
name: name of the variable

Definition at line 68 of file STK_Variable.h.

Referenced by STK::Variable< String >::clone(), and STK::Variable< String >::elt().

            : IVariable(IdTypeImpl<TYPE>::returnType(), name)
            , _IArray1DType(I)
    { ;}
template<class TYPE>
STK::Variable< TYPE >::Variable ( Range const &  I,
TYPE const &  v,
String const &  name = Arithmetic<String>::NA() 
) [inline]

Misc constructor.

Parameters:
I: range of the data
name: name of the variable
v: initial value

Definition at line 80 of file STK_Variable.h.

            : IVariable(IdTypeImpl<TYPE>::returnType(), name)
            , _IArray1DType(I, v)
     { ;}
template<class TYPE>
STK::Variable< TYPE >::Variable ( Variable< TYPE > const &  V,
bool  ref = false 
) [inline]

Copy ctor.

Parameters:
Vthe Variable to copy
reftrue if we want to wrap V

Definition at line 89 of file STK_Variable.h.

            : IVariable(V)
            , _IArray1DType(V, ref)
     { ;}
template<class TYPE>
STK::Variable< TYPE >::Variable ( Variable< TYPE > const &  V,
Range const &  I,
Integer  col 
) [inline]

Reference constructor.

Parameters:
Vthe Variable to wrap
Irange of the data
colthe column of the data

Definition at line 99 of file STK_Variable.h.

            : IVariable(V)
            , _IArray1DType(V, I, col)
    { ;}
template<class TYPE>
virtual STK::Variable< TYPE >::~Variable ( ) [inline, virtual]

Virtual destructor.

Definition at line 106 of file STK_Variable.h.

    { ;}

Member Function Documentation

template<class TYPE>
TYPE& STK::Variable< TYPE >::elt ( Integer const &  pos) [inline]

access to one element.

Parameters:
posindex of the element

Reimplemented from STK::ITContainer1D< TYPE, Variable< TYPE > >.

Definition at line 112 of file STK_Variable.h.

Referenced by STK::operator>>().

    { return this->data(pos);}
template<class TYPE>
TYPE const& STK::Variable< TYPE >::elt ( Integer const &  pos) const [inline]

access to one element const.

Parameters:
posindex of the const element

Reimplemented from STK::ITContainer1D< TYPE, Variable< TYPE > >.

Definition at line 118 of file STK_Variable.h.

    { return this->data(pos);}
template<class TYPE>
Variable STK::Variable< TYPE >::elt ( Range const &  J) const [inline]

access to many elements.

Parameters:
Jthe range of the elements

Reimplemented from STK::ITContainer1D< TYPE, Variable< TYPE > >.

Definition at line 124 of file STK_Variable.h.

    {
#ifdef STK_BOUNDS_CHECK
      if ((J.first()<this->first()))
      { throw std::out_of_range("Array1D::elt(J) "
                                "J.first()<this->first()");
      }
      if ((J.last()>this->last()))
      { throw std::out_of_range("Array1D::elt(J) "
                                "J.last()>this->last()");
      }
#endif
      return Variable(*this, J);
    }
template<class TYPE>
Variable& STK::Variable< TYPE >::operator= ( Variable< TYPE > const &  V) [inline]

Operator = : overwrite the Variable with V.

Parameters:
Vthe variable to copy

Definition at line 142 of file STK_Variable.h.

    {
            IVariable *p3 = this;   // convert this to IVariable
      const IVariable *p4 = &V;     // convert V    to IVariable
      (*p3) = (*p4);                // use = of IVariable class

      // check size
      if (size()!=V.size()) resize(V.range());
      // copy without ovelapping.
      if (first() < V.first())
      { for (Integer i=first(), j=V.first(); j<=V.last(); i++, j++)
          setData(i, V.data(j));
      }
      else
      { for (Integer i=last(), j=V.last(); j>=V.first(); i--, j--)
          setData(i, V.data(j));
      }
      return *this;
    }
template<class TYPE>
Variable& STK::Variable< TYPE >::operator= ( TYPE const &  v) [inline]

Operator = : overwrite the Variable with the value v.

Parameters:
vthe value to set to the variable

Definition at line 165 of file STK_Variable.h.

    {
      for (Integer i=first(); i<=last(); i++)
        setData(i, v);
      return *this;
    }
template<class TYPE>
virtual Variable* STK::Variable< TYPE >::clone ( bool  ref = false) const [inline, virtual]

clone return a ptr on a copy of the Object.

Parameters:
reftrue if we want just a reference

Implements STK::IVariable.

Definition at line 175 of file STK_Variable.h.

    { return new Variable(*this, ref);}
template<class TYPE>
void STK::Variable< TYPE >::pushBackNAValues ( Integer const &  n = 1) [inline, virtual]

push back n NA values.

Parameters:
nnumber of NA values to add

Implements STK::IVariable.

Definition at line 181 of file STK_Variable.h.

    {
      insert(Range(last() +1, n), Arithmetic<TYPE>::NA());
    }
template<class TYPE>
virtual Integer STK::Variable< TYPE >::importString ( const _VarStringType V,
std::ios_base &(*)(std::ios_base &)  f = std::dec 
) [inline, virtual]

overwrite the Variable by converting the strings contained in V into the Type.

Give the number of success.

Parameters:
VVariable of String
fio flags
Returns:
number of successful conversion

Implements STK::IVariable.

Definition at line 192 of file STK_Variable.h.

Referenced by STK::ImportFromCsv::convertToTYPE().

    {
      this->resize(V.range());
      this->setName(V.name());
      Integer nSuccess = V.size();
      for (Integer i=V.first(); i<=V.last(); i++)
        if (Arithmetic<String>::isNA(V[i])) // not Available
          this->at(i) = Arithmetic<TYPE>::NA();
        else
        if (!stringToType<TYPE>(this->at(i), V[i]))
          nSuccess--;
      return nSuccess;
    }
template<class TYPE>
virtual Variable const& STK::Variable< TYPE >::exportString ( Variable< String > &  V,
std::ios_base &(*)(std::ios_base &)  f = std::dec 
) const [inline, virtual]

Overwrite the variable V by converting the data into strings.

Parameters:
VVariable of String
fio flags

Definition at line 212 of file STK_Variable.h.

    {
      V.resize(this->range());
      V.setName(this->name());
      for (Integer i=first(); i<=last(); i++)
      {
        V[i] = typeToString<TYPE>(this->at(i), f);
      }
      return *this;
    }
template<class TYPE>
virtual Variable& STK::Variable< TYPE >::operator<< ( const Variable< String > &  V) [inline, virtual]

Operator << : overwrite the IVariable by converting the strings contained in V into the Type.

Parameters:
Vthe Variable of string to import

Definition at line 230 of file STK_Variable.h.

    {
      this->resize(V.range());
      this->setName(V.name());
      for (Integer i=V.first(); i<=V.last(); i++)
        stringToType<TYPE>(this->at(i), V[i]);
      return *this;
    }
template<class TYPE>
virtual Variable const& STK::Variable< TYPE >::operator>> ( Variable< String > &  V) const [inline, virtual]

Operator >> : convert the Variable V into strings.

Parameters:
VVariable of String

Definition at line 242 of file STK_Variable.h.

    {
      V.resize(this->range());
      V.setName(this->name());
      for (Integer i=first(); i<=last(); i++)
        V[i] = typeToString<TYPE>(this->at(i));

      return *this;
    }

Friends And Related Function Documentation

template<class TYPE>
ostream& operator<< ( ostream s,
const Variable< TYPE > &  V 
) [friend]

ostream for Variable.

Definition at line 253 of file STK_Variable.h.

    {
      s << V.name() << STRING_NL;
      return out1D(s,V);
    }

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