libFAUDES

Sections

Index

faudes::TBaseVector< T > Class Template Reference
[State, Event and Transition Set]

#include <basevector.h>

Inherits faudes::Type.

List of all members.


Detailed Description

template<class T>
class faudes::TBaseVector< T >

Vector template.

This class is designed as a random access container for a small number of comperatively large objects, eg a vector of generators to model a decentralized DES. The API is restricted to simple positional access and there are no explicit iterators nor is there a deferred copy mechanism.

Internally, the Vector template uses STL vector of pointers to the individual entries. When adding an entry, you may either do so be refernce or by pointer. When setting by reference, the vector takes a copy and owns the new entry. When setting by a pointer, the vector only records the reference. The vector tracks ownership of each entry in order to properly destruct entries.

TVectorSet serves as a base class for all libFaudes vectors:

  • GeneratorVector (vector or generators)
  • EventSetVector (vector of event sets)

Token io assumes that the type parameter is a faudes type, ie. entries of the vector provide token io themselfs. To derive a vector class with non-faudes-type entries, you will need to reimplement token io. As a convenience feature, the vector keeps a record of filenames associated with individual entries. You can inspect and edit this record via the FilenameAt members. When writing the vector to a file and all entries have an associated filename, output will be to the individual files.

Definition at line 69 of file basevector.h.


Public Types

typedef std::vector< int >
::size_type 
Position
 convenience typedef for positions

Public Member Functions

virtual TBaseVectorNew (void) const
 Construct on heap.
virtual TBaseVectorCopy (void) const
 Construct on heap.
virtual const TBaseVectorCast (const Type *pOther) const
 Cast other object to this type.
virtual TBaseVectorAssign (const Type &rSrc)
 Assign configuration data from other object.
virtual bool Equal (const Type &rOther) const
 Test equality of configuration data.
virtual TBaseVectoroperator= (const TBaseVector &rSrc)
virtual bool operator== (const TBaseVector &rOther) const
virtual bool operator!= (const TBaseVector &rOther) const
 TBaseVector (void)
 Constructor.
 TBaseVector (const TBaseVector &rOtherSet)
 Copy-constructor.
 TBaseVector (const std::string &rFilename, const std::string &rLabel="BaseVector")
 Constructor from file.
virtual ~TBaseVector (void)
 Virtual destructor.
const std::string & Name (void) const
 Return name of TBaseVector.
void Name (const std::string &rName)
 Set name of TBaseVector.
virtual void Clear (void)
 Clear all vector.
Idx Size (void) const
 Get size of vector.
void Size (Idx len)
 Set size of vector.
bool Empty (void) const
 Check if the TBaseVector ist Empty.
virtual const T & At (const Position &pos) const
 Access elemend.
virtual T & At (const Position &pos)
 Access elemend.
virtual void Replace (const Position &pos, const T &rElem)
 Replace specified entry.
virtual void Replace (const Position &pos, T *pElem)
 Replace specified entry.
virtual void Replace (const Position &pos, const std::string &rFileName)
 Replace specified entry.
virtual void Erase (const Position &pos)
 Erase entry by position.
virtual void Insert (const Position &pos, const T &rElem)
 Insert specified entry.
virtual void Insert (const Position &pos, T *rElem)
 Insert specified entry.
virtual void Insert (const Position &pos, const std::string &rFileName)
 Insert specified entry.
virtual void PushBack (const T &rElem)
 Append specified entry.
virtual void PushBack (T *rElem)
 Append specified entry.
virtual void PushBack (const std::string &rFileName)
 Append specified entry.
virtual void Append (const T &rElem)
 Append specified entry.
virtual void Append (T *rElem)
 Append specified entry.
virtual void Append (const std::string &rFileName)
 Append specified entry.
void FilenameAt (const Position &pos, const std::string &rFileName)
 Specify a filename.
const std::string & FilenameAt (const Position &pos) const
 Get filename of entry.
void TakeOwnership (void)
 Take ownership of all entries.
void TakeCopies (void)
 Take local copies of all entries.

Protected Types

typedef std::vector< Element >
::iterator 
iterator
 convenience typedef

Protected Member Functions

virtual void DoDWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Token output, debugging see Type::DWrite for public wrappers.
virtual void DoSWrite (TokenWriter &rTw) const
 Token output, see Type::SWrite for public wrappers.
virtual void DoWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Token output, see Type::Write for public wrappers.
virtual void DoRead (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 Token input, see Type::Read for public wrappers.
virtual TBaseVectorDoAssign (const TBaseVector< T > &rSourceVector)
 Assignment method.

Protected Attributes

std::vector< ElementmVector
 STL vector of element.

Private Attributes

std::string mMyName
 Name of TBaseVector.

Classes

class  Element
 Internal entry data type. More...

Member Typedef Documentation

template<class T>
typedef std::vector<int>::size_type faudes::TBaseVector< T >::Position

convenience typedef for positions

Definition at line 154 of file basevector.h.

template<class T>
typedef std::vector<Element>::iterator faudes::TBaseVector< T >::iterator [protected]

convenience typedef

Definition at line 466 of file basevector.h.


Constructor & Destructor Documentation

template<class T>
faudes::TBaseVector< T >::TBaseVector ( void   )  [inline]

Constructor.

Definition at line 503 of file basevector.h.

template<class T>
faudes::TBaseVector< T >::TBaseVector ( const TBaseVector< T > &  rOtherSet  )  [inline]

Copy-constructor.

Parameters:
rOtherSet Source to copy from

Definition at line 525 of file basevector.h.

template<class T>
faudes::TBaseVector< T >::TBaseVector ( const std::string &  rFilename,
const std::string &  rLabel = "BaseVector" 
) [inline]

Constructor from file.

Parameters:
rFilename Name of File
rLabel Section for the set in the file;

Definition at line 513 of file basevector.h.

template<class T>
faudes::TBaseVector< T >::~TBaseVector ( void   )  [inline, virtual]

Virtual destructor.

Definition at line 533 of file basevector.h.


Member Function Documentation

template<class T>
TBaseVector< T > * faudes::TBaseVector< T >::New ( void   )  const [inline, virtual]

Construct on heap.

Technically not a constructor, this function creates an object with the same type Type. New() is defined as a virtual function and derived classes are meant to re-implement with the appropiate constructor. This can be done via the provided macros FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION. As with new, it is the callers reponsabilty to delete the object when no longer needed.

Returns:
Pointer to new Type object

Reimplemented from faudes::Type.

Definition at line 499 of file basevector.h.

template<class T>
TBaseVector< T > * faudes::TBaseVector< T >::Copy ( void   )  const [inline, virtual]

Construct on heap.

Technically not a constructor, this function creates an object with the same type Type and the same configuration. Copy() is defined as a virtual function and derived classes are meant to re-implement with the appropiate copy constructor. This can be done via the provided macros FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION. As with new, it is the callers reponsabilty to delete the object when no longer needed.

Returns:
Pointer to new Type object

Reimplemented from faudes::Type.

Definition at line 499 of file basevector.h.

template<class T>
const TBaseVector< T > * faudes::TBaseVector< T >::Cast ( const Type pOther  )  const [inline, virtual]

Cast other object to this type.

Enables the run-time interface to test whether pObject is derived from this object. This feature is used e.g. in the faudes container classes to test attributes. Derived classes must reimplement this function using the appropriate dynamic cast.

Re-implementation can be done via the convenience macros FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.

Returns:
Typed pointer object

Reimplemented from faudes::Type.

Definition at line 499 of file basevector.h.

template<class T>
TBaseVector< T > & faudes::TBaseVector< T >::Assign ( const Type rSrc  )  [inline, virtual]

Assign configuration data from other object.

Derived classes should reimplement this method to first try to cast the source to the respective class. If successful, the protected function DoAssign is invoked to perform the actual assignment. If the cast fails, the Assign method of the parent class is called. Thus, faudes objects are up- and downcatsted for assignment, maintaining as much of the source data as digestable by the destination object. On the downside, there is no sensible typechecking at compile-time.

Re-implementation can be done via the convenience macros FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.

Parameters:
rSrc Source to copy from
Returns:
Reference to this object.

Reimplemented from faudes::Type.

Definition at line 499 of file basevector.h.

template<class T>
bool faudes::TBaseVector< T >::Equal ( const Type rOther  )  const [inline, virtual]

Test equality of configuration data.

Derived classes should reimplement this method to return true if both actual types and configuration data match. The object name is not consired in the test.

This method calls the virtual method DoEqual(). Re-implementation can be done via the convenience macros FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.

Parameters:
rOther Other objevt to compare with.
Returns:
True on match.

Reimplemented from faudes::Type.

Definition at line 499 of file basevector.h.

template<class T>
TBaseVector< T > & faudes::TBaseVector< T >::operator= ( const TBaseVector< T > &  rSrc  )  [inline, virtual]

Definition at line 499 of file basevector.h.

template<class T>
bool faudes::TBaseVector< T >::operator== ( const TBaseVector< T > &  rOther  )  const [inline, virtual]

Definition at line 499 of file basevector.h.

template<class T>
bool faudes::TBaseVector< T >::operator!= ( const TBaseVector< T > &  rOther  )  const [inline, virtual]

Definition at line 499 of file basevector.h.

template<class T>
const std::string & faudes::TBaseVector< T >::Name ( void   )  const [inline, virtual]

Return name of TBaseVector.

Returns:
Name of TBaseVector

Reimplemented from faudes::Type.

Definition at line 575 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::Name ( const std::string &  rName  )  [inline, virtual]

Set name of TBaseVector.

Parameters:
rName Name to set

Reimplemented from faudes::Type.

Definition at line 580 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::Clear ( void   )  [inline, virtual]

Clear all vector.

Reimplemented from faudes::Type.

Definition at line 564 of file basevector.h.

template<class T>
Idx faudes::TBaseVector< T >::Size ( void   )  const [inline]

Get size of vector.

Returns:
Number of entries.

Definition at line 585 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::Size ( Idx  len  )  [inline]

Set size of vector.

If the new size is smaller than the current size, the vector is truncated. If it is larger, default members are inserted at the end.

Parameters:
len Number of entries in vector

Definition at line 590 of file basevector.h.

template<class T>
bool faudes::TBaseVector< T >::Empty ( void   )  const [inline]

Check if the TBaseVector ist Empty.

Returns:
True if empty

Definition at line 611 of file basevector.h.

template<class T>
const T & faudes::TBaseVector< T >::At ( const Position pos  )  const [inline, virtual]

Access elemend.

Parameters:
pos Specify entry to access
Exceptions:
Exception 
  • Position out of range (id 69)

Definition at line 617 of file basevector.h.

template<class T>
T & faudes::TBaseVector< T >::At ( const Position pos  )  [inline, virtual]

Access elemend.

Parameters:
pos Specify entry to access
Exceptions:
Exception 
  • Position out of range (id 69)

Definition at line 629 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::Replace ( const Position pos,
const T &  rElem 
) [inline, virtual]

Replace specified entry.

This method takes a copy of the entry to replace and the vector becomes the owner of the copy.

Parameters:
pos Position to replace
rElem New entry
Exceptions:
Exception 
  • Position out of range (id 69)

Definition at line 643 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::Replace ( const Position pos,
T *  pElem 
) [inline, virtual]

Replace specified entry.

This method avoids to copy the entry to replace and only records the reference. The vector does not take ownership of the new entry. I.e., when the vector is destroyed, or the entry is deleted from the vector, the entry itself remains allocated.

Parameters:
pos Position to replace
pElem New entry
Exceptions:
Exception 
  • Position out of range (id 69)

Definition at line 659 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::Replace ( const Position pos,
const std::string &  rFileName 
) [inline, virtual]

Replace specified entry.

This method reads the sepcified entry from file and the vector becomes the owner of the new entry.

Parameters:
pos Position to replace
rFileName New entry to be read from file
Exceptions:
Exception 
  • Position out of range (id 69)

Definition at line 675 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::Erase ( const Position pos  )  [inline, virtual]

Erase entry by position.

If the vector owns the entry, it will be destructed.

Parameters:
pos Specify entry to erase
Exceptions:
Exception 
  • Position out of range (id 69)

Definition at line 692 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::Insert ( const Position pos,
const T &  rElem 
) [inline, virtual]

Insert specified entry.

This method takes a copy of the entry to replace and the vector becomes the owner of the copy.

Parameters:
pos Position at which to insert
rElem Element to insert
Exceptions:
Exception 
  • Position out of range (id 69)

Definition at line 707 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::Insert ( const Position pos,
T *  rElem 
) [inline, virtual]

Insert specified entry.

This method avoids to copy the entry to replace and only records the reference. The vector does not take ownership of the new entry. I.e., when the vector is destroyed, or the entry is deleted from the vector, the entry itself remains allocated.

Parameters:
pos Position at which to insert
rElem Element to insert
Exceptions:
Exception 
  • Position out of range (id 69)

Definition at line 724 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::Insert ( const Position pos,
const std::string &  rFileName 
) [inline, virtual]

Insert specified entry.

This method reads the sepcified entry from file and the vector becomes the owner of the new entry.

Parameters:
pos Position at which to insert
rFileName Element to insert
Exceptions:
Exception 
  • Position out of range (id 69)

Definition at line 741 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::PushBack ( const T &  rElem  )  [inline, virtual]

Append specified entry.

This method takes a copy of the entry to replace and the vector becomes the owner of the copy.

Parameters:
rElem Element to append

Definition at line 760 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::PushBack ( T *  rElem  )  [inline, virtual]

Append specified entry.

This method avoids to copy the entry to replace and only records the reference. The vector does not take ownership of the new entry. I.e., when the vector is destroyed, or the entry is deleted from the vector, the entry itself remains allocated.

Parameters:
rElem Element to insert

Definition at line 769 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::PushBack ( const std::string &  rFileName  )  [inline, virtual]

Append specified entry.

This method reads the sepcified entry from file and the vector becomes the owner of the new entry.

Parameters:
rFileName Element to insert

Definition at line 778 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::Append ( const T &  rElem  )  [inline, virtual]

Append specified entry.

Synonymous for PushBack. This method takes a copy of the entry to replace and the vector becomes the owner of the copy.

Parameters:
rElem Element to append

Definition at line 789 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::Append ( T *  rElem  )  [inline, virtual]

Append specified entry.

Synonymous for PushBack. This method avoids to copy the entry to replace and only records the reference. The vector does not take ownership of the new entry. I.e., when the vector is destroyed, or the entry is deleted from the vector, the entry itself remains allocated.

Parameters:
rElem Element to insert

Definition at line 794 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::Append ( const std::string &  rFileName  )  [inline, virtual]

Append specified entry.

Synonymous for PushBack. This method reads the sepcified entry from file and the vector becomes the owner of the new entry.

Parameters:
rFileName Element to insert

Definition at line 799 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::FilenameAt ( const Position pos,
const std::string &  rFileName 
) [inline]

Specify a filename.

When each entry has a filenam specified, file io of the vector will be to indivudual files.

Parameters:
pos Position of entry
rFileName Filename relative to vector file
Exceptions:
Exception 
  • Position out of range (id 69)

Definition at line 817 of file basevector.h.

template<class T>
const std::string & faudes::TBaseVector< T >::FilenameAt ( const Position pos  )  const [inline]

Get filename of entry.

Parameters:
pos Position of entry
Returns:
Filename assoiated with entry
Exceptions:
Exception 
  • Position out of range (id 69)

Definition at line 805 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::TakeOwnership ( void   )  [inline]

Take ownership of all entries.

Thsi method will take ownership of all entries, including those, that have been set by pointer reference. When the vector is destructed, all entries will be destructed, too. However, write access may invalidate element pointers.

Definition at line 839 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::TakeCopies ( void   )  [inline]

Take local copies of all entries.

This method will construct local copies of all entries not previously owned.

Definition at line 829 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::DoDWrite ( TokenWriter rTw,
const std::string &  rLabel = "",
const Type pContext = 0 
) const [inline, protected, virtual]

Token output, debugging see Type::DWrite for public wrappers.

The method assumes that the type parameter is a faudes type and uses the provide write method per entry. Reimplement this function in derived classes for non-faudes type vectors.

Parameters:
rTw Reference to TokenWriter
rLabel Label of section to write, defaults to name of set
pContext Write context to provide contextual information

Reimplemented from faudes::Type.

Definition at line 877 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::DoSWrite ( TokenWriter rTw  )  const [inline, protected, virtual]

Token output, see Type::SWrite for public wrappers.

The method assumes that the type parameter is a faudes type and uses the provide write method per entry. Reimplement this function in derived classes for non-faudes type vectors.

Parameters:
rTw Reference to TokenWriter
Exceptions:
Exception 
  • IO errors (id 2)

Reimplemented from faudes::Type.

Definition at line 890 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::DoWrite ( TokenWriter rTw,
const std::string &  rLabel = "",
const Type pContext = 0 
) const [inline, protected, virtual]

Token output, see Type::Write for public wrappers.

The method assumes that the type parameter is a faudes type and uses the provide write method per entry. Reimplement this function in derived classes for non-faudes type vectors.

Parameters:
rTw Reference to TokenWriter
rLabel Label of section to write, defaults to name of set
pContext Write context to provide contextual information

Reimplemented from faudes::Type.

Definition at line 846 of file basevector.h.

template<class T>
void faudes::TBaseVector< T >::DoRead ( TokenReader rTr,
const std::string &  rLabel = "",
const Type pContext = 0 
) [inline, protected, virtual]

Token input, see Type::Read for public wrappers.

The method assumes that the type parameter is a faudes type and uses the provide read method per entry. Reimplement this function in derived classes for non-faudes type vectors. By convention, the default label "" should be translated to some meaningful default, eg "GeneratorVector" for a vector of generators. The pContext pointer can be type-checked and interpreted, ie as a symboltable to provide symbolic names. It is also passed on to vector entries.

Parameters:
rTr Reference to TokenReader
rLabel Label of section to read, defaults to name of set
pContext Read context to provide contextual information

Reimplemented from faudes::Type.

Definition at line 902 of file basevector.h.

template<class T>
TBaseVector< T > & faudes::TBaseVector< T >::DoAssign ( const TBaseVector< T > &  rSourceVector  )  [inline, protected, virtual]

Assignment method.

Definition at line 544 of file basevector.h.


Member Data Documentation

template<class T>
std::vector<Element> faudes::TBaseVector< T >::mVector [protected]

STL vector of element.

Definition at line 463 of file basevector.h.

template<class T>
std::string faudes::TBaseVector< T >::mMyName [private]

Name of TBaseVector.

Definition at line 471 of file basevector.h.


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

libFAUDES 2.14g --- 2009-12-3 --- c++ source docu by doxygen 1.5.6