|
|
Go to the documentation of this file.
25#ifndef FAUDES_BASESET_H
26#define FAUDES_BASESET_H
51template< class T, class Attr, class Cmp> class TAttrMap;
100template< class T, class Cmp=std::less<T> >
107 using ExtType::operator=;
108 using ExtType::operator==;
109 using ExtType::operator!=;
112 template< class TP, class AP, class CP> friend class TAttrMap;
138 TBaseSet( const std::string& rFilename, const std::string& rLabel = "BaseSet");
181 virtual std::string Str( const T& rElem) const;
193 virtual std::string Str( void) const;
239 virtual bool Valid( const T& rElem) const;
261 virtual Iterator Erase( const Iterator& pos);
309 virtual Iterator Inject( const Iterator& pos, const T& rElem);
350 Iterator Find( const T& rElem) const;
387 void DValid( const std::string& rMessage= "") const;
410 class Iterator : private std::set<T,Cmp>::const_iterator {
422 const typename std::set<T,Cmp>::const_iterator& sit,
428 if(pBaseSet && att) {
437 pBaseSet(fit.pBaseSet),
441 pBaseSet->AttachIterator( this);
448 if(mAttached) pBaseSet->DetachIterator( this);
453 std::stringstream rstr;
454 rstr << "[dit base " << pBaseSet << " a" << mAttached << " data " << pBaseSet->pSet;
455 if(pBaseSet) rstr << " elem " << pBaseSet->Str(** this);
462#ifdef FAUDES_DEBUG_CODE
464 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator= invalid iterator: no baseset");
469 if(mAttached) if(pBaseSet==rSrc. pBaseSet) {
470 std::set<T,Cmp>::const_iterator::operator= (rSrc);
474 if(mAttached) pBaseSet->DetachIterator( this);
475 std::set<T,Cmp>::const_iterator::operator= (rSrc);
487 void StlIterator( const typename std::set<T,Cmp>::const_iterator& sit) {
488 std::set<T,Cmp>::const_iterator::operator= (sit);
492 const typename std::set<T,Cmp>::const_iterator& StlIterator( void) const {
511 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):DValid(): invalid iterator: no baseset");
514 pBaseSet->DValid( "Iterator");
518 const T* operator-> ( void) const {
519#ifdef FAUDES_DEBUG_CODE
521 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator->: invalid iterator: no baseset");
525 return std::set<T,Cmp>::const_iterator::operator-> ();
529 const T& operator* ( void) const {
530#ifdef FAUDES_DEBUG_CODE
532 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator*: invalid iterator: no baseset");
536 return std::set<T,Cmp>::const_iterator::operator* ();
541#ifdef FAUDES_DEBUG_CODE
543 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator==: invalid iterator: no baseset");
547 return * static_cast< const typename std::set<T,Cmp>::const_iterator * >( this) == rOther;
552#ifdef FAUDES_DEBUG_CODE
554 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator!=: invalid iterator: no baseset");
558 return * static_cast< const typename std::set<T,Cmp>::const_iterator * >( this) != rOther;
563#ifdef FAUDES_DEBUG_CODE
565 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator++: invalid iterator: no baseset");
570 std::set<T,Cmp>::const_iterator::operator++ (step);
576#ifdef FAUDES_DEBUG_CODE
578 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator++: invalid iterator: no baseset");
582 std::set<T,Cmp>::const_iterator::operator++ ();
588#ifdef FAUDES_DEBUG_CODE
590 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator--: invalid iterator: no baseset");
594 Iterator old(pBaseSet, * this, true);
595 std::set<T,Cmp>::const_iterator::operator-- (step);
601#ifdef FAUDES_DEBUG_CODE
603 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator--: invalid iterator: no baseset");
607 std::set<T,Cmp>::const_iterator::operator-- ();
626#ifdef DONT_TRACK_REFERENCES
632 class Iterator : public std::set<T,Cmp>::const_iterator {
637 std::set<T,Cmp>::const_iterator()
641 Iterator( const Iterator& fit) :
642 std::set<T,Cmp>::const_iterator(fit)
646 Iterator( const typename std::set<T,Cmp>::const_iterator& sit) :
647 std::set<T,Cmp>::const_iterator(sit)
652 const TBaseSet<T,Cmp>* pBaseSet,
653 const typename std::set<T,Cmp>::const_iterator& sit) :
654 std::set<T,Cmp>::const_iterator(sit)
658 void StlIterator( const typename std::set<T,Cmp>::const_iterator& sit) {
659 std::set<T,Cmp>::const_iterator::operator= (sit);
663 const typename std::set<T,Cmp>::const_iterator& StlIterator( void) const {
668 void Invalidate( void) {};
801 virtual void AttributeTry( const T& rElem, const Type& rAttr) { (void) rElem; (void) rAttr; };
820 virtual void FromStl( const std::set<T,Cmp>& rStlSet);
830 virtual void ToStl(std::set<T,Cmp>& rStlSet) const;
1021 typedef typename std::map<T,AttributeVoid*>::iterator aiterator;
1072 std::map< T, AttributeVoid* >* pGea;
1089template< class T, class Cmp>
1091 FD_DC( "FAUDES_DEBUG_CONTAINER: SetUnion(TBaseSet<T,Cmp>): res at " << &rRes);
1095 if(&rSetA==&rSetB && &rSetA==&rRes) {rRes. Name(name); return;}
1097 if(&rSetA==&rSetB) {rRes. Assign(rSetA); rRes. Name(name); return;}
1099 if(&rSetA==&rRes) {rRes. InsertSet(rSetB); rRes. Name(name); return;};
1101 if(&rSetB==&rRes) {rRes. InsertSet(rSetA); rRes. Name(name); return;};
1106 FD_DC( "FAUDES_DEBUG_CONTAINER: SetUnion(TBaseSet<T,Cmp>): done, res at " << &rRes << " #" << rRes. Size());
1119template< class T, class Cmp >
1124 if(&rSetA==&rSetB && &rSetA==&rRes) {rRes. Name(name); return;}
1126 if(&rSetA==&rSetB) { rRes. Assign(rSetA); rRes. Name(name); return;}
1128 if(&rSetA==&rRes) {rRes. RestrictSet(rSetB); rRes. Name(name); return;};
1130 if(&rSetB==&rRes) {rRes. RestrictSet(rSetA); rRes. Name(name); return;};
1148template< class T, class Cmp >
1153 if(&rSetA==&rSetB) { rRes. Clear(); rRes. Name(name); return;}
1155 if(&rSetA==&rRes) {rRes. EraseSet(rSetB); rRes. Name(name); return;};
1182template< class T, class Cmp >
1184 return rSetA==rSetB;
1198template< class T, class Cmp >
1200 return rSetA<=rSetB;
1222#define THIS TBaseSet<T,Cmp>
1223#define TEMP template<class T, class Cmp>
1243 static std::set<T,Cmp> ges;
1244#ifdef FAUDES_DEBUG_CODE
1245 static bool done= false;
1247 std::cerr << "BaseSet::GlobalEmptySet(): for " << typeid(ges).name() << " at " << &ges << std::endl;
1255TEMP std::map< T,AttributeVoid* > * THIS::GlobalEmptyAttributes( void) {
1256 static std::map<T,AttributeVoid*> gea;
1257#ifdef FAUDES_DEBUG_CODE
1258 static bool done= false;
1260 std::cerr << "BaseSetGlobalEmptyAttributes(): for " << typeid(gea).name() << " at " << &gea << std::endl;
1271 pSet(GlobalEmptySet()),
1273 pAttributes(GlobalEmptyAttributes()),
1276 mpClients(new std::list< TBaseSet<T,Cmp>* >),
1279 pGes(GlobalEmptySet()),
1280 pGea(GlobalEmptyAttributes())
1283 FD_DC( "TBaseSet(" << this << ")::TBaseSet(): as " << typeid(*this).name() );
1287#ifdef FAUDES_DEBUG_CODE
1293TEMP THIS::TBaseSet( const std::string& rFileName, const std::string& rLabel) :
1295 pSet(GlobalEmptySet()),
1297 pAttributes(GlobalEmptyAttributes()),
1300 mpClients(new std::list< TBaseSet<T,Cmp>* >),
1303 pGes(GlobalEmptySet()),
1304 pGea(GlobalEmptyAttributes())
1307 FD_DC( "TBaseSet(" << this << ")::TBaseSet()");
1312 Read(rFileName,rLabel);
1318 pSet(GlobalEmptySet()),
1320 pAttributes(GlobalEmptyAttributes()),
1323 mpClients(new std::list< TBaseSet<T,Cmp>* >),
1326 pGes(GlobalEmptySet()),
1327 pGea(GlobalEmptyAttributes())
1330 FD_DC( "TBaseSet(" << this << ")::TBaseSet(rOtherSet " << &rOtherSet << "): fake copy construct");
1336#ifdef FAUDES_DEBUG_CODE
1344 FD_DC( "TBaseSet(" << this << ")::~TBaseSet()");
1347 pHostSet->DetachClient( this);
1348 if(mpClients) delete mpClients;
1351 typename std::set< Iterator* >::const_iterator iit;
1352 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1353 (**iit).Invalidate();
1356 if(mpSet) delete mpSet;
1358 for( aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait)
1360 delete mpAttributes;
1367 FD_DC( "TBaseSet(" << this << "[" << this->Name() << "])::DoAssign(rOtherSet " << &rSourceSet << "): shallow copy -- src attr# " << rSourceSet.pAttributes->size());
1368 FD_DC( "TBaseSet():DoAssign(): " << typeid(*this->AttributeType()).name() << " <== " << typeid(*rSourceSet.AttributeType()).name());
1369#ifdef FAUDES_DEBUG_CODE
1370 DValid( "PreFakeAssignment");
1373 if( this==&rSourceSet) {
1374 FD_DC( "TBaseSet():DoAssign(): bail out on identical objects");
1378 mObjectName=rSourceSet.mObjectName;
1379 mElementTagDef=rSourceSet.mElementTagDef;
1381 if(pHostSet==rSourceSet.pHostSet) return;
1384 pHostSet->DetachClient( this);
1391 for( aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait)
1393 delete mpAttributes;
1401 if( typeid(*rSourceSet.AttributeType())== typeid(*this->AttributeType())) {
1402 pHostSet=rSourceSet.pHostSet;
1403 pHostSet->AttachClient( this);
1404 pSet=rSourceSet.pSet;
1405 pAttributes=rSourceSet.pAttributes;
1409 mpSet = new std::set<T,Cmp>();
1410 *mpSet = *rSourceSet.pSet;
1412 mpAttributes = new std::map<T,AttributeVoid*>();
1413 if( typeid(*this->AttributeType()) != typeid( const AttributeVoid)) {
1414 for( aiterator ait=rSourceSet.pAttributes->begin(); ait!=rSourceSet.pAttributes->end(); ++ait) {
1416 (*mpAttributes)[ait->first]=attr;
1420 pAttributes = mpAttributes;
1422 mpClients= new std::list< TBaseSet<T,Cmp>* >;
1425 typename std::set< Iterator* >::iterator iit;
1426 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1427 (**iit).Invalidate();
1437#ifdef FAUDES_DEBUG_CODE
1438 DValid( "PostFakeAssignment");
1440 FD_DC( "TBaseSet(" << this << ")::DoAssign(rOtherSet " << &rSourceSet << "): fake copy -- done with attr# " << pAttributes->size());
1445 FD_DC( "TBaseSet(" << this << ")::Detach(void)");
1446#ifdef FAUDES_DEBUG_CODE
1447 DValid( "PreDetach");
1452 if(flag==SetOnly) pAttributes->clear();
1457 THIS* fake_const = const_cast< THIS* >( this);
1459#ifdef FAUDES_DEBUG_CODE
1464 if(mpClients->empty()) {
1465 FD_ERR( "TBaseSet(" << this << ")::Detach(): missed detach (?)");
1467 fake_const->mDetached= true;
1472 std::set<T,Cmp>* scopy = new std::set<T,Cmp>();
1476 std::map<T,AttributeVoid*>* acopy = new std::map<T,AttributeVoid*>();
1477 if(flag==AttrIncl) {
1478 for( aiterator ait=pAttributes->begin(); ait!=pAttributes->end(); ++ait) {
1480 (*acopy)[ait->first]=attr;
1489 FD_DC( "TBaseSet(" << this << ")::Detach(): allocate and copy, strategie A");
1491 THIS* newhost = *mpClients->begin();
1492#ifdef FAUDES_DEBUG_CODE
1493 if(newhost->mpClients)
1494 FD_ERR( "TBaseSet(" << this << ")::Detach(): new host used to have clients (?)");
1496 newhost->pHostSet=newhost;
1497 newhost->mpSet=scopy;
1498 newhost->pSet=scopy;
1499 newhost->mpAttributes=acopy;
1500 newhost->pAttributes=acopy;
1501 newhost->mpClients=mpClients;
1502 newhost->DetachClient(newhost);
1503 fake_const->mpClients=NULL;
1505 typename std::list< THIS* >::const_iterator rit;
1506 for(rit=newhost->mpClients->begin();rit!=newhost->mpClients->end(); ++rit) {
1507 (*rit)->pHostSet=newhost;
1508 (*rit)->pSet=newhost->pSet;
1509 (*rit)->pAttributes=newhost->pAttributes;
1512 typename std::set< Iterator* >::iterator iit;
1513 for(rit=newhost->mpClients->begin(); rit!=newhost->mpClients->end(); ++rit) {
1514 for(iit=(*rit)->mIterators.begin(); iit!=(*rit)->mIterators.end(); ++iit) {
1515 if((**iit).StlIterator()==pSet->end())
1516 **iit= Iterator( this, scopy->end());
1518 **iit= Iterator( this, scopy->find(***iit));
1522 for(iit=newhost->mIterators.begin(); iit!=newhost->mIterators.end(); ++iit) {
1523 if((**iit).StlIterator()==pSet->end())
1524 **iit= Iterator( this, scopy->end());
1526 **iit= Iterator( this, scopy->find(***iit));
1529 fake_const->mpSet=pSet;
1530 fake_const->mpAttributes=pAttributes;
1531 fake_const->mpClients= new std::list< TBaseSet<T,Cmp>* >;
1532 fake_const->mDetached= true;
1534 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit)
1536 fake_const->mIterators.clear();
1544 FD_DC( "TBaseSet(" << this << ")::Detach(): allocate and copy, strategie B");
1546 fake_const->RelinkClients();
1547 pHostSet->DetachClient(fake_const);
1549 fake_const->mpSet = scopy;
1550 fake_const->mpAttributes=acopy;
1552 typename std::set< Iterator* >::iterator iit;
1553 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1554 if((**iit).StlIterator()==pSet->end())
1555 **iit= Iterator( this, mpSet->end());
1557 **iit= Iterator( this, mpSet->find(***iit));
1560 fake_const->pHostSet=fake_const;
1561 fake_const->pSet=mpSet;
1562 fake_const->pAttributes=mpAttributes;
1563 fake_const->mDetached= true;
1564 if(fake_const->mpClients) delete fake_const->mpClients;
1565 fake_const->mpClients= new std::list< TBaseSet<T,Cmp>* >;
1569#ifdef FAUDES_DEBUG_CODE
1570 DValid( "PostDetach");
1572 FD_DC( "TBaseSet(" << this << ")::Detach(): done");
1577 FD_DC( "TBaseSet(" << this << ")::Lock(void)");
1578#ifdef FAUDES_DEBUG_CODE
1588 THIS* fake_const = const_cast< THIS* >( this);
1591 typename std::set< Iterator* >::const_iterator iit;
1592 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1595 fake_const->mIterators.clear();
1598 fake_const->mLocked= true;
1600#ifdef FAUDES_DEBUG_CODE
1607TEMP inline void THIS::RelinkClients( void) {
1608 FD_DC( "TBaseSet::RelinkClients(" << this << ")")
1609#ifdef FAUDES_DEBUG_CODE
1610 DValid( "PreRelink");
1614 if(!mpClients) return;
1616 if(mpClients->empty()) return;
1618 FD_DC( "TBaseSet::RelinkClients(" << this << "): doit")
1621 THIS* newhost = *mpClients->begin();
1622#ifdef FAUDES_DEBUG_CODE
1623 if(newhost->pHostSet!= this)
1624 FD_ERR( "BaseSet::RelinkRefernces: old reference must have this as provider");
1625 if(newhost->mpClients)
1626 FD_ERR( "TBaseSet(" << this << ")::RelinkClients(void): client is a host (?)");
1628 newhost->pHostSet=newhost;
1629 newhost->mpSet=mpSet;
1631 newhost->mpAttributes=mpAttributes;
1632 newhost->pAttributes=pAttributes;
1633 newhost->mpClients=mpClients;
1634 newhost->DetachClient(newhost);
1637 typename std::list< THIS* >::const_iterator rit;
1638 for(rit=newhost->mpClients->begin();rit!=newhost->mpClients->end(); ++rit) {
1639 (*rit)->pHostSet=newhost;
1645 pAttributes=newhost->pAttributes;
1647 newhost->AttachClient( this);
1648#ifdef FAUDES_DEBUG_CODE
1649 DValid( "PostRelink");
1651 FD_DC( "TBaseSet::RelinkClients(" << this << "): done")
1658 const_cast< THIS* >( this)->mpClients->push_back(pRef);
1660 const_cast< THIS* >( this)->mDetached= false;
1665 FD_DC( "TBaseSet::DetachClient(" << this << "):" << pRef);
1667 if(!mpClients) return;
1668 if(mpClients->empty()) return;
1671 THIS* fake_const = const_cast< THIS* >( this);
1672#ifdef FAUDES_DEBUG_CODE
1674 typename std::list< TBaseSet<T,Cmp>* >::iterator cit;
1676 for(cit=fake_const->mpClients->begin(); cit!=fake_const->mpClients->end(); ++cit) {
1677 if(*cit==pRef) cf= true;
1680 FD_ERR( "TBaseSet::DetachClient(" << this << "): client not found " << pRef);
1693 typename std::list< TBaseSet<T,Cmp>* >::iterator rit;
1694 for(rit=fake_const->mpClients->begin(); rit!=fake_const->mpClients->end(); ++rit) {
1695 if(*rit!=pRef) continue;
1696 fake_const->mpClients->erase(rit);
1700 if(mpClients->empty() && (pSet!=pGes)) fake_const->mDetached= true;
1701 FD_DC( "TBaseSet::DetachClient(" << this << "): done.");
1708 FD_DC( "TBaseSet::AttachIterator(" << this << "):" << pFit)
1709 const_cast< THIS* >( this)->mIterators.insert(pFit);
1715 FD_DC( "TBaseSet::DetachIterator(" << this << "):" << pFit)
1716 const_cast< THIS* >( this)->mIterators.erase(pFit);
1720TEMP void THIS::DValid( const std::string& rMessage) const {
1721 typename std::set< Iterator* >::const_iterator iit;
1722 typename std::list< THIS* >::const_iterator rit;
1723#ifdef FAUDES_DEBUG_CONTAINER
1724 std::cerr << "TBaseSet(" << this << ")::DValid(): " << rMessage <<
1725 " host " << pHostSet << (pHostSet == this ? " +s+ " : " ") <<
1726 (pHostSet->pSet==pHostSet->pGes ? "+e+ " : "+f+ ") <<
1727 (mLocked ? "+l+ " : " ") << (mDetached ? "+d+" : " ")
1728 << " stl at " << pSet << " own data " << mpSet << " ges " << pGes;
1729 std::cerr << " -- refs ";
1730 if(pHostSet->mpClients)
1731 for(rit=pHostSet->mpClients->begin(); rit!=pHostSet->mpClients->end(); ++rit)
1732 std::cerr << *rit << " ";
1733 std::cerr << "-- its ";
1734 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit)
1735 std::cerr << *iit << " ";
1736 std::cerr << "-- attr at " << pAttributes;
1737 std::cerr << "(#" << pAttributes->size() << ") ";
1738 if(mpAttributes) std::cerr << "(" << mpAttributes->size() << ") ";
1739 else std::cerr << " ";
1740 std::cerr << (pAttributes==pGea ? "+e+ " : "+f+ ") << std::endl;
1743 if(pGes!=GlobalEmptySet()) {
1744 FD_WARN( "BaseSet("<< this << "," << rMessage << "): lost empty set: " << pGes);
1748 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1749 if((*iit)->pBaseSet!= this) {
1750 FD_WARN( "BaseSet("<< this << "," << rMessage << "): invalid iterator (baseset): "<< *iit);
1755 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1756 if(!(*iit)->mAttached) {
1757 FD_WARN( "BaseSet("<< this << "," << rMessage << "): invalid iterator (attached): "<< *iit);
1762 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1763 typename std::set<T,Cmp>::const_iterator vit;
1764 for(vit=pSet->begin(); vit!= pSet->end(); ++vit) {
1765 if(vit==(**iit).StlIterator()) break;
1767 if(vit!=(**iit).StlIterator()) {
1768 FD_WARN( "BaseSet("<< this << "," << rMessage << "): invalid iterator (stl) "<< *iit);
1769 (**iit).StlIterator(pSet->end());
1774 if(pHostSet==NULL) {
1775 FD_WARN( "BaseSet(" << this << "," << rMessage << "): no host found");
1779 if(pHostSet->pHostSet != pHostSet) {
1780 FD_WARN( "BaseSet(" << this << "," << rMessage << "): inconsistent host");
1784 if((mpSet!=NULL) && (pHostSet != this)) {
1785 FD_WARN( "BaseSet(" << this << "," << rMessage << "): double data");
1789 if(pHostSet!= this && mpClients!=NULL) {
1790 FD_WARN( "BaseSet(" << this << "," << rMessage << "): cannot be client and have clients oneself");
1794 if(pHostSet->mpClients==NULL) {
1795 FD_WARN( "BaseSet(" << this << "," << rMessage << "): refers to invalid host (a)");
1799 if(pHostSet!= this && pHostSet->mpClients->empty()) {
1800 FD_WARN( "BaseSet(" << this << "," << rMessage << "): refers to invalid host (b)");
1804 if((pHostSet == this) && (mpSet==NULL) && (pSet!=pGes)) {
1805 FD_WARN( "BaseSet(" << this << "," << rMessage << "): no data");
1809 if((pHostSet== this) && (pSet!=pGes) && (mpClients==NULL)) {
1810 FD_WARN( "BaseSet(" << this << "," << rMessage << "): host with no client list");
1814 if((pHostSet == this) && (pSet != mpSet) && (pSet!=pGes)) {
1815 FD_WARN( "BaseSet(" << this << "," << rMessage << "): data pointer mismatch A");
1819 if(pSet != pHostSet->pSet) {
1820 FD_WARN( "BaseSet(" << this << "," << rMessage << "): data pointer mismatch B");
1825 for(rit=pHostSet->mpClients->begin(); rit!=pHostSet->mpClients->end(); ++rit) {
1826 if((*rit)== this) hf= true;
1827 if((*rit)->pHostSet== pHostSet) continue;
1828 FD_WARN( "BaseSet(" << this << "," << rMessage << "): invalid client " << (*rit));
1831 if(!hf && (pHostSet!= this)) {
1832 FD_WARN( "BaseSet(" << this << "," << rMessage << "): client not registered with host");
1836 if(pHostSet!= this && *mClientRecord!= this) {
1837 FD_WARN( "BaseSet(" << this << "," << rMessage << "): refers to invalid host (c)");
1841 if(mDetached && mpClients==NULL) {
1842 FD_WARN( "BaseSet(" << this << "," << rMessage << "): invalid detached flag A");
1846 if(mDetached && !mpClients->empty()) {
1847 FD_WARN( "BaseSet(" << this << "," << rMessage << "): invalid detached flag B");
1851 if(mDetached && (pSet==pHostSet->pGes)) {
1852 FD_WARN( "BaseSet(" << this << "," << rMessage << "): detached empty set");
1856 if(mLocked && (mpClients==NULL)) {
1857 FD_WARN( "BaseSet(" << this << "," << rMessage << "): locked reference (a)");
1861 if(!pGes->empty()) {
1862 FD_WARN( "BaseSet(" << this << "," << rMessage << "): invalid empty set");
1866 if(!GlobalEmptyAttributes()->empty()) {
1867 FD_WARN( "BaseSet(" << this << "," << rMessage << "): invalid empty attributes");
1870#ifdef FAUDES_DEBUG_CONTAINER
1871 std::cerr << "TBaseSet(" << this << ")::DValid(): passed" << std::endl;
1877TEMP std::string THIS::Str( const T& rElem) const {
1879 std::string res= "E";
1884TEMP std::string THIS::Str( void) const {
1885 std::stringstream str;
1886 str << "[" << Name() << "]{ ";
1889 if(Size()>0) while( true) {
1890 str << Str(*(eit++));
1891 if(eit==eit_end) break;
1900 return ( Idx) pSet->size();
1905 return pSet->empty();
1909TEMP void THIS::DoWriteElement( TokenWriter& rTw, const T& rElem, const std::string& rLabel, const Type* pContext) const {
1913 ep-> Write(rTw,rLabel,pContext);
1917 std::stringstream errstr;
1918 errstr << "used but not reimplemented" << typeid( this).name() << std::endl;
1919 throw Exception( "BaseSet::DoWriteElement", errstr.str(), 61);
1923TEMP void THIS::DoXWriteElement( TokenWriter& rTw, const T& rElem, const std::string& rLabel, const Type* pContext) const {
1927 ep-> XWrite(rTw,rLabel,pContext);
1931 std::stringstream errstr;
1932 errstr << "used but not reimplemented" << typeid( this).name() << std::endl;
1933 throw Exception( "BaseSet::DoXWriteElement", errstr.str(), 61);
1937TEMP void THIS::DoDWriteElement( TokenWriter& rTw, const T& rElem, const std::string& rLabel, const Type* pContext) const {
1941 ep-> DWrite(rTw,rLabel,pContext);
1945 std::stringstream errstr;
1946 errstr << "used but not reimplemented" << typeid( this).name() << std::endl;
1947 throw Exception( "BaseSet::DoDWriteElement", errstr.str(), 61);
1952 std::string label=rLabel;
1953 if(label== "") label=Name();
1954 if(label== "") label= "BaseSet";
1955 std::string etstr=ElementTag();
1956 FD_DC( "TBaseSet(" << this << ")::DoWrite(..): section " << label << " #" << Size());
1960 for (it = Begin(); it != End(); ++it) {
1961 DoWriteElement(rTw, *it, etstr, pContext);
1970 Token btag=XBeginTag(rLabel, "BaseSet");
1972 FD_DC( "BaseSet(" << this << ")::DoXWrite(..): section " << btag. StringValue() << " #" << Size());
1974 std::string etstr=ElementTag();
1976 for (it = Begin(); it != End(); ++it) {
1977 DoXWriteElement(rTw, *it, etstr, pContext);
1984 std::string label=rLabel;
1985 if(label== "") label=Name();
1986 if(label== "") label= "BaseSet";
1987 std::string etstr=ElementTag();
1988 FD_DC( "TBaseSet(" << this << ")::DoDWrite(..): section " << label << " #" << Size());
1991 BASE::DoSWrite(rTw);
1993 if(pHostSet->mpClients) shares=pHostSet->mpClients->size();
2000#ifdef FAUDES_DEBUG_CODE
2005 for (it = Begin(); it != End(); ++it) {
2006 DoDWriteElement(rTw, *it, etstr, pContext);
2013 BASE::DoSWrite(rTw);
2015 if(pHostSet->mpClients) shares=pHostSet->mpClients->size();
2018 if(pAttributes->size()!=0)
2020 if(pAttributes->size()!=0) {
2032 ep-> Read(rTr,rLabel,pContext);
2036 std::stringstream errstr;
2037 errstr << "used but not reimplemented" << typeid( this).name() << std::endl;
2038 throw Exception( "BaseSet::DoReadElement", errstr.str(), 61);
2044 std::string label=rLabel;
2045 std::string ftype=TypeName();
2046 std::string etstr=ElementTag();
2048 std::string etype= "";
2058 if(label== "") label=ftype;
2064 FD_DC( "BaseSet(" << typeid(*this).name() << ")::DoRead(..): section " << label << " elements " << etstr);
2066 while(!rTr. Eos(label)) {
2070 FD_DC( "TBaseSet(" << typeid(*this).name() << ")::DoRead(..): inserting element");
2073 DoReadElement(rTr,elem,etstr,pContext);
2075 FD_DC( "TBaseSet(" << typeid(*this).name() << ")::DoRead(..): inserting element: ok");
2079 std::stringstream errstr;
2080 errstr << "Invalid token of type " << token. Type() << " at " << rTr. FileLine();
2081 throw Exception( "BaseSet::DoRead", errstr.str(), 50);
2084 FD_DC( "BaseSet(" << this << ")::DoRead(tr," << label << ", " << pContext << "): done");
2088TEMP typename THIS::Iterator THIS::ThisIterator( const typename std::set<T,Cmp>::const_iterator& sit) const {
2093TEMP inline typename THIS::Iterator THIS::Begin( void) const {
2094 return ThisIterator(pSet->begin());
2098TEMP inline typename THIS::Iterator THIS::End( void) const {
2099 return ThisIterator(pSet->end());
2105 FD_DC( "TBaseSet(" << this << ")::Clear()");
2106#ifdef FAUDES_DEBUG_CODE
2110 if(pSet==pHostSet->pGes) return;
2112 FD_DC( "TBaseSet(" << this << ")::Clear(): doit");
2113 FD_DC( "TBaseSet(" << this << ")::Clear(): type " << typeid(*this).name());
2115 if(mLocked) Detach(SetOnly);
2118 pHostSet->DetachClient( this);
2121 if(!mpClients) mpClients= new std::list< TBaseSet<T,Cmp>* >;
2130 for( aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait) {
2131 FD_DC( "TBaseSet(" << this << ")::Clear(): del attr " << ait->second);
2134 delete mpAttributes;
2139 pAttributes=GlobalEmptyAttributes();
2141 typename std::set< Iterator* >::iterator iit;
2142 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
2143 (**iit).Invalidate();
2148#ifdef FAUDES_DEBUG_CODE
2149 DValid( "PostClear");
2151 FD_DC( "TBaseSet(" << this << ")::Clear(): done");
2156TEMP bool THIS::IsDefault( void) const {
2157 return pSet->empty();
2161TEMP inline bool THIS::Valid( const T& rElem) const {
2167TEMP bool THIS::Insert( const T& rElem) {
2168#ifdef FAUDES_CHECKED
2170 std::stringstream errstr;
2171 errstr << "refuse to insert invalid element" << std::endl;
2172 throw Exception( "BaseSet::Insert", errstr.str(), 61);
2175 if(!mDetached) Detach();
2176 return pSet->insert(rElem).second;
2180TEMP typename THIS::Iterator THIS::Inject( const Iterator& pos, const T& rElem) {
2181 if(!mDetached) Detach();
2183 return ThisIterator(pSet->insert(dst,rElem));
2188TEMP void THIS::Inject( const T& rElem) {
2189 if(!mDetached) Detach();
2190 pSet->insert(pSet->end(),rElem);
2195 FD_DC( "TBaseSet(" << this << ")::InsertSet(" << &rOtherSet << ")");
2196 if(!mDetached) Detach();
2205 while ((it1 != pSet->end()) && (it2 != rOtherSet. pSet->end())) {
2209 else if (*it1 == *it2) {
2218 while (it2 != rOtherSet. pSet->end()) {
2226TEMP bool THIS::Erase( const T& rElem) {
2227 if(!mDetached) Detach();
2228 return (pSet->erase(rElem)!=0);
2234#ifdef FAUDES_CHECKED
2236 std::stringstream errstr;
2237 errstr << "iterator out of range " << std::endl;
2238 throw Exception( "BaseSet::Erase", errstr.str(), 62);
2244 return ThisIterator(del);
2250 FD_DC( "TBaseSet(" << this << ")::EraseSet(" << &rOtherSet << ")");
2251 if(!mDetached) Detach();
2255 while ((it != pSet->end()) && (oit != rOtherSet. pSet->end())) {
2257 it=pSet->lower_bound(*oit);
2259 else if (*it == *oit) {
2264 oit=rOtherSet. pSet->lower_bound(*it);
2272 FD_DC( "TBaseSet(" << this << ")::RestrictSet(" << &rOtherSet << ")");
2273 if(!mDetached) Detach();
2277 while ((it != pSet->end()) && (oit != rOtherSet. pSet->end())) {
2281 else if (*it == *oit) {
2286 oit=rOtherSet. pSet->lower_bound(*it);
2289 while(it != pSet->end()) {
2297 FD_DC( "TBaseSet(" << this << ")::Disjoint(" << &rOtherSet << ")");
2299 if(pSet->empty()) return true;
2300 if(rOtherSet. pSet->empty()) return true;
2301 if(*pSet->rbegin()<*rOtherSet. pSet->begin()) return true;
2302 if(*rOtherSet. pSet->rbegin()<*pSet->begin()) return true;
2303 if(rOtherSet. pSet==pSet) return false;
2307 while ((it != pSet->end()) && (oit != rOtherSet. pSet->end())) {
2308 if (*it < *oit) { it++; continue;}
2309 if (*it == *oit) { return false; }
2317TEMP typename THIS::Iterator THIS::Find( const T& rElem) const {
2318 return ThisIterator(pSet->find(rElem));
2322TEMP bool THIS::Exists( const T& rElem) const {
2323 return pSet->find(rElem) != pSet->end();
2352 FD_DC( "TBaseSet::DoEqual()");
2354 if(pSet == rOtherSet. pSet) return true;
2356 return ( *pSet == *rOtherSet. pSet );
2361 FD_DC( "BaseSet::op<=()");
2362 return ( std::includes(rOtherSet. pSet->begin(), rOtherSet. pSet->end(), pSet->begin(), pSet->end()) ) ;
2367 FD_DC( "BaseSet::op>=()");
2368 return ( std::includes(pSet->begin(), pSet->end(), rOtherSet. pSet->begin(), rOtherSet. pSet->end()) );
2373 return *pSet < *rOtherSet. pSet;
2384TEMP bool THIS::AttributeTest( const Type& rAttr) const {
2385 return AttributeType()-> Cast(&rAttr)!=NULL;
2390 return ( Idx) pAttributes->size();
2394TEMP void THIS::ClearAttributes( void) {
2396 if(this->pAttributes->size()==0) return;
2398 this->Detach(SetOnly);
2404 FD_DC( "TBaseSet::EqualAttributes(TBaseSet)");
2406 FD_DC( "TBaseSet::EqualAttributes(TBaseSet): 1");
2407 if( typeid(*rOtherSet. AttributeType())!= typeid(*this->AttributeType()))
2410 FD_DC( "TBaseSet::EqualAttributes(TBaseSet): 2");
2414 FD_DC( "TBaseSet::EqualAttributes(TBaseSet): 3");
2416 if(this->AttributesSize()==0)
2421 while ((ait1 != pAttributes->end()) && (ait2 != rOtherSet. pAttributes->end())) {
2422 if (ait1->first < ait2->first) {
2425 else if (ait1->first == ait2->first) {
2426 FD_DC( "TBaseSet::EqualAttributes(TBaseSet): cmp " << ait1->second->ToString()
2427 << " vs " << ait2->second->ToString());
2428 if( ! ait1->second->Equal(*ait2->second)) return false;
2437 FD_DC( "TBaseSet::EqualAttributes(TBaseSet): pass");
2446 this->DoAssign(rSourceSet);
2448 this->Detach(SetOnly);
2454 FD_DC( "TBaseSet::Attributes("<< this<< ")");
2457 std::stringstream errstr;
2458 errstr << "cannot cast attribute " << std::endl;
2459 throw Exception( "TBaseSet::Attributes(otherset)", errstr.str(), 63);
2462 if( typeid(*this->AttributeType())== typeid( const AttributeVoid)) return;
2464 this->Detach(AttrIncl);
2467 while ((it1 != pSet->end()) && (it2 != rOtherSet. pSet->end())) {
2471 else if (*it1 == *it2) {
2472 DoAttribute(*it1,&rOtherSet. Attribute(*it2));
2480 FD_DC( "TBaseSet::Attributes(): copy ok");
2488 std::stringstream errstr;
2489 errstr << "cannot get attribute for TBaseSet \"" << mObjectName << "\" type " << typeid(*this).name();
2490 throw Exception( "TBaseSet::Attributep(rElem)", errstr.str(), 63);
2504TEMP void THIS::Attribute( const T& rElem, const Type& rAttr) {
2507#ifdef FAUDES_CHECKED
2508 if (!Exists(rElem)) {
2509 std::stringstream errstr;
2510 errstr << "element not member of set" << std::endl;
2511 throw Exception( "TBaseSet::Attribute(elem,attr)", errstr.str(), 60);
2514 if(!AttributeTest(rAttr)) {
2515 std::stringstream errstr;
2516 errstr << "cannot cast attribute " << std::endl;
2517 throw Exception( "TBaseSet::Attribute(elem,attr)", errstr.str(), 63);
2524TEMP void THIS::ClrAttribute( const T& rElem) {
2533 ait=this->pAttributes->find(rElem);
2534 if(ait==this->pAttributes->end()) return NULL;
2540 FD_DC( "TBaseSet::DoAttributeExplicit(elem)");
2541#ifdef FAUDES_DEBUG_CODE
2542 if(this->pAttributes!=this->mpAttributes) {
2543 FD_ERR( "TBaseSet::DoAttributeExplicit(elem): attributes not detached");
2548 ait=this->pAttributes->find(rElem);
2549 if(ait!=this->pAttributes->end())
2553 FD_DC( "TBaseSet::DoAttributeExplicit(Elem): inserting explicit default " << attr << " type " << typeid(*attr).name());
2554 (*this->pAttributes)[rElem]=attr;
2559TEMP void THIS::DoAttribute( const T& rElem, const Type* pAttr) {
2560 FD_DC( "TBaseSet::DoAttribute([v] " << this->EStr(rElem) << ", ...)");
2561#ifdef FAUDES_DEBUG_CODE
2562 if(this->pAttributes!=this->mpAttributes) {
2563 FD_ERR( "TBaseSet::DoAttribute([v] set): attributes not detached");
2569 if(!this->AttributeType()->Cast(pAttr)) newattr=NULL;
2573 ait=this->pAttributes->find(rElem);
2574 if(ait!=this->pAttributes->end() )
2575 oldattr=ait->second;
2578 FD_DC( "TBaseSet::DoAttribute([v] " << this->EStr(rElem) << ", ...): default 1");
2579 if(oldattr==NULL) return;
2581 this->pAttributes->erase(ait);
2586 FD_DC( "TBaseSet::DoAttribute([v] " << this->EStr(rElem) << ", ...): default 2");
2587 if(oldattr==NULL) return;
2589 this->pAttributes->erase(ait);
2592 FD_DC( "TBaseSet::DoAttribute([v] " << this->EStr(rElem) << ", ...): " << newattr-> ToString());
2597 (*this->pAttributes)[rElem]=attr;
2601 FD_DC( "TBaseSet::DoAttribute([v] " << this->EStr(rElem) << ", ...): " << newattr-> ToString());
2602 oldattr-> Assign(*newattr);
2606TEMP void THIS::FromStl( const std::set<T,Cmp>& rStlSet) {
2608 typename std::set<T,Cmp>::const_iterator it;
2610 while(it!=rStlSet.end())
2615TEMP void THIS::ToStl(std::set<T,Cmp>& rStlSet) const {
#define FAUDES_OBJCOUNT_DEC(type)
#define FAUDES_OBJCOUNT_INC(type)
#define FAUDES_TYPE_TIMPLEMENTATION_CAST(ftype, ctype, cbase, ctemp)
#define FAUDES_TYPE_TIMPLEMENTATION_EQUAL(ftype, ctype, cbase, ctemp)
#define FAUDES_TYPE_TDECLARATION(ftype, ctype, cbase)
#define FAUDES_TYPE_TIMPLEMENTATION_ASSIGN(ftype, ctype, cbase, ctemp)
#define FAUDES_TYPE_TIMPLEMENTATION_COPY(ftype, ctype, cbase, ctemp)
#define FAUDES_TYPE_TIMPLEMENTATION_NEW(ftype, ctype, cbase, ctemp)
virtual bool IsDefault(void) const
std::string mElementTagDef
const std::string & Name(void) const
Iterator(const TBaseSet< T, Cmp > *pBaseSet, const typename std::set< T, Cmp >::const_iterator &sit, bool att=false)
void StlIterator(const typename std::set< T, Cmp >::const_iterator &sit)
Iterator(const Iterator &fit)
const TBaseSet< T, Cmp > * pBaseSet
const std::set< T, Cmp >::const_iterator & StlIterator(void) const
std::string DStr(void) const
std::list< TBaseSet< T, Cmp > * > * mpClients
std::map< T, AttributeVoid * > * pGea
std::map< T, AttributeVoid * > * mpAttributes
std::set< Iterator * > mIterators
std::set< T, Cmp >::iterator iterator
std::set< T, Cmp > * mpSet
std::set< T, Cmp > * pGes
virtual void AttributeTry(const T &rElem, const Type &rAttr)
std::map< T, AttributeVoid * > * pAttributes
std::map< T, AttributeVoid * >::const_iterator const_aiterator
std::set< T, Cmp >::const_iterator const_iterator
std::map< T, AttributeVoid * >::iterator aiterator
std::list< TBaseSet< T, Cmp > * >::iterator mClientRecord
std::set< T, Cmp > * pSet
TBaseSet< T, Cmp > * pHostSet
std::string FileLine(void) const
bool Eos(const std::string &rLabel)
void ReadEnd(const std::string &rLabel)
void ReadBegin(const std::string &rLabel)
void WriteComment(const std::string &rComment)
void Write(Token &rToken)
void WriteEnd(const std::string &rLabel)
void WriteBegin(const std::string &rLabel)
const std::string & StringValue(void) const
@ Begin <label> (begin of section)
bool ExistsAttributeString(const std::string &name)
const std::string & AttributeStringValue(const std::string &name)
TokenType Type(void) const
void ElementType(const std::string &rTypeName, const std::string &rElementType)
static TypeRegistry * G()
void DWrite(const Type *pContext=0) const
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
std::string ToString(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
virtual Type & Assign(const Type &rSrc)
virtual Type * New(void) const
virtual Type * Copy(void) const
void Write(const Type *pContext=0) const
virtual const Type * Cast(const Type *pOther) const
virtual bool Insert(const T &rElem)
bool DoEqual(const TBaseSet &rOtherSet) const
virtual const AttributeVoid * AttributeType(void) const
virtual std::string Str(void) const
void DoAttribute(const T &rElem, const Type *pAttr)
virtual TBaseSet & AssignWithoutAttributes(const TBaseSet &rSourceSet)
void DoAssign(const TBaseSet &rSourceSet)
void Detach(DetachMode flag=AttrIncl) const
bool SetInclusion(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB)
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
void AttachClient(TBaseSet *pRef) const
bool SetEquality(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB)
virtual void DoReadElement(TokenReader &rTr, T &rElem, const std::string &rLabel, const Type *pContext)
void DetachClient(TBaseSet *pRef) const
void SetDifference(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB, TBaseSet< T, Cmp > &rRes)
static std::map< T, AttributeVoid * > * GlobalEmptyAttributes(void)
bool Exists(const T &rElem) const
virtual void Attributes(const TBaseSet &rOtherSet)
virtual void Attribute(const T &rElem, const Type &rAttr)
static std::set< T, Cmp > * GlobalEmptySet(void)
virtual bool Disjoint(const TBaseSet &rOtherSet) const
virtual void FromStl(const std::set< T, Cmp > &rStlSet)
const AttributeVoid * DoAttribute(const T &rElem) const
void DetachIterator(Iterator *pFit) const
TBaseSet< T, Cmp >::Iterator ThisIterator(const typename std::set< T, Cmp >::const_iterator &sit) const
virtual void DoWriteElement(TokenWriter &rTw, const T &rElem, const std::string &rLabel="", const Type *pContext=0) const
Iterator Find(const T &rElem) const
virtual bool Valid(const T &rElem) const
virtual Iterator Inject(const Iterator &pos, const T &rElem)
virtual void DoDWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Idx AttributesSize(void) const
virtual void DoXWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
virtual bool AttributeTest(const Type &rAttr) const
TBaseSet(const std::string &rFilename, const std::string &rLabel="BaseSet")
virtual void DoDWriteElement(TokenWriter &rTw, const T &rElem, const std::string &rLabel="", const Type *pContext=0) const
virtual void RestrictSet(const TBaseSet &rOtherSet)
virtual void InsertSet(const TBaseSet &rOtherSet)
virtual AttributeVoid * Attributep(const T &rElem)
bool EqualAttributes(const TBaseSet &rOtherSet) const
Iterator Begin(void) const
virtual void DoXWriteElement(TokenWriter &rTw, const T &rElem, const std::string &rLabel="", const Type *pContext=0) const
virtual const AttributeVoid & Attribute(const T &rElem) const
void DValid(const std::string &rMessage="") const
AttributeVoid * DoAttributeExplicit(const T &rElem)
virtual bool Erase(const T &rElem)
void SetUnion(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB, TBaseSet< T, Cmp > &rRes)
void SetIntersection(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB, TBaseSet< T, Cmp > &rRes)
virtual void EraseSet(const TBaseSet &rOtherSet)
TBaseSet(const TBaseSet &rOtherSet)
virtual void Inject(const T &rElem)
virtual void ToStl(std::set< T, Cmp > &rStlSet) const
void ClearAttributes(void)
virtual std::string Str(const T &rElem) const
virtual Iterator Erase(const Iterator &pos)
void AttachIterator(Iterator *pFit) const
virtual void ClrAttribute(const T &rElem)
virtual bool IsDefault(void) const
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
virtual void DoSWrite(TokenWriter &rTw) const
const std::string & FaudesTypeName(const Type &rObject)
std::string ToStringInteger(Int number)
std::string CollapsString(const std::string &rString, unsigned int len)
libFAUDES 2.33k
--- 2025.09.16
--- c++ api documentaion by doxygen
|