Detailed Description

Vector bass class.

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. As with other faudes containers, vBaseVector is the universal base class for all faudes vector data types. The latter explicitely refer to the element data type and are implemented as templates.

Internally, the vBaseVector 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.

vBaseVector 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 70 of file cfl_basevector.h.

#include <cfl_basevector.h>

Classes

class  ElementRecord
 Internal entry data type. More...
 

Public Types

typedef size_t Position
 convenience typedef for positions (must be unsigned) More...
 

Public Member Functions

 vBaseVector (void)
 Constructor. More...
 
 vBaseVector (const vBaseVector &rOtherVector)
 Copy-constructor. More...
 
 vBaseVector (const std::string &rFilename, const std::string &rLabel="BaseVector")
 Constructor from file. More...
 
virtual ~vBaseVector (void)
 Virtual destructor. More...
 
virtual const TypeElementp (void) const
 Prototype for vector entries. More...
 
virtual const TypeElement (void) const
 Prototype for vector entries. More...
 
virtual TypeNewElement (void)
 Factory method for vector entries. More...
 
virtual bool ElementTry (const Type &rElement) const
 Test whether the specified element is acceptebla for this vector. More...
 
const std::string & Name (void) const
 Return name of vBaseVector. More...
 
void Name (const std::string &rName)
 Set name of vBaseVector. More...
 
virtual void Clear (void)
 Clear all vector. More...
 
Idx Size (void) const
 Get size of vector. More...
 
void Size (Idx len)
 Set size of vector. More...
 
bool Empty (void) const
 Check if the vBaseVector ist Empty. More...
 
virtual const TypeAt (const Position &pos) const
 Access element. More...
 
virtual TypeAt (const Position &pos)
 Access element. More...
 
virtual void Replace (const Position &pos, const Type &rElem)
 Replace specified entry. More...
 
virtual void Replace (const Position &pos, Type *pElem)
 Replace specified entry. More...
 
virtual void Replace (const Position &pos, const std::string &rFileName)
 Replace specified entry. More...
 
virtual void Erase (const Position &pos)
 Erase entry by position. More...
 
virtual void Insert (const Position &pos, const Type &rElem)
 Insert specified entry. More...
 
virtual void Insert (const Position &pos, Type *rElem)
 Insert specified entry. More...
 
virtual void Insert (const Position &pos, const std::string &rFileName)
 Insert specified entry. More...
 
virtual void PushBack (const Type &rElem)
 Append specified entry. More...
 
virtual void PushBack (Type *rElem)
 Append specified entry. More...
 
virtual void PushBack (const std::string &rFileName)
 Append specified entry. More...
 
virtual void Append (const Type &rElem)
 Append specified entry. More...
 
virtual void Append (Type *rElem)
 Append specified entry. More...
 
virtual void Append (const std::string &rFileName)
 Append specified entry. More...
 
void FilenameAt (const Position &pos, const std::string &rFileName)
 Specify a filename. More...
 
const std::string & FilenameAt (const Position &pos) const
 Get filename of entry. More...
 
void TakeOwnership (void)
 Take ownership of all entries. More...
 
void TakeCopies (void)
 Take local copies of all entries. More...
 
- Public Member Functions inherited from faudes::Type
 Type (void)
 Constructor. More...
 
 Type (const Type &rType)
 Copy constructor. More...
 
virtual ~Type (void)
 Destructor. More...
 
virtual TypeNew (void) const
 Construct on heap. More...
 
virtual TypeCopy (void) const
 Construct on heap. More...
 
virtual const TypeCast (const Type *pOther) const
 Cast other object to this type. More...
 
virtual TypeAssign (const Type &rSrc)
 Assign configuration data from other object. More...
 
virtual Typeoperator= (const Type &rSrc)
 Assign configurationdata from other object. More...
 
virtual bool Equal (const Type &rOther) const
 Test equality of configuration data. More...
 
virtual bool operator== (const Type &rOther) const
 Test equality of configuration data. More...
 
virtual bool operator!= (const Type &rOther) const
 Test equality of configuration data. More...
 
virtual const std::string & TypeName (void) const
 Get objects's type name. More...
 
void Write (const Type *pContext=0) const
 Write configuration data to console. More...
 
void Write (const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0, std::ios::openmode openmode=std::ios::out|std::ios::trunc) const
 Write configuration data to a file. More...
 
void Write (const std::string &pFileName, std::ios::openmode openmode) const
 Write configuration data to a file. More...
 
void Write (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data to TokenWriter. More...
 
virtual void XWrite (const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data to an XML file. More...
 
void XWrite (const Type *pContext=0) const
 Write configuration data in XML format to concole Note: this write function uses the virtual function DoXWrite(), to be reimplemented by derived classes. More...
 
void XWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data in XML format to TokenWriter. More...
 
std::string ToString (const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data to a string. More...
 
std::string ToText (const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data to a formated string. More...
 
void DWrite (const Type *pContext=0) const
 Write configuration data to console, debugging format. More...
 
void DWrite (const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0, std::ios::openmode openmode=std::ios::out|std::ios::trunc) const
 Write configuration data to a file, debugging format. More...
 
void DWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data in debug format to TokenWriter. More...
 
void SWrite (TokenWriter &rTw) const
 Write statistics comment to TokenWriter. More...
 
void SWrite (void) const
 Write statistics comment to console. More...
 
std::string ToSText (void) const
 Write statistics to a string. More...
 
void Read (const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
 Read configuration data from file with label specified. More...
 
void FromString (const std::string &rString, const std::string &rLabel="", const Type *pContext=0)
 Read configuration data from a string. More...
 
void Read (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 Read configuration data from TokenReader with label sepcified. More...
 

Protected Types

typedef std::vector< ElementRecord >::iterator iterator
 convenience typedef More...
 

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. More...
 
virtual void DoSWrite (TokenWriter &rTw) const
 Token output, see Type::SWrite for public wrappers. More...
 
virtual void DoWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Token output, see Type::Write for public wrappers. More...
 
virtual void DoRead (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 Token input, see Type::Read for public wrappers. More...
 
void DoAssign (const vBaseVector &rSourceVector)
 Assignment method
More...
 
- Protected Member Functions inherited from faudes::Type
void DoAssign (const Type &rSrc)
 Assign configuration data from other object. More...
 
bool DoEqual (const Type &rOther) const
 Test equality of configuration data. More...
 
virtual void DoXWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data of this object to TokenWriter in XML format. More...
 
virtual const TypeDefinitionTypeDefinitionp (void) const
 Get objects's type definition. More...
 
virtual Token XBeginTag (const std::string &rLabel="", const std::string &rFallbackLabel="") const
 

Protected Attributes

std::vector< ElementRecordmVector
 STL vector of element. More...
 

Private Attributes

std::string mMyName
 Name of TBaseVector. More...
 

Member Typedef Documentation

◆ iterator

typedef std::vector<ElementRecord>::iterator faudes::vBaseVector::iterator
protected

convenience typedef

Definition at line 521 of file cfl_basevector.h.

◆ Position

convenience typedef for positions (must be unsigned)

Definition at line 197 of file cfl_basevector.h.

Constructor & Destructor Documentation

◆ vBaseVector() [1/3]

faudes::vBaseVector::vBaseVector ( void  )

Constructor.

Definition at line 46 of file cfl_basevector.cpp.

◆ vBaseVector() [2/3]

faudes::vBaseVector::vBaseVector ( const vBaseVector rOtherVector)

Copy-constructor.

Parameters
rOtherVectorSource to copy from

Definition at line 68 of file cfl_basevector.cpp.

◆ vBaseVector() [3/3]

faudes::vBaseVector::vBaseVector ( const std::string &  rFilename,
const std::string &  rLabel = "BaseVector" 
)

Constructor from file.

Parameters
rFilenameName of File
rLabelSection for the set in the file;

Definition at line 56 of file cfl_basevector.cpp.

◆ ~vBaseVector()

faudes::vBaseVector::~vBaseVector ( void  )
virtual

Virtual destructor.

Definition at line 76 of file cfl_basevector.cpp.

Member Function Documentation

◆ Append() [1/3]

void faudes::vBaseVector::Append ( const std::string &  rFileName)
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
rFileNameElement to insert

Definition at line 392 of file cfl_basevector.cpp.

◆ Append() [2/3]

void faudes::vBaseVector::Append ( const Type rElem)
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
rElemElement to append
Exceptions
Exception
  • Cannot cast element type (63)

Definition at line 382 of file cfl_basevector.cpp.

◆ Append() [3/3]

void faudes::vBaseVector::Append ( Type rElem)
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
rElemElement to insert
Exceptions
Exception
  • Cannot cast element type (63)

Definition at line 387 of file cfl_basevector.cpp.

◆ At() [1/2]

Type & faudes::vBaseVector::At ( const Position pos)
virtual

Access element.

Parameters
posSpecify entry to access
Exceptions
Exception
  • Position out of range (id 69)

Reimplemented in faudes::TBaseVector< T >, and faudes::TBaseVector< Generator >.

Definition at line 192 of file cfl_basevector.cpp.

◆ At() [2/2]

const Type & faudes::vBaseVector::At ( const Position pos) const
virtual

Access element.

Parameters
posSpecify entry to access
Exceptions
Exception
  • Position out of range (id 69)

Reimplemented in faudes::TBaseVector< T >, and faudes::TBaseVector< Generator >.

Definition at line 180 of file cfl_basevector.cpp.

◆ Clear()

void faudes::vBaseVector::Clear ( void  )
virtual

Clear all vector.

Reimplemented from faudes::Type.

Definition at line 127 of file cfl_basevector.cpp.

◆ DoAssign()

void faudes::vBaseVector::DoAssign ( const vBaseVector rSourceVector)
protected

Assignment method

Definition at line 108 of file cfl_basevector.cpp.

◆ DoDWrite()

void faudes::vBaseVector::DoDWrite ( TokenWriter rTw,
const std::string &  rLabel = "",
const Type pContext = 0 
) const
protectedvirtual

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
rTwReference to TokenWriter
rLabelLabel of section to write, defaults to name of set
pContextWrite context to provide contextual information

Reimplemented from faudes::Type.

Definition at line 469 of file cfl_basevector.cpp.

◆ DoRead()

void faudes::vBaseVector::DoRead ( TokenReader rTr,
const std::string &  rLabel = "",
const Type pContext = 0 
)
protectedvirtual

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
rTrReference to TokenReader
rLabelLabel of section to read, defaults to name of set
pContextRead context to provide contextual information

Reimplemented from faudes::Type.

Definition at line 494 of file cfl_basevector.cpp.

◆ DoSWrite()

void faudes::vBaseVector::DoSWrite ( TokenWriter rTw) const
protectedvirtual

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
rTwReference to TokenWriter
Exceptions
Exception
  • IO errors (id 2)

Reimplemented from faudes::Type.

Definition at line 482 of file cfl_basevector.cpp.

◆ DoWrite()

void faudes::vBaseVector::DoWrite ( TokenWriter rTw,
const std::string &  rLabel = "",
const Type pContext = 0 
) const
protectedvirtual

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
rTwReference to TokenWriter
rLabelLabel of section to write, defaults to name of set
pContextWrite context to provide contextual information

Reimplemented from faudes::Type.

Definition at line 439 of file cfl_basevector.cpp.

◆ Element()

const Type & faudes::vBaseVector::Element ( void  ) const
virtual

Prototype for vector entries.

This is a convenience wrapper for Elementp.

Returns
Element protoype

Definition at line 93 of file cfl_basevector.cpp.

◆ Elementp()

const Type * faudes::vBaseVector::Elementp ( void  ) const
virtual

Prototype for vector entries.

The virtual base vBaseVector will provide a plain Type object. Derived vector classes are meant to reimplement this function.

Returns
Element protoype

Reimplemented in faudes::TBaseVector< T >, and faudes::TBaseVector< Generator >.

Definition at line 87 of file cfl_basevector.cpp.

◆ ElementTry()

bool faudes::vBaseVector::ElementTry ( const Type rElement) const
virtual

Test whether the specified element is acceptebla for this vector.

This is a convenience wrapper for Elementp.

Parameters
rElementElement to type check.
Returns
True, if provided element is accepted by this vector.

Reimplemented in faudes::TBaseVector< T >, and faudes::TBaseVector< Generator >.

Definition at line 103 of file cfl_basevector.cpp.

◆ Empty()

bool faudes::vBaseVector::Empty ( void  ) const

Check if the vBaseVector ist Empty.

Returns
True if empty

Definition at line 174 of file cfl_basevector.cpp.

◆ Erase()

void faudes::vBaseVector::Erase ( const Position pos)
virtual

Erase entry by position.

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

Parameters
posSpecify entry to erase
Exceptions
Exception
  • Position out of range (id 69)

Definition at line 265 of file cfl_basevector.cpp.

◆ FilenameAt() [1/2]

const std::string & faudes::vBaseVector::FilenameAt ( const Position pos) const

Get filename of entry.

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

Definition at line 398 of file cfl_basevector.cpp.

◆ FilenameAt() [2/2]

void faudes::vBaseVector::FilenameAt ( const Position pos,
const std::string &  rFileName 
)

Specify a filename.

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

Parameters
posPosition of entry
rFileNameFilename relative to vector file
Exceptions
Exception
  • Position out of range (id 69)

Definition at line 410 of file cfl_basevector.cpp.

◆ Insert() [1/3]

void faudes::vBaseVector::Insert ( const Position pos,
const std::string &  rFileName 
)
virtual

Insert specified entry.

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

Parameters
posPosition at which to insert
rFileNameElement to insert
Exceptions
Exception
  • Position out of range (id 69)

Definition at line 324 of file cfl_basevector.cpp.

◆ Insert() [2/3]

void faudes::vBaseVector::Insert ( const Position pos,
const Type rElem 
)
virtual

Insert specified entry.

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

Parameters
posPosition at which to insert
rElemElement to insert
Exceptions
Exception
  • Position out of range (id 69)
  • Cannot cast element type (63)

Definition at line 280 of file cfl_basevector.cpp.

◆ Insert() [3/3]

void faudes::vBaseVector::Insert ( const Position pos,
Type rElem 
)
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
posPosition at which to insert
rElemElement to insert
Exceptions
Exception
  • Position out of range (id 69)
  • Cannot cast element type (63)

Definition at line 302 of file cfl_basevector.cpp.

◆ Name() [1/2]

void faudes::vBaseVector::Name ( const std::string &  rName)
virtual

Set name of vBaseVector.

Parameters
rNameName to set

Reimplemented from faudes::Type.

Definition at line 143 of file cfl_basevector.cpp.

◆ Name() [2/2]

const std::string & faudes::vBaseVector::Name ( void  ) const
virtual

Return name of vBaseVector.

Returns
Name of vBaseVector

Reimplemented from faudes::Type.

Definition at line 138 of file cfl_basevector.cpp.

◆ NewElement()

Type * faudes::vBaseVector::NewElement ( void  )
virtual

Factory method for vector entries.

This is a convenience wrapper using Elementp.

Returns
New element allocated on heap

Definition at line 98 of file cfl_basevector.cpp.

◆ PushBack() [1/3]

void faudes::vBaseVector::PushBack ( const std::string &  rFileName)
virtual

Append specified entry.

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

Parameters
rFileNameElement to insert

Definition at line 371 of file cfl_basevector.cpp.

◆ PushBack() [2/3]

void faudes::vBaseVector::PushBack ( const Type rElem)
virtual

Append specified entry.

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

Parameters
rElemElement to append
Exceptions
Exception
  • Cannot cast element type (63)

Definition at line 343 of file cfl_basevector.cpp.

◆ PushBack() [3/3]

void faudes::vBaseVector::PushBack ( Type rElem)
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
rElemElement to insert
Exceptions
Exception
  • Cannot cast element type (63)

Definition at line 357 of file cfl_basevector.cpp.

◆ Replace() [1/3]

void faudes::vBaseVector::Replace ( const Position pos,
const std::string &  rFileName 
)
virtual

Replace specified entry.

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

Parameters
posPosition to replace
rFileNameNew entry to be read from file
Exceptions
Exception
  • Position out of range (id 69)

Definition at line 248 of file cfl_basevector.cpp.

◆ Replace() [2/3]

void faudes::vBaseVector::Replace ( const Position pos,
const Type rElem 
)
virtual

Replace specified entry.

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

Parameters
posPosition to replace
rElemNew entry
Exceptions
Exception
  • Position out of range (id 69)
  • Cannot cast element type (63)

Definition at line 206 of file cfl_basevector.cpp.

◆ Replace() [3/3]

void faudes::vBaseVector::Replace ( const Position pos,
Type pElem 
)
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
posPosition to replace
pElemNew entry
Exceptions
Exception
  • Position out of range (id 69)
  • Cannot cast element type (63)

Definition at line 227 of file cfl_basevector.cpp.

◆ Size() [1/2]

void faudes::vBaseVector::Size ( Idx  len)

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
lenNumber of entries in vector

Definition at line 153 of file cfl_basevector.cpp.

◆ Size() [2/2]

Idx faudes::vBaseVector::Size ( void  ) const

Get size of vector.

Returns
Number of entries.

Definition at line 148 of file cfl_basevector.cpp.

◆ TakeCopies()

void faudes::vBaseVector::TakeCopies ( void  )

Take local copies of all entries.

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

Definition at line 422 of file cfl_basevector.cpp.

◆ TakeOwnership()

void faudes::vBaseVector::TakeOwnership ( void  )

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 432 of file cfl_basevector.cpp.

Member Data Documentation

◆ mMyName

std::string faudes::vBaseVector::mMyName
private

Name of TBaseVector.

Definition at line 526 of file cfl_basevector.h.

◆ mVector

std::vector<ElementRecord> faudes::vBaseVector::mVector
protected

STL vector of element.

Definition at line 518 of file cfl_basevector.h.


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

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen