#include <baseset.h>
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 82 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. | |
void | Write (void) const |
Write set to console. | |
void | Write (const std::string &pFileName, const std::string &rLabel="", std::ios::openmode openmode=std::ios::out|std::ios::trunc) const |
Write set to a file. | |
void | Write (TokenWriter &rTw, const std::string &rLabel="") const |
Write set to TokenWriter. | |
std::string | ToString (void) const |
Write set to a string. | |
void | DWrite (void) const |
Write debug info to console. | |
void | DWrite (TokenWriter &rTw) const |
Write debug info to TokenWriter. | |
void | DWrite (const char *pFileName, std::ios::openmode openmode=std::ios::out|std::ios::trunc) const |
Write debug info a file. | |
void | Read (const std::string &rFileName, const std::string &rLabel="BaseSet") |
Read from file with label specified. | |
void | Read (TokenReader &rTr, const std::string &rLabel="BaseSet") |
Read from TokenReader with label sepcified. | |
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 |
Actual DWrite routine, virtual. | |
virtual void | DoWrite (TokenWriter &rTw, const std::string &rLabel="") const |
Actual Write routine, virtual. | |
virtual void | DoRead (TokenReader &rTr, const std::string &rLabel="BaseSet") |
Actual Read routine, virtual. | |
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 in faudes::TaIndexSet< Attr >, faudes::TaTransSet< Attr >, faudes::TaIndexSet< StateAttr >, and faudes::TaIndexSet< EventAttr >. |
|
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.
|
|
Actual DWrite routine, virtual. Note: reimplement this function in derived classes for specific specific template parameters. Reimplemented in faudes::NameSet, faudes::TaNameSet< Attr >, and faudes::TaNameSet< EventAttr >. |
|
Actual Read routine, virtual. Note: reimplement this function in derived classes for specific specific template parameters. Reimplemented in faudes::IndexSet, faudes::TaIndexSet< Attr >, faudes::NameSet, faudes::TaNameSet< Attr >, faudes::TaIndexSet< StateAttr >, faudes::TaIndexSet< EventAttr >, and faudes::TaNameSet< EventAttr >. |
|
Actual Write routine, virtual. Note: reimplement this function in derived classes for specific specific template parameters. Reimplemented in faudes::IndexSet, faudes::TaIndexSet< Attr >, faudes::NameSet, faudes::TaNameSet< Attr >, faudes::TTransSet< Cmp >, faudes::TaIndexSet< StateAttr >, faudes::TaIndexSet< EventAttr >, and faudes::TaNameSet< EventAttr >. |
|
Some validation of deferred copy mechanism (provole abort).
|
|
Write debug info a file. The openmode can specified and defaults to truncate. Note: all write functions use the virtual function DoWrite(), to be reimplemented for specific template parameters.
|
|
Write debug info to TokenWriter. Note: all write functions use the virtual function DoWrite(), to be reimplemented for specific template parameters.
|
|
Write debug info to console. Note: all write functions use the virtual function DoWrite(), to be reimplemented for specific template parameters. |
|
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< StateAttr >, faudes::TaIndexSet< EventAttr >, 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::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.
|
|
Read from TokenReader with label sepcified. Note: all read functions use the virtual function DoRead(), to be reimplemented for specific template parameters.
|
|
Read from file with label specified. Note: all read functions use the virtual function DoRead(), to be reimplemented for specific template parameters.
|
|
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.
|
|
Write set to a string. Note: all write functions use the virtual function DoWrite(), to be reimplemented for specific template parameters.
|
|
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.
|
|
Write set to TokenWriter. Note: all write functions use the virtual function DoWrite(), to be reimplemented for specific template parameters.
|
|
Write set to a file. Note: all write functions use the virtual function DoWrite(), to be reimplemented for specific template parameters.
|
|
Write set to console. Note: all write functions use the virtual function DoWrite(), to be reimplemented for specific template parameters. |
|
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.
|