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 93 of file cfl_baseset.h.

#include <cfl_baseset.h>

Classes

class  Iterator
 Iterator class for high-level api to TBaseSet. More...
 

Public Types

enum  DetachMode { SetOnly , AttrIncl }
 Detach from extern storage (incl allocation and true copy) More...
 

Public Member Functions

 TBaseSet (void)
 Constructor. More...
 
 TBaseSet (const TBaseSet &rOtherSet)
 Copy-constructor. More...
 
 TBaseSet (const std::string &rFilename, const std::string &rLabel="BaseSet")
 Constructor from file. More...
 
virtual ~TBaseSet (void)
 Virtual destructor. More...
 
const std::string & Name (void) const
 Return name of TBaseSet. More...
 
void Name (const std::string &rName)
 Set name of TBaseSet. More...
 
virtual void Clear (void)
 Clear all set. More...
 
Idx Size (void) const
 Get Size of TBaseSet. More...
 
bool Empty (void) const
 Test whether if the TBaseSet is Empty. More...
 
virtual std::string Str (const T &rElem) const
 Return pretty printable element. More...
 
Iterator Begin (void) const
 Iterator to the begin of set. More...
 
Iterator End (void) const
 Iterator to the end of set. More...
 
virtual bool Valid (const T &rElem) const
 Test validty of candidate element. More...
 
virtual bool Erase (const T &rElem)
 Erase element by reference. More...
 
virtual Iterator Erase (const Iterator &pos)
 Erase element by iterator. More...
 
virtual void EraseSet (const TBaseSet &rOtherSet)
 Erase elements given by other set. More...
 
virtual void RestrictSet (const TBaseSet &rOtherSet)
 Restrict elements given by other set. More...
 
virtual bool Disjoint (const TBaseSet &rOtherSet) const
 Test for this set to be disjoint witg other set. More...
 
virtual bool Insert (const T &rElem)
 Insert specified element. More...
 
virtual Iterator Inject (const Iterator &pos, const T &rElem)
 Insert specified element. More...
 
virtual void Inject (const T &rElem)
 Insert specified element. More...
 
virtual void InsertSet (const TBaseSet &rOtherSet)
 Insert elements given by rOtherSet. More...
 
bool Exists (const T &rElem) const
 Test existence of element. More...
 
Iterator Find (const T &rElem) const
 Find element and return iterator. More...
 
TBaseSet operator+ (const TBaseSet &rOtherSet) const
 Set union operator. More...
 
TBaseSet operator- (const TBaseSet &rOtherSet) const
 Set difference operator. More...
 
TBaseSet operator* (const TBaseSet &rOtherSet) const
 Set intersection operator. More...
 
bool operator<= (const TBaseSet &rOtherSet) const
 Test for subset
More...
 
bool operator>= (const TBaseSet &rOtherSet) const
 Test for superset. More...
 
bool operator< (const TBaseSet &rOtherSet) const
 Order for sorting containers of TBaseSet. More...
 
void DValid (const std::string &rMessage="") const
 Some validation of deferred copy mechanism (provoke abort) More...
 
void Detach (DetachMode flag=AttrIncl) const
 
void Lock (void) const
 Detach and lock any further reallocation. More...
 
virtual const AttributeVoidAttributeType (void) const
 Attribute typeinfo. More...
 
virtual bool AttributeTest (const Type &rAttr) const
 Attribute typeinfo. More...
 
virtual TBaseSetAssignWithoutAttributes (const TBaseSet &rSourceSet)
 Attribute access. More...
 
virtual void Attributes (const TBaseSet &rOtherSet)
 Attributes access. More...
 
Idx AttributesSize (void) const
 Attribute access. More...
 
void ClearAttributes (void)
 Attribute access. More...
 
bool EqualAttributes (const TBaseSet &rOtherSet) const
 Attribute access. More...
 
virtual AttributeVoidAttributep (const T &rElem)
 Attribute access. More...
 
virtual const AttributeVoidAttribute (const T &rElem) const
 Attribute access. More...
 
virtual void Attribute (const T &rElem, const Type &rAttr)
 Attribute access. More...
 
virtual void AttributeTry (const T &rElem, const Type &rAttr)
 Attribute access. More...
 
virtual void ClrAttribute (const T &rElem)
 Attribute access. More...
 
virtual void XElementTag (const std::string &rTag)
 Configure the element name tag. More...
 
virtual const std::string & TypeName (void) const
 Get objects's type name. More...
 
virtual void TypeName (const std::string &rType)
 Overwrite faudes-type name. 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...
 
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::set< T, Cmp >::iterator iterator
 STL iterator, non-const version. More...
 
typedef std::set< T, Cmp >::const_iterator const_iterator
 STL iterator, const version. More...
 
typedef std::map< T, AttributeVoid * >::iterator aiterator
 STL attribute iterator, non-const version. More...
 
typedef std::map< T, AttributeVoid * >::const_iterator const_aiterator
 STL attribute iterator, const version. More...
 

Protected Member Functions

virtual void DoWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Token output, see Type::DWrite for public wrappers. More...
 
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 DoRead (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 Token input, see Type::Read for public wrappers. More...
 
void DoAssign (const TBaseSet &rSourceSet)
 assign my members More...
 
bool DoEqual (const TBaseSet &rOtherSet) const
 test equality More...
 
void DoAttribute (const T &rElem, const Type *pAttr)
 set attribute in map (assume elem exists in set, NULL <=> set to default) More...
 
const AttributeVoidDoAttribute (const T &rElem) const
 get attribute from map (return null if elem does not exist in map) More...
 
AttributeVoidDoAttributeExplicit (const T &rElem)
 get attribute from map (insert explicit default if elem does not exist in map) More...
 
TBaseSet< T, Cmp >::Iterator ThisIterator (const typename std::set< T, Cmp >::const_iterator &sit) const
 Convert STL iterator to API iterator. More...
 
void RelinkClients (void)
 Ensure that we do not host contents to anyone else. More...
 
void AttachClient (TBaseSet *pRef) const
 Record that we provide contents to some other BaseSet. More...
 
void DetachClient (TBaseSet *pRef) const
 Record that we stop providing data for some TBaseSet. More...
 
void AttachIterator (Iterator *pFit) const
 Record that an iterator refers to this TBaseSet. More...
 
void DetachIterator (Iterator *pFit) const
 Record that an iterator stops to refer to this TBaseSet. More...
 
virtual const TypeDefinitionTypeDefinitionp (void) const
 Reimplment from type to use chache. More...
 
virtual const std::string & XElementTag (void) const
 Get name of elements (used for XML IO) 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 Token XBeginTag (const std::string &rLabel="", const std::string &rFallbackLabel="") const
 

Protected Attributes

std::string mMyName
 Name of this BaseSet. More...
 
std::set< T, Cmp > * pSet
 Pointer on STL set to operate on. More...
 
std::set< T, Cmp > * mpSet
 STL set, if this object hosts data (else NULL) More...
 
std::map< T, AttributeVoid * > * pAttributes
 Pointer to attribute map to operate on. More...
 
std::map< T, AttributeVoid * > * mpAttributes
 Attribute map, if this object hosts data (else NULL). More...
 
TBaseSet< T, Cmp > * pHostSet
 Pointer on BaseSet that hosts our data (THIS if we host) More...
 
std::list< TBaseSet< T, Cmp > * >::iterator mClientRecord
 Iterator to the client list that hosts our data (maintained by host) More...
 
std::list< TBaseSet< T, Cmp > * > * mpClients
 BaseSets, that use data hosted by us (NULL if we dont host data, emptyset if we host to ourself excl.) More...
 
bool mDetached
 Indicate "hosts data to myself only". More...
 
bool mLocked
 Indicate "dont re-allocate the STL set ever again". More...
 
std::set< Iterator * > mIterators
 Iterators that refer to this TBaseSet. More...
 

Static Protected Attributes

static std::set< T, Cmp > msEmptySet =std::set<T,Cmp>()
 static empty STL set for default constructor More...
 
static std::map< T, AttributeVoid * > msEmptyAttributes =std::map<T,AttributeVoid*>()
 static empty STL map for default constructor More...
 

Private Attributes

const TypeDefinitionpTypeDefinition
 static empty STL client list More...
 
std::string mXElementTag
 Current/cached name of elements (used protected accessor method) More...
 
std::string mFaudesTypeName
 Current/cached faudes type-name. More...
 

Friends

template<class TP , class AP , class CP >
class TAttrMap
 allow access to attribute interface class More...
 

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 933 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 936 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 919 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 916 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 367 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 778 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 100 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 945 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 951 of file cfl_baseset.h.

◆ mFaudesTypeName

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

Current/cached faudes type-name.

Definition at line 1000 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 966 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 954 of file cfl_baseset.h.

◆ mMyName

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

Name of this BaseSet.

Definition at line 907 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 930 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 948 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 913 of file cfl_baseset.h.

◆ mXElementTag

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

Current/cached name of elements (used protected accessor method)

Definition at line 997 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 927 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 942 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 910 of file cfl_baseset.h.

◆ pTypeDefinition

template<class T , class Cmp = std::less<T>>
const TypeDefinition* faudes::TBaseSet< T, Cmp >::pTypeDefinition
private

static empty STL client list

TypeDefinition cache (should use guarded pointer here)

Definition at line 994 of file cfl_baseset.h.


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

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