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

#include <cfl_basevector.h>

Classes

class  ElementRecord
 

Public Types

typedef size_t Position
 

Public Member Functions

 vBaseVector (void)
 
 vBaseVector (const vBaseVector &rOtherVector)
 
 vBaseVector (const std::string &rFilename, const std::string &rLabel="Vector")
 
virtual ~vBaseVector (void)
 
void AssignByReference (vBaseVector &rSourceVector)
 
virtual const TypeElementp (void) const
 
virtual const TypeElement (void) const
 
virtual TypeNewElement (void)
 
virtual bool ElementTry (const Type &rElement) const
 
virtual void Clear (void)
 
Idx Size (void) const
 
void Size (Idx len)
 
bool IsDefault (void) const
 
bool Empty (void) const
 
virtual const TypeAt (const Position &pos) const
 
virtual TypeAt (const Position &pos)
 
virtual void Replace (const Position &pos, const Type &rElem)
 
virtual void Replace (const Position &pos, Type *pElem)
 
virtual void Replace (const Position &pos, const std::string &rFileName)
 
virtual void Erase (const Position &pos)
 
virtual void Insert (const Position &pos, const Type &rElem)
 
virtual void Insert (const Position &pos, Type *pElem)
 
virtual void Insert (const Position &pos, const std::string &rFileName)
 
virtual void PushBack (const Type &rElem)
 
virtual void PushBack (Type *rElem)
 
virtual void PushBack (const std::string &rFileName)
 
virtual void Append (const Type &rElem)
 
virtual void Append (Type *rElem)
 
virtual void Append (const std::string &rFileName)
 
virtual Position Find (const Type &rElem)
 
virtual void EraseDoublets (void)
 
void FilenameAt (const Position &pos, const std::string &rFileName)
 
const std::string & FilenameAt (const Position &pos) const
 
void TakeOwnership (void)
 
void TakeCopies (void)
 
- Public Member Functions inherited from faudes::ExtType
 ExtType (void)
 
 ExtType (const ExtType &rType)
 
virtual ~ExtType (void)
 
const std::string & Name (void) const
 
void Name (const std::string &rName)
 
virtual const std::string & TypeName (void) const
 
virtual void TypeName (const std::string &rType)
 
virtual const std::string & ElementTag (void) const
 
virtual void ElementTag (const std::string &rTag)
 
virtual const std::string & ElementType (void) const
 
virtual const TypeDefinitionTypeDefinitionp (void) const
 
Typeoperator= (const Type &rSrc)
 
bool operator== (const Type &rOther) const
 
bool operator!= (const Type &rOther) const
 
- Public Member Functions inherited from faudes::AttrType
 AttrType (void)
 
 AttrType (const AttrType &rSrc)
 
virtual ~AttrType (void)
 
Typeoperator= (const Type &rSrc)
 
bool operator== (const Type &rOther) const
 
bool operator!= (const Type &rOther) const
 
- Public Member Functions inherited from faudes::Type
 Type (void)
 
 Type (const Type &rType)
 
virtual ~Type (void)
 
virtual TypeNew (void) const
 
virtual TypeCopy (void) const
 
virtual const TypeCast (const Type *pOther) const
 
virtual TypeAssign (const Type &rSrc)
 
Typeoperator= (const Type &rSrc)
 
virtual bool Equal (const Type &rOther) const
 
bool operator== (const Type &rOther) const
 
bool operator!= (const Type &rOther) const
 
void Write (const Type *pContext=0) const
 
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
 
void Write (const std::string &pFileName, std::ios::openmode openmode) const
 
void Write (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
virtual void XWrite (const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0) const
 
void XWrite (const Type *pContext=0) const
 
void XWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
std::string ToString (const std::string &rLabel="", const Type *pContext=0) const
 
std::string ToText (const std::string &rLabel="", const Type *pContext=0) const
 
void DWrite (const Type *pContext=0) const
 
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
 
void DWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
void SWrite (TokenWriter &rTw) const
 
void SWrite (void) const
 
std::string ToSText (void) const
 
void Read (const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
 
void FromString (const std::string &rString, const std::string &rLabel="", const Type *pContext=0)
 
void Read (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 

Protected Types

typedef std::vector< ElementRecord >::iterator iterator
 

Protected Member Functions

virtual void DoDWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
virtual void DoSWrite (TokenWriter &rTw) const
 
virtual void DoWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
virtual void DoXWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
virtual void DoRead (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 
void DoAssign (const vBaseVector &rSourceVector)
 
bool DoEqual (const vBaseVector &rOther) const
 
- Protected Member Functions inherited from faudes::AttrType
void DoAssign (const AttrType &rSrc)
 
bool DoEqual (const AttrType &rOther) const
 
- Protected Member Functions inherited from faudes::Type
void DoAssign (const Type &rSrc)
 
bool DoEqual (const Type &rOther) const
 
virtual Token XBeginTag (const std::string &rLabel="", const std::string &rFallbackLabel="") const
 

Protected Attributes

std::vector< ElementRecordmVector
 
std::string mElementTagDef
 
- Protected Attributes inherited from faudes::ExtType
std::string mElementType
 
std::string mElementTagDef
 
std::string mObjectName
 

Private Attributes

std::string mFaudesTypeName
 
std::string mElementTag
 
std::string mMyName
 

Additional Inherited Members

- Static Public Member Functions inherited from faudes::AttrType
static void Skip (TokenReader &rTr)
 

Member Typedef Documentation

◆ iterator

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

convenience typedef

Definition at line 582 of file cfl_basevector.h.

◆ Position

convenience typedef for positions (must be unsigned)

Definition at line 210 of file cfl_basevector.h.

Constructor & Destructor Documentation

◆ vBaseVector() [1/3]

faudes::vBaseVector::vBaseVector ( void  )

Constructor.

Definition at line 49 of file cfl_basevector.cpp.

◆ vBaseVector() [2/3]

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

Copy-constructor.

This will copy the actual elements and we will take ownership of the copies. If the elements are fauddes sets, the performance penalty will only show oncle we write to an element.

Parameters
rOtherVectorSource to copy from.

Definition at line 73 of file cfl_basevector.cpp.

◆ vBaseVector() [3/3]

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

Constructor from file.

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

Definition at line 60 of file cfl_basevector.cpp.

◆ ~vBaseVector()

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

Virtual destructor

Definition at line 81 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 429 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 419 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 424 of file cfl_basevector.cpp.

◆ AssignByReference()

void faudes::vBaseVector::AssignByReference ( vBaseVector rSourceVector)

Assign by reference

This method will take references from the source entry, i.e., it will not take copies and will not attain ownership. The caller is hence responsible for the livetime of the elements. To obtain a full copy, use the copy constror or Assign() instead.

Definition at line 136 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 >, faudes::TBaseVector< EventSet >, faudes::TBaseVector< Generator >, and faudes::TBaseVector< RabinPair >.

Definition at line 229 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 >, faudes::TBaseVector< EventSet >, faudes::TBaseVector< Generator >, and faudes::TBaseVector< RabinPair >.

Definition at line 217 of file cfl_basevector.cpp.

◆ Clear()

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

Clear all vector

Reimplemented from faudes::Type.

Definition at line 158 of file cfl_basevector.cpp.

◆ DoAssign()

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

Assignment method (we will take copies and own all those thereafter)

Definition at line 113 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 567 of file cfl_basevector.cpp.

◆ DoEqual()

bool faudes::vBaseVector::DoEqual ( const vBaseVector rOther) const
protected

Test equality of configuration data.

To be equal, all elements must match.

Parameters
rOtherOther object to compare with.
Returns
True on match.

Definition at line 168 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 592 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.

Reimplemented in faudes::RabinAcceptance.

Definition at line 580 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 506 of file cfl_basevector.cpp.

◆ DoXWrite()

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

Token output strict XML, see Type::XWrite for public wrappers. The method assumes that the type parameter is a faudes type and uses the provide writed 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 537 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 98 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 >, faudes::TBaseVector< EventSet >, faudes::TBaseVector< Generator >, and faudes::TBaseVector< RabinPair >.

Definition at line 92 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 >, faudes::TBaseVector< EventSet >, faudes::TBaseVector< Generator >, and faudes::TBaseVector< RabinPair >.

Definition at line 108 of file cfl_basevector.cpp.

◆ Empty()

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

Check if the vBaseVector is Empty (amounts to the default configuration)

Returns
True if empty

Definition at line 212 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 302 of file cfl_basevector.cpp.

◆ EraseDoublets()

void faudes::vBaseVector::EraseDoublets ( void  )
virtual

Cnsolidate by removing doublets. This method iterates through the vector to find ad eliminate semantical doublets; i.e., it refers to equality as implementyed by the faudes type method DoEqual. This is generally inefficient, consider to use an ordered set instead.

Definition at line 449 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 465 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 filename specified, file io of the vector will be to individual files.

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

Definition at line 477 of file cfl_basevector.cpp.

◆ Find()

vBaseVector::Position faudes::vBaseVector::Find ( const Type rElem)
virtual

Find element. This method iterates through the vector to find a matching element. This is generally inefficient, consider to use an ordered set instead.

Parameters
rElemElement to serach for
Returns
Position on success (or >= Size() for not found)
Exceptions
Exception
  • Cannot cast element type (63)

Definition at line 435 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 361 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 be inserted 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 317 of file cfl_basevector.cpp.

◆ Insert() [3/3]

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

Insert specified entry. This method avoids to make a copy and inserts only a reference. The caller remains the owner and is responsable for destruction.

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

◆ IsDefault()

bool faudes::vBaseVector::IsDefault ( void  ) const
virtual

Check for default configuration aka empty

Returns
True if empty

Reimplemented from faudes::AttrType.

Definition at line 207 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 103 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 408 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 380 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 394 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 285 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 243 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 264 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 186 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 181 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 489 of file cfl_basevector.cpp.

◆ TakeOwnership()

void faudes::vBaseVector::TakeOwnership ( void  )

Take ownership of all entries. This 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 499 of file cfl_basevector.cpp.

Member Data Documentation

◆ mElementTag

std::string faudes::vBaseVector::mElementTag
private

Current/cached name of elements (use protected accessor methods for caching)

Definition at line 590 of file cfl_basevector.h.

◆ mElementTagDef

std::string faudes::vBaseVector::mElementTagDef
protected

Defauft name of elements (if not over written by registry)

Definition at line 595 of file cfl_basevector.h.

◆ mFaudesTypeName

std::string faudes::vBaseVector::mFaudesTypeName
private

Current/cached faudes type-name

Definition at line 587 of file cfl_basevector.h.

◆ mMyName

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

Name of TBaseVector

Definition at line 600 of file cfl_basevector.h.

◆ mVector

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

STL vector of element

Definition at line 579 of file cfl_basevector.h.


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

libFAUDES 2.33h --- 2025.06.18 --- c++ api documentaion by doxygen