|
Go to the documentation of this file.
25 #ifndef FAUDES_BASESET_H
26 #define FAUDES_BASESET_H
43 template< class T, class Attr, class Cmp> class TaBaseSet;
95 template< class T, class Cmp=std::less<T> >
106 template< class TP, class AP, class CP> friend class TaBaseSet;
133 TBaseSet( const std::string& rFilename, const std::string& rLabel = "BaseSet");
146 const std::string& Name( void) const;
154 void Name( const std::string& rName);
160 virtual void Clear( void);
176 bool Empty( void) const;
188 virtual std::string Str( const T& rElem) const;
202 Iterator Begin( void) const;
210 Iterator End( void) const;
223 virtual bool Valid( const T& rElem) const;
234 virtual bool Erase( const T& rElem);
245 virtual Iterator Erase( const Iterator& pos);
273 virtual bool Insert( const T& rElem);
286 virtual Iterator Inject( const Iterator& pos, const T& rElem);
297 virtual void Inject( const T& rElem);
334 bool Exists( const T& rElem) const;
345 Iterator Find( const T& rElem) const;
382 void DValid( const std::string& rMessage= "") const;
385 virtual void Detach( void) const;
388 virtual void Lock( void) const;
416 const typename std::set<T,Cmp>::const_iterator& sit,
422 if(pBaseSet && att) {
447 std::stringstream rstr;
456 #ifdef FAUDES_DEBUG_CODE
458 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator= invalid iterator: no baseset");
481 void StlIterator( const typename std::set<T,Cmp>::const_iterator& sit) {
486 const typename std::set<T,Cmp>::const_iterator& StlIterator( void) const {
505 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):DValid(): invalid iterator: no baseset");
513 #ifdef FAUDES_DEBUG_CODE
515 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator->: invalid iterator: no baseset");
524 #ifdef FAUDES_DEBUG_CODE
526 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator*: invalid iterator: no baseset");
535 #ifdef FAUDES_DEBUG_CODE
537 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator==: invalid iterator: no baseset");
541 return * static_cast< const typename std::set<T,Cmp>::const_iterator * >( this) == rOther;
546 #ifdef FAUDES_DEBUG_CODE
548 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator!=: invalid iterator: no baseset");
552 return * static_cast< const typename std::set<T,Cmp>::const_iterator * >( this) != rOther;
557 #ifdef FAUDES_DEBUG_CODE
559 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator++: invalid iterator: no baseset");
570 #ifdef FAUDES_DEBUG_CODE
572 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator++: invalid iterator: no baseset");
582 #ifdef FAUDES_DEBUG_CODE
584 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator--: invalid iterator: no baseset");
595 #ifdef FAUDES_DEBUG_CODE
597 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator--: invalid iterator: no baseset");
620 #ifdef DONT_TRACK_REFERENCES
640 Iterator( const typename std::set<T,Cmp>::const_iterator& sit) :
647 const typename std::set<T,Cmp>::const_iterator& sit) :
652 void StlIterator( const typename std::set<T,Cmp>::const_iterator& sit) {
657 const typename std::set<T,Cmp>::const_iterator& StlIterator( void) const {
674 virtual const AttributeVoid* Attributep( void) const;
681 virtual const AttributeVoid& Attribute( void) const;
798 virtual void AttributeTry( const T& rElem, const Type& rAttr) { (void) rElem; (void) rAttr; };
831 virtual const std::string& TypeName( void) const;
840 virtual void TypeName( const std::string& rType);
928 typedef typename std::set<T,Cmp>::iterator iterator;
945 typedef typename std::map<T,AttributeVoid*>::iterator aiterator;
992 virtual const std::string& XElementTag( void) const;
1039 template< class T, class Cmp>
1041 FD_DC( "FAUDES_DEBUG_CONTAINER: SetUnion(TBaseSet<T,Cmp>): res at " << &rRes);
1045 if(&rSetA==&rSetB && &rSetA==&rRes) {rRes. Name(name); return;}
1047 if(&rSetA==&rSetB) {rRes. Assign(rSetA); rRes. Name(name); return;}
1049 if(&rSetA==&rRes) {rRes. InsertSet(rSetB); rRes. Name(name); return;};
1051 if(&rSetB==&rRes) {rRes. InsertSet(rSetA); rRes. Name(name); return;};
1056 FD_DC( "FAUDES_DEBUG_CONTAINER: SetUnion(TBaseSet<T,Cmp>): done, res at " << &rRes << " #" << rRes. Size());
1069 template< class T, class Cmp >
1074 if(&rSetA==&rSetB && &rSetA==&rRes) {rRes. Name(name); return;}
1076 if(&rSetA==&rSetB) { rRes. Assign(rSetA); rRes. Name(name); return;}
1078 if(&rSetA==&rRes) {rRes. RestrictSet(rSetB); rRes. Name(name); return;};
1080 if(&rSetB==&rRes) {rRes. RestrictSet(rSetA); rRes. Name(name); return;};
1098 template< class T, class Cmp >
1103 if(&rSetA==&rSetB) { rRes. Clear(); rRes. Name(name); return;}
1105 if(&rSetA==&rRes) {rRes. EraseSet(rSetB); rRes. Name(name); return;};
1132 template< class T, class Cmp >
1134 return rSetA==rSetB;
1148 template< class T, class Cmp >
1150 return rSetA<=rSetB;
1173 #define THIS TBaseSet<T,Cmp>
1174 #define TEMP template<class T, class Cmp>
1193 TEMP std::set<T,Cmp> THIS::msEmptySet=std::set<T,Cmp>();
1194 TEMP std::map<T,AttributeVoid*> THIS::msEmptyAttributes=std::map<T,AttributeVoid*>();
1201 pAttributes(&msEmptyAttributes),
1204 mpClients(new std::list< TBaseSet<T,Cmp>* >),
1207 pTypeDefinition(NULL)
1210 FD_DC( "TBaseSet(" << this << ")::TBaseSet()");
1216 TEMP THIS::TBaseSet( const std::string& rFileName, const std::string& rLabel) :
1220 pAttributes(&msEmptyAttributes),
1223 mpClients(new std::list< TBaseSet<T,Cmp>* >),
1226 pTypeDefinition(NULL)
1229 FD_DC( "TBaseSet(" << this << ")::TBaseSet()");
1233 Read(rFileName,rLabel);
1241 pAttributes(&msEmptyAttributes),
1244 mpClients(new std::list< TBaseSet<T,Cmp>* >),
1247 pTypeDefinition(NULL)
1250 FD_DC( "TBaseSet(" << this << ")::TBaseSet(rOtherSet " << &rOtherSet << "): fake copy construct");
1253 #ifdef FAUDES_DEBUG_CODE
1261 FD_DC( "TBaseSet(" << this << ")::~TBaseSet()");
1264 pHostSet->DetachClient( this);
1265 if(mpClients) delete mpClients;
1268 typename std::set< Iterator* >::const_iterator iit;
1269 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1270 (**iit).Invalidate();
1273 if(mpSet) delete mpSet;
1275 for( aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait)
1277 delete mpAttributes;
1284 FD_DC( "TBaseSet(" << this << ")::DoAssign(rOtherSet " << &rSourceSet << "): fake copy");
1286 if( this==&rSourceSet) return;
1288 mMyName=rSourceSet.mMyName;
1290 if(pHostSet==rSourceSet.pHostSet) return;
1293 pHostSet->DetachClient( this);
1295 #ifdef FAUDES_DEBUG_CODE
1297 FD_ERR( "TBaseSet::DoAssign(): locked target will be unlocked: not implemented");
1302 pHostSet=rSourceSet.pHostSet;
1303 pHostSet->AttachClient( this);
1304 pSet=rSourceSet.pSet;
1305 pAttributes=&msEmptyAttributes;
1312 for( aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait)
1314 delete mpAttributes;
1325 typename std::set< Iterator* >::iterator iit;
1326 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1327 (**iit).Invalidate();
1330 #ifdef FAUDES_DEBUG_CODE
1331 DValid( "PostFakeAssignment");
1336 TEMP void THIS::Detach( void) const {
1337 FD_DC( "TBaseSet(" << this << ")::Detach(void)");
1338 #ifdef FAUDES_DEBUG_CODE
1339 DValid( "PreDetach");
1343 if(mDetached) return;
1346 THIS* fake_const = const_cast< THIS* >( this);
1348 #ifdef FAUDES_DEBUG_CODE
1351 if(pSet!=&msEmptySet)
1353 if(mpClients->empty()) {
1354 FD_ERR( "TBaseSet(" << this << ")::Detach(void): missed detach (?)");
1356 fake_const->mDetached= true;
1365 FD_DC( "TBaseSet(" << this << ")::Detach(void): allocate and copy, strategie A");
1367 std::set<T,Cmp>* scopy = new std::set<T,Cmp>();
1370 THIS* newhost = *mpClients->begin();
1371 #ifdef FAUDES_DEBUG_CODE
1372 if(newhost->mpClients)
1373 FD_ERR( "TBaseSet(" << this << ")::Detach(void): new host used to heve clients (?)");
1375 newhost->pHostSet=newhost;
1376 newhost->mpSet=scopy;
1377 newhost->pSet=scopy;
1378 newhost->mpAttributes=mpAttributes;
1379 newhost->pAttributes=pAttributes;
1380 newhost->mpClients=mpClients;
1381 newhost->DetachClient(newhost);
1383 typename std::list< THIS* >::const_iterator rit;
1384 for(rit=newhost->mpClients->begin();rit!=newhost->mpClients->end(); ++rit) {
1385 (*rit)->pHostSet=newhost;
1386 (*rit)->pSet=newhost->pSet;
1387 (*rit)->pAttributes=newhost->pAttributes;
1390 typename std::set< Iterator* >::iterator iit;
1391 for(rit=newhost->mpClients->begin(); rit!=newhost->mpClients->end(); ++rit) {
1392 for(iit=(*rit)->mIterators.begin(); iit!=(*rit)->mIterators.end(); ++iit) {
1393 if((**iit).StlIterator()==pSet->end())
1394 **iit= Iterator( this, scopy->end());
1396 **iit= Iterator( this, scopy->find(***iit));
1400 for(iit=newhost->mIterators.begin(); iit!=newhost->mIterators.end(); ++iit) {
1401 if((**iit).StlIterator()==pSet->end())
1402 **iit= Iterator( this, scopy->end());
1404 **iit= Iterator( this, scopy->find(***iit));
1407 fake_const->mpSet=pSet;
1408 fake_const->mpAttributes=NULL;
1409 fake_const->pAttributes=&msEmptyAttributes;
1410 fake_const->mpClients= new std::list< TBaseSet<T,Cmp>* >;
1411 fake_const->mDetached= true;
1413 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1416 fake_const->mIterators.clear();
1424 FD_DC( "TBaseSet(" << this << ")::Detach(void): allocate and copy, strategie B");
1426 fake_const->RelinkClients();
1427 pHostSet->DetachClient(fake_const);
1429 fake_const->mpSet = new std::set<T,Cmp>();
1430 *fake_const->mpSet= *pSet;
1432 fake_const->mpAttributes=NULL;
1433 fake_const->pAttributes=&msEmptyAttributes;
1435 typename std::set< Iterator* >::iterator iit;
1436 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1437 if((**iit).StlIterator()==pSet->end())
1438 **iit= Iterator( this, mpSet->end());
1440 **iit= Iterator( this, mpSet->find(***iit));
1443 fake_const->pHostSet=fake_const;
1444 fake_const->pSet=mpSet;
1445 fake_const->mDetached= true;
1446 if(fake_const->mpClients) delete fake_const->mpClients;
1447 fake_const->mpClients= new std::list< TBaseSet<T,Cmp>* >;
1450 #ifdef FAUDES_DEBUG_CODE
1451 DValid( "PostDetach");
1453 FD_DC( "TBaseSet(" << this << ")::Detach(void): done");
1458 FD_DC( "TBaseSet(" << this << ")::Lock(void)");
1459 #ifdef FAUDES_DEBUG_CODE
1469 THIS* fake_const = const_cast< THIS* >( this);
1472 typename std::set< Iterator* >::const_iterator iit;
1473 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1476 fake_const->mIterators.clear();
1479 fake_const->mLocked= true;
1481 #ifdef FAUDES_DEBUG_CODE
1488 TEMP inline void THIS::RelinkClients( void) {
1489 FD_DC( "TBaseSet::RelinkClients(" << this << ")")
1490 #ifdef FAUDES_DEBUG_CODE
1491 DValid( "PreRelink");
1495 if(!mpClients) return;
1497 if(mpClients->empty()) return;
1499 FD_DC( "TBaseSet::RelinkClients(" << this << "): doit")
1502 THIS* newhost = *mpClients->begin();
1503 #ifdef FAUDES_DEBUG_CODE
1504 if(newhost->pHostSet!= this)
1505 FD_ERR( "BaseSet::RelinkRefernces: old reference must have this as provider");
1506 if(newhost->mpClients)
1507 FD_ERR( "TBaseSet(" << this << ")::RelinkClients(void): client is a host (?)");
1509 newhost->pHostSet=newhost;
1510 newhost->mpSet=mpSet;
1512 newhost->mpAttributes=mpAttributes;
1513 newhost->pAttributes=pAttributes;
1514 newhost->mpClients=mpClients;
1515 newhost->DetachClient(newhost);
1517 typename std::list< THIS* >::const_iterator rit;
1518 for(rit=newhost->mpClients->begin();rit!=newhost->mpClients->end(); ++rit) {
1519 (*rit)->pHostSet=newhost;
1525 pAttributes=newhost->pAttributes;
1527 newhost->AttachClient( this);
1529 #ifdef FAUDES_DEBUG_CODE
1530 DValid( "PostRelink");
1532 FD_DC( "TBaseSet::RelinkClients(" << this << "): done")
1539 const_cast< THIS* >( this)->mpClients->push_back(pRef);
1541 const_cast< THIS* >( this)->mDetached= false;
1546 FD_DC( "TBaseSet::DetachClient(" << this << "):" << pRef);
1548 if(!mpClients) return;
1549 if(mpClients->empty()) return;
1552 THIS* fake_const = const_cast< THIS* >( this);
1553 #ifdef FAUDES_DEBUG_CODE
1555 typename std::list< TBaseSet<T,Cmp>* > ::iterator cit;
1557 for(cit=fake_const->mpClients->begin(); cit!=fake_const->mpClients->end(); ++cit) {
1558 if(*cit==pRef) cf= true;
1561 FD_ERR( "TBaseSet::DetachClient(" << this << "): client not found " << pRef);
1574 typename std::list< TBaseSet<T,Cmp>* > ::iterator rit;
1575 for(rit=fake_const->mpClients->begin(); rit!=fake_const->mpClients->end(); ++rit) {
1576 if(*rit!=pRef) continue;
1577 fake_const->mpClients->erase(rit);
1581 if(mpClients->empty() && (pSet!=&msEmptySet)) fake_const->mDetached= true;
1582 FD_DC( "TBaseSet::DetachClient(" << this << "): done.");
1589 FD_DC( "TBaseSet::AttachIterator(" << this << "):" << pFit)
1590 const_cast< THIS* >( this)->mIterators.insert(pFit);
1596 FD_DC( "TBaseSet::DetachIterator(" << this << "):" << pFit)
1597 const_cast< THIS* >( this)->mIterators.erase(pFit);
1601 TEMP void THIS::DValid( const std::string& rMessage) const {
1602 typename std::set< Iterator* >::const_iterator iit;
1603 typename std::list< THIS* >::const_iterator rit;
1604 #ifdef FAUDES_DEBUG_CONTAINER
1605 std::cerr << "TBaseSet(" << this << ")::DValid(): " << rMessage << " source "
1606 << pHostSet << " " << (pHostSet->pSet==&msEmptySet ? "+e+" : "+f+") <<
1607 (mLocked ? " +l+" : " ") << (mDetached ? " +d+" : " ") << " -- refs ";
1608 if(pHostSet->mpClients)
1609 for(rit=pHostSet->mpClients->begin(); rit!=pHostSet->mpClients->end(); ++rit)
1610 std::cerr << *rit << " ";
1611 std::cerr << "-- its ";
1612 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit)
1613 std::cerr << *iit << " ";
1614 std::cerr << "-- attr #" << pAttributes->size();
1615 if(mpAttributes) std::cerr << "(" << mpAttributes->size() << ") ";
1616 else std::cerr << " ";
1617 std::cerr << (pAttributes==&msEmptyAttributes ? "+e+ " : "+f+ ") << std::endl;
1620 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1621 if((*iit)->pBaseSet!= this) {
1622 FD_ERR( "BaseSet("<< this << "," << rMessage << "): invalid iterator (baseset): "<< *iit);
1627 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1628 if(!(*iit)->mAttached) {
1629 FD_ERR( "BaseSet("<< this << "," << rMessage << "): invalid iterator (attached): "<< *iit);
1634 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1635 typename std::set<T,Cmp>::const_iterator vit;
1636 for(vit=pSet->begin(); vit!= pSet->end(); ++vit) {
1637 if(vit==(**iit).StlIterator()) break;
1639 if(vit!=(**iit).StlIterator()) {
1640 FD_ERR( "BaseSet("<< this << "," << rMessage << "): invalid iterator (stl) "<< *iit);
1641 (**iit).StlIterator(pSet->end());
1646 if(pHostSet==NULL) {
1647 FD_ERR( "BaseSet(" << this << "," << rMessage << "): no host found");
1651 if(pHostSet->pHostSet != pHostSet) {
1652 FD_ERR( "BaseSet(" << this << "," << rMessage << "): inconsistent host");
1656 if((mpSet!=NULL) && (pHostSet != this)) {
1657 FD_ERR( "BaseSet(" << this << "," << rMessage << "): double data");
1661 if(pHostSet!= this && mpClients!=NULL) {
1662 FD_ERR( "BaseSet(" << this << "," << rMessage << "): cannot be client and have clients oneself");
1666 if(pHostSet->mpClients==NULL) {
1667 FD_ERR( "BaseSet(" << this << "," << rMessage << "): refers to invalid host (a)");
1671 if(pHostSet!= this && pHostSet->mpClients->empty()) {
1672 FD_ERR( "BaseSet(" << this << "," << rMessage << "): refers to invalid host (b)");
1676 if((pHostSet == this) && (mpSet==NULL) && (pSet!=&msEmptySet)) {
1677 FD_ERR( "BaseSet(" << this << "," << rMessage << "): no data");
1681 if((pHostSet== this) && (pSet!=&msEmptySet) && (mpClients==NULL)) {
1682 FD_ERR( "BaseSet(" << this << "," << rMessage << "): host with no client list");
1686 if((pHostSet == this) && (pSet != mpSet) && (pSet!=&msEmptySet)) {
1687 FD_ERR( "BaseSet(" << this << "," << rMessage << "): data pointer mismatch A");
1691 if(pSet != pHostSet->pSet) {
1692 FD_ERR( "BaseSet(" << this << "," << rMessage << "): data pointer mismatch B");
1697 for(rit=pHostSet->mpClients->begin(); rit!=pHostSet->mpClients->end(); ++rit) {
1698 if((*rit)== this) hf= true;
1699 if((*rit)->pHostSet== pHostSet) continue;
1700 FD_ERR( "BaseSet(" << this << "," << rMessage << "): invalid client " << (*rit));
1703 if(!hf && (pHostSet!= this)) {
1704 FD_ERR( "BaseSet(" << this << "," << rMessage << "): client not registered with host");
1708 if(pHostSet!= this && *mClientRecord!= this) {
1709 FD_ERR( "BaseSet(" << this << "," << rMessage << "): refers to invalid host (c)");
1713 if(mDetached && mpClients==NULL) {
1714 FD_ERR( "BaseSet(" << this << "," << rMessage << "): invalid detached flag A");
1718 if(mDetached && !mpClients->empty()) {
1719 FD_ERR( "BaseSet(" << this << "," << rMessage << "): invalid detached flag B");
1723 if(mDetached && (pSet==&msEmptySet)) {
1724 FD_ERR( "BaseSet(" << this << "," << rMessage << "): detached empty set");
1728 if(mLocked && (mpClients==NULL)) {
1729 FD_ERR( "BaseSet(" << this << "," << rMessage << "): locked reference (a)");
1733 if(!msEmptySet.empty()) {
1734 FD_ERR( "BaseSet(" << this << "," << rMessage << "): invalid empty set");
1738 if(!msEmptyAttributes.empty()) {
1739 FD_ERR( "BaseSet(" << this << "," << rMessage << "): invalid empty attributes");
1742 #ifdef FAUDES_DEBUG_CONTAINER
1743 std::cerr << "TBaseSet(" << this << ")::DValid(): passed" << std::endl;
1750 TEMP const std::string& THIS::Name( void) const {
1755 TEMP void THIS::Name( const std::string& rName) {
1763 if(!pTypeDefinition) {
1765 THIS* fake_const = const_cast< THIS* >( this);
1768 return pTypeDefinition;
1772 TEMP const std::string& THIS::XElementTag( void) const {
1773 if(mXElementTag.empty()) {
1775 THIS* fake_const = const_cast< THIS* >( this);
1776 fake_const->mXElementTag= "Element";
1778 if(fdp) fake_const->mXElementTag=fdp-> XElementTag();
1780 return mXElementTag;
1784 TEMP void THIS::XElementTag( const std::string& rTag) {
1790 TEMP const std::string& THIS::TypeName( void) const {
1791 if(mFaudesTypeName.empty()) {
1793 THIS* fake_const = const_cast< THIS* >( this);
1795 if(fdp) fake_const->mFaudesTypeName=fdp-> Name();
1797 return mFaudesTypeName;
1801 TEMP void THIS::TypeName( const std::string& rType) {
1802 mFaudesTypeName=rType;
1807 TEMP std::string THIS::Str( const T& rElem) const {
1815 return ( Idx) pSet->size();
1819 TEMP bool THIS::Empty( void) const {
1820 return pSet->empty();
1827 std::string label=rLabel;
1828 if(label== "") label=Name();
1829 if(label== "") label= "BaseSet";
1830 FD_DC( "TBaseSet(" << this << ")::DoWrite(..): section " << label << " #" << Size());
1840 BASE::DoSWrite(rTw);
1842 if(pHostSet->mpClients) shares=pHostSet->mpClients->size();
1849 #ifdef FAUDES_DEBUG_CODE
1856 BASE::DoSWrite(rTw);
1858 if(pHostSet->mpClients) shares=pHostSet->mpClients->size();
1861 if(pAttributes->size()!=0)
1863 if(pAttributes->size()!=0) {
1872 std::string label=rLabel;
1873 if(label== "") label=Name();
1874 if(label== "") label= "BaseSet";
1881 TEMP typename THIS::Iterator THIS::ThisIterator( const typename std::set<T,Cmp>::const_iterator& sit) const {
1886 TEMP inline typename THIS::Iterator THIS::Begin( void) const {
1887 return ThisIterator(pSet->begin());
1891 TEMP inline typename THIS::Iterator THIS::End( void) const {
1892 return ThisIterator(pSet->end());
1898 FD_DC( "TBaseSet(" << this << ")::Clear()");
1899 #ifdef FAUDES_DEBUG_CODE
1903 if(pSet==&msEmptySet) return;
1904 FD_DC( "TBaseSet(" << this << ")::Clear(): doit");
1907 if(mLocked) Detach();
1910 pHostSet->DetachClient( this);
1913 if(!mpClients) mpClients= new std::list< TBaseSet<T,Cmp>* >;
1922 for( aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait)
1924 delete mpAttributes;
1929 pAttributes=&msEmptyAttributes;
1931 typename std::set< Iterator* >::iterator iit;
1932 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1933 (**iit).Invalidate();
1938 #ifdef FAUDES_DEBUG_CODE
1939 DValid( "PostClear");
1945 TEMP inline bool THIS::Valid( const T& rElem) const {
1951 TEMP bool THIS::Insert( const T& rElem) {
1952 #ifdef FAUDES_CHECKED
1954 std::stringstream errstr;
1955 errstr << "cannot insert invalid element" << std::endl;
1956 throw Exception( "BaseSet::Insert", errstr.str(), 61);
1959 if(!mDetached) Detach();
1960 return pSet->insert(rElem).second;
1964 TEMP typename THIS::Iterator THIS::Inject( const Iterator& pos, const T& rElem) {
1965 if(!mDetached) Detach();
1967 return ThisIterator(pSet->insert(dst,rElem));
1972 TEMP void THIS::Inject( const T& rElem) {
1973 if(!mDetached) Detach();
1974 pSet->insert(pSet->end(),rElem);
1979 FD_DC( "TBaseSet(" << this << ")::InsertSet(" << &rOtherSet << ")");
1980 if(!mDetached) Detach();
1989 while ((it1 != pSet->end()) && (it2 != rOtherSet. pSet->end())) {
1993 else if (*it1 == *it2) {
2002 while (it2 != rOtherSet. pSet->end()) {
2010 TEMP bool THIS::Erase( const T& rElem) {
2011 if(!mDetached) Detach();
2012 return (pSet->erase(rElem)!=0);
2018 #ifdef FAUDES_CHECKED
2020 std::stringstream errstr;
2021 errstr << "iterator out of range " << std::endl;
2022 throw Exception( "BaseSet::Erase", errstr.str(), 62);
2028 return ThisIterator(del);
2034 FD_DC( "TBaseSet(" << this << ")::EraseSet(" << &rOtherSet << ")");
2035 if(!mDetached) Detach();
2039 while ((it != pSet->end()) && (oit != rOtherSet. pSet->end())) {
2041 it=pSet->lower_bound(*oit);
2043 else if (*it == *oit) {
2048 oit=rOtherSet. pSet->lower_bound(*it);
2056 FD_DC( "TBaseSet(" << this << ")::RestrictSet(" << &rOtherSet << ")");
2057 if(!mDetached) Detach();
2061 while ((it != pSet->end()) && (oit != rOtherSet. pSet->end())) {
2065 else if (*it == *oit) {
2070 oit=rOtherSet. pSet->lower_bound(*it);
2073 while(it != pSet->end()) {
2080 TEMP typename THIS::Iterator THIS::Find( const T& rElem) const {
2081 return ThisIterator(pSet->find(rElem));
2085 TEMP bool THIS::Exists( const T& rElem) const {
2086 return pSet->find(rElem) != pSet->end();
2092 if(!mDetached) Detach();
2095 while ((it1 != pSet->end()) && (it2 != rOtherSet. pSet->end())) {
2106 pSet->insert(it1,*it2);
2109 while (it2 != rOtherSet. pSet->end()) {
2110 pSet->insert(pSet->end(),*it2);
2117 if(!mDetached) Detach();
2120 while ((it1 != pSet->end()) && (it2 != rOtherSet. pSet->end())) {
2133 while(it1 != pSet->end()) {
2141 FD_DC( "TBaseSet(" << this << ")::FnctUnion (" << &rOtherSet << ")");
2143 std::insert_iterator< std::set<T,Cmp> > insit(*rRes. pSet, rRes. pSet->begin());
2144 std::set_union(pSet->begin(), pSet->end(), rOtherSet. pSet->begin(), rOtherSet. pSet->end(), insit);
2150 FD_DC( "TBaseSet(" << this << ")::FnctDifference (" << &rOtherSet << ")");
2152 std::insert_iterator< std::set<T,Cmp> > insit(*rRes. pSet, rRes. pSet->begin());
2153 std::set_difference(pSet->begin(), pSet->end(), rOtherSet. pSet->begin(), rOtherSet. pSet->end(), insit);
2160 FD_DC( "TBaseSet(" << this << ")::FnctIntersection (" << &rOtherSet << ")");
2162 std::insert_iterator< std::set<T,Cmp> > insit(*rRes. pSet, rRes. pSet->begin());
2163 std::set_intersection(pSet->begin(), pSet->end(), rOtherSet. pSet->begin(), rOtherSet. pSet->end(), insit);
2170 FnctUnion(rOtherSet,res);
2177 FnctDifference(rOtherSet,res);
2185 FnctIntersection(rOtherSet,res);
2192 FD_DC( "TBaseSet::DoEqual()");
2194 if(pSet == rOtherSet. pSet) return true;
2196 return ( *pSet == *rOtherSet. pSet );
2201 FD_DC( "BaseSet::op<=()");
2202 return ( std::includes(rOtherSet. pSet->begin(), rOtherSet. pSet->end(), pSet->begin(), pSet->end()) ) ;
2207 FD_DC( "BaseSet::op>=()");
2208 return ( std::includes(pSet->begin(), pSet->end(), rOtherSet. pSet->begin(), rOtherSet. pSet->end()) );
2213 return *pSet < *rOtherSet. pSet;
2232 std::stringstream errstr;
2233 errstr << "cannot get attribute for TBaseSet \"" << mMyName << "\" type " << typeid(*this).name();
2234 throw Exception( "TBaseSet::Attributep(rElem)", errstr.str(), 63);
2247 TEMP void THIS::Attribute( const T& rElem, const Type& rAttr) {
2258 if(!AttributeTry(rAttr)) {
2259 std::stringstream errstr;
2260 errstr << "cannot cast attribute " << std::endl;
2261 throw Exception( "TBaseSet::Attribute(elem,attr)", errstr.str(), 63);
libFAUDES 2.26g
--- 2015.08.17
--- c++ api documentaion by doxygen
|