#include <baseset.h>
Inheritance diagram for faudes::TBaseSet< T, Cmp >:
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. Clearly, this introduces some 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.
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) differ in this aspect. The class TBaseSet::Iterator hides the issue from the faudes API but it is still present internaly: in its current implementation, libfaudes will not compile with MS STL. At this stage we are aware of two workarounds, one simple but on cost of performance, one a little bit awkward. Let us know if MS STL is missioncrititical for your libfaudes application.
Definition at line 85 of file baseset.h.
Public Member Functions | |
TBaseSet (void) | |
Constructor. | |
TBaseSet (const TBaseSet &rOtherSet) | |
Copy-constructor. | |
virtual | ~TBaseSet (void) |
Virtual destructor. | |
std::string | Name (void) const |
Return name of TBaseSet. | |
void | Name (const std::string &rName) |
Set name of TBaseSet. | |
virtual void | Clear (void) |
Clear all set. | |
Idx | Size (void) const |
Get Size of TBaseSet. | |
bool | Empty (void) const |
Check if the TBaseSet ist Empty. | |
Iterator | Begin (void) const |
Iterator to the begin of set. | |
Iterator | End (void) const |
Iterator to the end of set. | |
virtual bool | Valid (const T &rElem) const |
Test validty of candidate element. | |
virtual bool | Erase (const T &rElem) |
Erase element by reference. | |
virtual Iterator | Erase (const Iterator &pos) |
Erase element by iterator. | |
virtual void | EraseSet (const TBaseSet &rOtherSet) |
Erase elements given by other set. | |
virtual bool | Insert (const T &rElem) |
Insert specified element. | |
virtual void | InsertSet (const TBaseSet &rOtherSet) |
Insert elements given by rOtherSet. | |
virtual void | SetUnion (const TBaseSet &rOtherSet) |
Set Union, result is accumulated in this set. | |
virtual void | SetIntersection (const TBaseSet &rOtherSet) |
Set Intersection, result is stored in this set. | |
bool | Exists (const T &rElem) const |
Test existence of element. | |
Iterator | Find (const T &rElem) const |
Find element and return iterator. | |
TBaseSet | operator+ (const TBaseSet &rOtherSet) const |
Set union operator. | |
TBaseSet | operator- (const TBaseSet &rOtherSet) const |
Set difference operator. | |
TBaseSet | operator * (const TBaseSet &rOtherSet) const |
Set intersection operator. | |
bool | operator== (const TBaseSet &rOtherSet) const |
Test for equality. | |
bool | operator!= (const TBaseSet &rOtherSet) const |
Test for inequality. | |
bool | operator<= (const TBaseSet &rOtherSet) const |
Test for subset. | |
bool | operator>= (const TBaseSet &rOtherSet) const |
Test for superset. | |
bool | operator< (const TBaseSet &rOtherSet) const |
Order for sorting containers of TBaseSet. | |
virtual const TBaseSet & | operator= (const TBaseSet &rSrc) |
Assignment operator (fake copy). | |
void | DValid (const std::string &rMessage="") const |
Some validation of deferred copy mechanism (provole abort). | |
void | Detach (void) const |
Detach from extern storage (incl allocation and true copy). | |
void | Lock (void) const |
Detach and lock any further reallocation. | |
Protected Types | |
typedef std::set< T, Cmp >::iterator | iterator |
STL iterator, non-const version. | |
typedef std::set< T, Cmp >::const_iterator | const_iterator |
STL iterator, const version. | |
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 | DoWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const |
Token output, see Type::DWrite for public wrappers. | |
virtual void | DoRead (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0) |
Token input, see Type::Read for public wrappers. | |
const TBaseSet< T, Cmp > & | Assign (const TBaseSet< T, Cmp > &rOtherSet) |
Assignment function (fake copy, no storage allocated). | |
TBaseSet< T, Cmp >::Iterator | ThisIterator (const typename std::set< T, Cmp >::const_iterator &sit) const |
Convert STL iterator. | |
Protected Attributes | |
std::set< T, Cmp > * | mpSet |
STL set, if the object owns content (else NULL). | |
std::set< T, Cmp > * | pSet |
Pointer on STL set to operate on. | |
Static Protected Attributes | |
static std::set< T, Cmp > | mEmptySet = std::set<T,Cmp>() |
static empty STL set for default constructor | |
Private Member Functions | |
void | RelinkReferences (void) |
Ensure that we do not serve contents to anyone else. | |
void | AttachReference (TBaseSet *pRef) const |
Record that we serve contents to some other TBaseSet. | |
void | DetachReference (TBaseSet *pRef) const |
Record that we stop serving contents to some TBaseSet. | |
void | AttachIterator (Iterator *pFit) const |
Record that an iterator refers to this TBaseSet. | |
void | DetachIterator (Iterator *pFit) const |
Record that an iterator stops to refer to this TBaseSet. | |
Private Attributes | |
std::string | mMyName |
Name of TBaseSet. | |
std::set< TBaseSet< T, Cmp > * > | mReferences |
Other BaseSets, that refer to the STL set provided by this TBaseSet. | |
TBaseSet< T, Cmp > * | pBaseSet |
Pointer on BaseSet that owns the STL set this BaseSet referrs to. | |
bool | mDetached |
Indicate "has no references, provides STL set". | |
bool | mLocked |
Indicate "dont re-allocate the STL set again". | |
std::set< Iterator * > | mIterators |
Iterators that refer to this TBaseSet. | |
Classes | |
class | Iterator |
Iterator class for high-level api to TBaseSet. More... |
|
STL iterator, const version.
|
|
STL iterator, non-const version.
|
|
Constructor.
|
|
Copy-constructor.
|
|
Virtual destructor.
|
|
Assignment function (fake copy, no storage allocated).
|
|
Record that an iterator refers to this TBaseSet.
|
|
Record that we serve contents to some other TBaseSet.
|
|
Iterator to the begin of set.
Reimplemented in faudes::TTransSet< Cmp >. |
|
Clear all set.
Reimplemented from faudes::Type. Reimplemented in faudes::TaIndexSet< Attr >, faudes::TaTransSet< Attr >, faudes::TaIndexSet< SimConditionAttribute >, faudes::TaIndexSet< StateAttr >, faudes::TaIndexSet< AttributeCFlags >, faudes::TaIndexSet< EventAttr >, and faudes::TaIndexSet< AttributeTimedState >. |
|
Detach from extern storage (incl allocation and true copy).
|
|
Record that an iterator stops to refer to this TBaseSet.
|
|
Record that we stop serving contents to some TBaseSet.
|
|
Token output, debugging see Type::DWrite for public wrappers. Reimplement this function in derived classes for specific specific template parameters.
Reimplemented from faudes::Type. Reimplemented in faudes::NameSet, faudes::TaNameSet< Attr >, faudes::TaNameSet< SimConditionAttribute >, faudes::TaNameSet< AttributeCFlags >, and faudes::TaNameSet< EventAttr >. |
|
Token input, see Type::Read for public wrappers. Reimplement this function in derived classes for specific specific template parameters. By convention, the default label "" should be translated to some meaningful default, eg "IndexSet" for a set of indices". The pContext pointer can de type-checked and interpreted, ie as a symboltable to provide symbolic names. It is also passed on to attributes.
Reimplemented from faudes::Type. Reimplemented in faudes::IndexSet, faudes::TaIndexSet< Attr >, faudes::NameSet, faudes::TaNameSet< Attr >, faudes::SymbolSet, faudes::TaIndexSet< SimConditionAttribute >, faudes::TaIndexSet< StateAttr >, faudes::TaIndexSet< AttributeCFlags >, faudes::TaIndexSet< EventAttr >, faudes::TaIndexSet< AttributeTimedState >, faudes::TaNameSet< SimConditionAttribute >, faudes::TaNameSet< AttributeCFlags >, and faudes::TaNameSet< EventAttr >. |
|
Token output, see Type::DWrite for public wrappers. Reimplement this function in derived classes for specific specific template parameters. By convention, the default label "" should be translated to a) the name of the set or b) some meaningful default, eg "IndexSet" for a set of indices". The pContext pointer can de type-checked and interpreted, ie as a symboltable to provide symbolic names. It is also passed on to attributes.
Reimplemented from faudes::Type. Reimplemented in faudes::IndexSet, faudes::TaIndexSet< Attr >, faudes::NameSet, faudes::TaNameSet< Attr >, faudes::SymbolSet, faudes::TTransSet< Cmp >, faudes::TaIndexSet< SimConditionAttribute >, faudes::TaIndexSet< StateAttr >, faudes::TaIndexSet< AttributeCFlags >, faudes::TaIndexSet< EventAttr >, faudes::TaIndexSet< AttributeTimedState >, faudes::TaNameSet< SimConditionAttribute >, faudes::TaNameSet< AttributeCFlags >, and faudes::TaNameSet< EventAttr >. |
|
Some validation of deferred copy mechanism (provole abort).
|
|
Check if the TBaseSet ist Empty.
|
|
Iterator to the end of set.
Reimplemented in faudes::TTransSet< Cmp >. |
|
Erase element by iterator.
Reimplemented in faudes::TaIndexSet< Attr >, faudes::NameSet, faudes::TaNameSet< Attr >, faudes::TaTransSet< Attr >, faudes::TaIndexSet< SimConditionAttribute >, faudes::TaIndexSet< StateAttr >, faudes::TaIndexSet< AttributeCFlags >, faudes::TaIndexSet< EventAttr >, faudes::TaIndexSet< AttributeTimedState >, faudes::TaNameSet< SimConditionAttribute >, faudes::TaNameSet< AttributeCFlags >, and faudes::TaNameSet< EventAttr >. |
|
Erase element by reference.
Reimplemented in faudes::TTransSet< Cmp >, and faudes::TaTransSet< Attr >. |
|
Erase elements given by other set.
|
|
Test existence of element.
Reimplemented in faudes::TTransSet< Cmp >. |
|
Find element and return iterator.
Reimplemented in faudes::TTransSet< Cmp >. |
|
Insert specified element.
Reimplemented in faudes::SymbolSet, faudes::TTransSet< Cmp >, and faudes::TaTransSet< Attr >. |
|
Insert elements given by rOtherSet.
|
|
Detach and lock any further reallocation.
|
|
Set name of TBaseSet.
|
|
Return name of TBaseSet.
|
|
Set intersection operator.
|
|
Test for inequality.
|
|
Set union operator.
|
|
Set difference operator.
|
|
Order for sorting containers of TBaseSet.
|
|
Test for subset.
|
|
Assignment operator (fake copy).
|
|
Test for equality.
|
|
Test for superset.
|
|
Ensure that we do not serve contents to anyone else.
|
|
Set Intersection, result is stored in this set.
|
|
Set Union, result is accumulated in this set.
|
|
Get Size of TBaseSet.
|
|
Convert STL iterator.
|
|
Test validty of candidate element. Reimplement this function for particular type T of elements, eg for an index set with T=Idx indicate 0 an invalid index.
Reimplemented in faudes::SymbolSet. |
|
Indicate "has no references, provides STL set".
|
|
static empty STL set for default constructor
|
|
Iterators that refer to this TBaseSet.
|
|
Indicate "dont re-allocate the STL set again".
|
|
Name of TBaseSet.
|
|
STL set, if the object owns content (else NULL).
|
|
Other BaseSets, that refer to the STL set provided by this TBaseSet.
|
|
Pointer on BaseSet that owns the STL set this BaseSet referrs to.
|
|
Pointer on STL set to operate on.
|