Detailed Description

template<class T, class Cmp = std::less<T>>
class faudes::TBaseSet< T, Cmp >

STL style set template. This class template is built on top of the STL set template. It provides essentials of the STL interface relevant to libFAUDES plus a deferred copy mechanism, aka copy-on-write. TBaseSet serves as a base class for all libFaudes containers:

The public functions of a TBaseSet provide the high-level api, with the intention to organize the deferred copy machanism in a transparent manner. Since STL iterators refer to a particular STL container, they become invalid when the internal container is copied. Therefor, TBaseSet tracks iterators and fixes them when the actual copy takes place. This introduces some runtime overhead, in particular when your application represents subsets as sets of iterators. You may use the public method Lock() to enforce a full copy and to prevent any further re-allocation.

Alternatively to the high-level api, a protected low-level api is provided with direct access to the internal STL set. When using this api, it is up to the derived class to ensure that the BaseSet gets detached from its refernces befor write operations can take place.

The virtual function TBaseSet<T>::Valid() is used to indicate whether a candidate element is valid as a set member. If the macro FAUDES_CHECKED is defined, the attempt to insert an invalid element triggers an exception (id 61). Invalid iterators throw an exception (id 62) when used as an argument to a BaseSet function.

The TBaseSet also hosts a container to associate an attribute with each set element. However, in the plain TBAseSey the attribute type is set to void and member methods only deal with attributes when this does not invilve too much overhead. To make effective use of attributes, one is meant to derive a class from TBaseSet that encodes the actual attribute type and that provides appropriate access methods. This is facilitated by the class TAttrMap.

Note on a boring technical detail: since STL sets are sorted, effectively all set iterators should be const. However, there is a minor issue whether or not the erase function should use a const iterator as argument. SGI derived STL implementations (as used on most GNU systems) avoid this issue by defining const and non-const iterators on sets as identical types. MS implementation (used in VS C++ by default, as of 2006) differ in this aspect. The class TBaseSet::Iterator hides the issue from the faudes API but it is still present internaly.

Definition at line 98 of file cfl_baseset.h.

#include <cfl_baseset.h>

Classes

class  Iterator
 

Public Types

enum  DetachMode { SetOnly , AttrIncl }
 
typedef Iterator CIterator
 

Public Member Functions

 TBaseSet (void)
 
 TBaseSet (const TBaseSet &rOtherSet)
 
 TBaseSet (const std::string &rFilename, const std::string &rLabel="BaseSet")
 
virtual ~TBaseSet (void)
 
virtual void Clear (void)
 
virtual bool IsDefault (void) const
 
Idx Size (void) const
 
bool Empty (void) const
 
virtual std::string Str (const T &rElem) const
 
Iterator Begin (void) const
 
Iterator End (void) const
 
virtual bool Valid (const T &rElem) const
 
virtual bool Erase (const T &rElem)
 
virtual Iterator Erase (const Iterator &pos)
 
virtual void EraseSet (const TBaseSet &rOtherSet)
 
virtual void RestrictSet (const TBaseSet &rOtherSet)
 
virtual bool Disjoint (const TBaseSet &rOtherSet) const
 
virtual bool Insert (const T &rElem)
 
virtual Iterator Inject (const Iterator &pos, const T &rElem)
 
virtual void Inject (const T &rElem)
 
virtual void InsertSet (const TBaseSet &rOtherSet)
 
bool Exists (const T &rElem) const
 
Iterator Find (const T &rElem) const
 
TBaseSet operator+ (const TBaseSet &rOtherSet) const
 
TBaseSet operator- (const TBaseSet &rOtherSet) const
 
TBaseSet operator* (const TBaseSet &rOtherSet) const
 
bool operator<= (const TBaseSet &rOtherSet) const
 
bool operator>= (const TBaseSet &rOtherSet) const
 
bool operator< (const TBaseSet &rOtherSet) const
 
void DValid (const std::string &rMessage="") const
 
void Detach (DetachMode flag=AttrIncl) const
 
void Lock (void) const
 
virtual const AttributeVoidAttributeType (void) const
 
virtual bool AttributeTest (const Type &rAttr) const
 
virtual TBaseSetAssignWithoutAttributes (const TBaseSet &rSourceSet)
 
virtual void Attributes (const TBaseSet &rOtherSet)
 
Idx AttributesSize (void) const
 
void ClearAttributes (void)
 
bool EqualAttributes (const TBaseSet &rOtherSet) const
 
virtual AttributeVoidAttributep (const T &rElem)
 
virtual const AttributeVoidAttribute (const T &rElem) const
 
virtual void Attribute (const T &rElem, const Type &rAttr)
 
virtual void AttributeTry (const T &rElem, const Type &rAttr)
 
virtual void ClrAttribute (const T &rElem)
 
- 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::set< T, Cmp >::iterator iterator
 
typedef std::set< T, Cmp >::const_iterator const_iterator
 
typedef std::map< T, AttributeVoid * >::iterator aiterator
 
typedef std::map< T, AttributeVoid * >::const_iterator const_aiterator
 

Protected Member Functions

virtual void DoWriteElement (TokenWriter &rTw, const T &rElem, const std::string &rLabel="", const Type *pContext=0) const
 
virtual void DoXWriteElement (TokenWriter &rTw, const T &rElem, const std::string &rLabel="", const Type *pContext=0) const
 
virtual void DoReadElement (TokenReader &rTr, T &rElem, const std::string &rLabel, const Type *pContext)
 
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 DoDWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
virtual void DoSWrite (TokenWriter &rTw) const
 
virtual void DoRead (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 
void DoAssign (const TBaseSet &rSourceSet)
 
bool DoEqual (const TBaseSet &rOtherSet) const
 
void DoAttribute (const T &rElem, const Type *pAttr)
 
const AttributeVoidDoAttribute (const T &rElem) const
 
AttributeVoidDoAttributeExplicit (const T &rElem)
 
TBaseSet< T, Cmp >::Iterator ThisIterator (const typename std::set< T, Cmp >::const_iterator &sit) const
 
void RelinkClients (void)
 
void AttachClient (TBaseSet *pRef) const
 
void DetachClient (TBaseSet *pRef) const
 
void AttachIterator (Iterator *pFit) const
 
void DetachIterator (Iterator *pFit) 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::set< T, Cmp > * pSet
 
std::set< T, Cmp > * mpSet
 
std::map< T, AttributeVoid * > * pAttributes
 
std::map< T, AttributeVoid * > * mpAttributes
 
TBaseSet< T, Cmp > * pHostSet
 
std::list< TBaseSet< T, Cmp > * >::iterator mClientRecord
 
std::list< TBaseSet< T, Cmp > * > * mpClients
 
bool mDetached
 
bool mLocked
 
std::set< Iterator * > mIterators
 
- Protected Attributes inherited from faudes::ExtType
std::string mElementType
 
std::string mElementTagDef
 
std::string mObjectName
 

Static Protected Attributes

static std::set< T, Cmp > msEmptySet =std::set<T,Cmp>()
 
static std::map< T, AttributeVoid * > msEmptyAttributes =std::map<T,AttributeVoid*>()
 

Friends

template<class TP , class AP , class CP >
class TAttrMap
 

Additional Inherited Members

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

Member Typedef Documentation

◆ aiterator

template<class T , class Cmp = std::less<T>>
typedef std::map<T,AttributeVoid*>::iterator faudes::TBaseSet< T, Cmp >::aiterator
protected

STL attribute iterator, non-const version

Definition at line 970 of file cfl_baseset.h.

◆ CIterator

template<class T , class Cmp = std::less<T>>
typedef Iterator faudes::TBaseSet< T, Cmp >::CIterator

Iterator class for high-level api to TBaseSet.

This is a convenoience typedef — faudes set iterators are const anyway.

Definition at line 192 of file cfl_baseset.h.

◆ const_aiterator

template<class T , class Cmp = std::less<T>>
typedef std::map<T,AttributeVoid*>::const_iterator faudes::TBaseSet< T, Cmp >::const_aiterator
protected

STL attribute iterator, const version

Definition at line 973 of file cfl_baseset.h.

◆ const_iterator

template<class T , class Cmp = std::less<T>>
typedef std::set<T,Cmp>::const_iterator faudes::TBaseSet< T, Cmp >::const_iterator
protected

STL iterator, const version

Definition at line 956 of file cfl_baseset.h.

◆ iterator

template<class T , class Cmp = std::less<T>>
typedef std::set<T,Cmp>::iterator faudes::TBaseSet< T, Cmp >::iterator
protected

STL iterator, non-const version

Definition at line 953 of file cfl_baseset.h.

Member Enumeration Documentation

◆ DetachMode

template<class T , class Cmp = std::less<T>>
enum faudes::TBaseSet::DetachMode

Detach from extern storage (incl allocation and true copy)

Enumerator
SetOnly 
AttrIncl 

Definition at line 374 of file cfl_baseset.h.

Member Function Documentation

◆ AttributeTry()

template<class T , class Cmp = std::less<T>>
virtual void faudes::TBaseSet< T, Cmp >::AttributeTry ( const T &  rElem,
const Type rAttr 
)
inlinevirtual

Attribute access. This virtual function provides an interface for derived classes with attributes eg TaIndexSet. It is meant to try to set the attribute as specified if the type can be casted. Otherwise it does nothing.

Parameters
rElemElement of which the attribute is to be set
rAttrAttribute value to set.

Reimplemented in faudes::TaTransSet< Attr >, faudes::TaNameSet< Attr >, faudes::TaNameSet< faudes::AttributeFailureEvents >, faudes::TaNameSet< AttributeSimCondition >, faudes::TaNameSet< faudes::AttributeSignalEvent >, faudes::TaNameSet< faudes::AttributeSimplenetEvent >, faudes::TaNameSet< EventAttr >, faudes::TaNameSet< SimEventAttribute >, faudes::TaIndexSet< Attr >, faudes::TaIndexSet< StateAttr >, and faudes::TaIndexSet< faudes::DiagLabelSet >.

Definition at line 785 of file cfl_baseset.h.

Friends And Related Function Documentation

◆ TAttrMap

template<class T , class Cmp = std::less<T>>
template<class TP , class AP , class CP >
friend class TAttrMap
friend

allow access to attribute interface class

Definition at line 109 of file cfl_baseset.h.

Member Data Documentation

◆ mClientRecord

template<class T , class Cmp = std::less<T>>
std::list< TBaseSet<T,Cmp>* >::iterator faudes::TBaseSet< T, Cmp >::mClientRecord
protected

Iterator to the client list that hosts our data (maintained by host)

Definition at line 982 of file cfl_baseset.h.

◆ mDetached

template<class T , class Cmp = std::less<T>>
bool faudes::TBaseSet< T, Cmp >::mDetached
protected

Indicate "hosts data to myself only"

Definition at line 988 of file cfl_baseset.h.

◆ mIterators

template<class T , class Cmp = std::less<T>>
std::set< Iterator* > faudes::TBaseSet< T, Cmp >::mIterators
protected

Iterators that refer to this TBaseSet

Definition at line 1003 of file cfl_baseset.h.

◆ mLocked

template<class T , class Cmp = std::less<T>>
bool faudes::TBaseSet< T, Cmp >::mLocked
protected

Indicate "dont re-allocate the STL set ever again"

Definition at line 991 of file cfl_baseset.h.

◆ mpAttributes

template<class T , class Cmp = std::less<T>>
std::map<T,AttributeVoid*>* faudes::TBaseSet< T, Cmp >::mpAttributes
protected

Attribute map, if this object hosts data (else NULL).

Definition at line 967 of file cfl_baseset.h.

◆ mpClients

template<class T , class Cmp = std::less<T>>
std::list< TBaseSet<T,Cmp>* >* faudes::TBaseSet< T, Cmp >::mpClients
protected

BaseSets, that use data hosted by us (NULL if we dont host data, emptyset if we host to ourself excl.)

Definition at line 985 of file cfl_baseset.h.

◆ mpSet

template<class T , class Cmp = std::less<T>>
std::set<T,Cmp>* faudes::TBaseSet< T, Cmp >::mpSet
protected

STL set, if this object hosts data (else NULL)

Definition at line 950 of file cfl_baseset.h.

◆ pAttributes

template<class T , class Cmp = std::less<T>>
std::map<T,AttributeVoid*>* faudes::TBaseSet< T, Cmp >::pAttributes
protected

Pointer to attribute map to operate on

Definition at line 964 of file cfl_baseset.h.

◆ pHostSet

template<class T , class Cmp = std::less<T>>
TBaseSet<T,Cmp>* faudes::TBaseSet< T, Cmp >::pHostSet
protected

Pointer on BaseSet that hosts our data (THIS if we host)

Definition at line 979 of file cfl_baseset.h.

◆ pSet

template<class T , class Cmp = std::less<T>>
std::set<T,Cmp>* faudes::TBaseSet< T, Cmp >::pSet
protected

Pointer on STL set to operate on

Definition at line 947 of file cfl_baseset.h.


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

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