|
|
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;
240 bool IsEnd( const Iterator& pos) const;
253 virtual bool Valid( const T& rElem) const;
274 virtual Iterator Erase( const Iterator& pos);
322 virtual Iterator Inject( const Iterator& pos, const T& rElem);
363 Iterator Find( const T& rElem) const;
400 void DValid( const std::string& rMessage= "") const;
422 class Iterator : private std::set<T,Cmp>::const_iterator {
434 const typename std::set<T,Cmp>::const_iterator& sit,
440 if(pBaseSet && att) {
449 pBaseSet(fit.pBaseSet),
453 pBaseSet->AttachIterator( this);
460 if(mAttached) pBaseSet->DetachIterator( this);
465 std::stringstream rstr;
466 rstr << "[dit base " << pBaseSet << " a" << mAttached << " data " << pBaseSet->pSet;
467 if(pBaseSet) rstr << " elem " << pBaseSet->Str(** this);
474#ifdef FAUDES_DEBUG_CODE
476 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator= invalid iterator: no baseset");
481 if(mAttached) if(pBaseSet==rSrc. pBaseSet) {
482 std::set<T,Cmp>::const_iterator::operator= (rSrc);
486 if(mAttached) pBaseSet->DetachIterator( this);
487 std::set<T,Cmp>::const_iterator::operator= (rSrc);
499 void StlIterator( const typename std::set<T,Cmp>::const_iterator& sit) {
500 std::set<T,Cmp>::const_iterator::operator= (sit);
504 const typename std::set<T,Cmp>::const_iterator& StlIterator( void) const {
521 if(pBaseSet==NULL) return false;
522 return !pBaseSet->IsEnd(* this);
528 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):DValid(): invalid iterator: no BaseSet");
531 pBaseSet->DValid( "Iterator");
535 const T* operator-> ( void) const {
536#ifdef FAUDES_DEBUG_CODE
538 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator->: invalid iterator: no baseset");
542 return std::set<T,Cmp>::const_iterator::operator-> ();
546 const T& operator* ( void) const {
547#ifdef FAUDES_DEBUG_CODE
549 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator*: invalid iterator: no baseset");
553 return std::set<T,Cmp>::const_iterator::operator* ();
558#ifdef FAUDES_DEBUG_CODE
560 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator==: invalid iterator: no baseset");
564 return * static_cast< const typename std::set<T,Cmp>::const_iterator * >( this) == rOther;
569#ifdef FAUDES_DEBUG_CODE
571 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator!=: invalid iterator: no baseset");
575 return * static_cast< const typename std::set<T,Cmp>::const_iterator * >( this) != rOther;
580#ifdef FAUDES_DEBUG_CODE
582 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator++: invalid iterator: no baseset");
587 std::set<T,Cmp>::const_iterator::operator++ (step);
593#ifdef FAUDES_DEBUG_CODE
595 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator++: invalid iterator: no baseset");
599 std::set<T,Cmp>::const_iterator::operator++ ();
605#ifdef FAUDES_DEBUG_CODE
607 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator--: invalid iterator: no baseset");
611 Iterator old(pBaseSet, * this, true);
612 std::set<T,Cmp>::const_iterator::operator-- (step);
618#ifdef FAUDES_DEBUG_CODE
620 FD_ERR( "TBaseSet<T,Cmp>::Iterator(" << this << "):operator--: invalid iterator: no baseset");
624 std::set<T,Cmp>::const_iterator::operator-- ();
643#ifdef DONT_TRACK_REFERENCES
650 class Iterator : public std::set<T,Cmp>::const_iterator {
655 std::set<T,Cmp>::const_iterator()
659 Iterator( const Iterator& fit) :
660 std::set<T,Cmp>::const_iterator(fit)
664 Iterator( const typename std::set<T,Cmp>::const_iterator& sit) :
665 std::set<T,Cmp>::const_iterator(sit)
670 const TBaseSet<T,Cmp>* pBaseSet,
671 const typename std::set<T,Cmp>::const_iterator& sit) :
672 std::set<T,Cmp>::const_iterator(sit)
676 void StlIterator( const typename std::set<T,Cmp>::const_iterator& sit) {
677 std::set<T,Cmp>::const_iterator::operator= (sit);
681 const typename std::set<T,Cmp>::const_iterator& StlIterator( void) const {
686 void Invalidate( void) {};
689 bool Valid( void) const { return false;};
821 virtual void AttributeTry( const T& rElem, const Type& rAttr) { (void) rElem; (void) rAttr; };
840 virtual void FromStl( const std::set<T,Cmp>& rStlSet);
850 virtual void ToStl(std::set<T,Cmp>& rStlSet) const;
1049 typedef typename std::map<T,AttributeVoid*>::iterator aiterator;
1100 std::map< T, AttributeVoid* >* pGea;
1117template< class T, class Cmp>
1119 FD_DC( "FAUDES_DEBUG_CONTAINER: SetUnion(TBaseSet<T,Cmp>): res at " << &rRes);
1123 if(&rSetA==&rSetB && &rSetA==&rRes) {rRes. Name(name); return;}
1125 if(&rSetA==&rSetB) {rRes. Copy(rSetA); rRes. Name(name); return;}
1127 if(&rSetA==&rRes) {rRes. InsertSet(rSetB); rRes. Name(name); return;};
1129 if(&rSetB==&rRes) {rRes. InsertSet(rSetA); rRes. Name(name); return;};
1134 FD_DC( "FAUDES_DEBUG_CONTAINER: SetUnion(TBaseSet<T,Cmp>): done, res at " << &rRes << " #" << rRes. Size());
1147template< class T, class Cmp >
1152 if(&rSetA==&rSetB && &rSetA==&rRes) {rRes. Name(name); return;}
1154 if(&rSetA==&rSetB) { rRes. Copy(rSetA); rRes. Name(name); return;}
1156 if(&rSetA==&rRes) {rRes. RestrictSet(rSetB); rRes. Name(name); return;};
1158 if(&rSetB==&rRes) {rRes. RestrictSet(rSetA); rRes. Name(name); return;};
1176template< class T, class Cmp >
1181 if(&rSetA==&rSetB) { rRes. Clear(); rRes. Name(name); return;}
1183 if(&rSetA==&rRes) {rRes. EraseSet(rSetB); rRes. Name(name); return;};
1210template< class T, class Cmp >
1212 return rSetA==rSetB;
1226template< class T, class Cmp >
1228 return rSetA<=rSetB;
1250#define THIS TBaseSet<T,Cmp>
1251#define TEMP template<class T, class Cmp>
1272 static std::set<T,Cmp> ges;
1273#ifdef FAUDES_DEBUG_CODE
1274 static bool done= false;
1276 std::cerr << "BaseSet::GlobalEmptySet(): for " << typeid(ges).name() << " at " << &ges << std::endl;
1284TEMP std::map< T,AttributeVoid* > * THIS::GlobalEmptyAttributes( void) {
1285 static std::map<T,AttributeVoid*> gea;
1286#ifdef FAUDES_DEBUG_CODE
1287 static bool done= false;
1289 std::cerr << "BaseSetGlobalEmptyAttributes(): for " << typeid(gea).name() << " at " << &gea << std::endl;
1300 pSet(GlobalEmptySet()),
1302 pAttributes(GlobalEmptyAttributes()),
1305 mpClients(new std::list< TBaseSet<T,Cmp>* >),
1308 pGes(GlobalEmptySet()),
1309 pGea(GlobalEmptyAttributes())
1312 FD_DC( "TBaseSet(" << this << ")::TBaseSet(): as " << typeid(*this).name() );
1316#ifdef FAUDES_DEBUG_CODE
1324 FD_DC( "TBaseSet(" << this << ")::TBaseSet(rOtherSet " << &rOtherSet << "): fake copy construct");
1330#ifdef FAUDES_DEBUG_CODE
1336TEMP THIS::TBaseSet( const std::string& rFileName, const std::string& rLabel) : TBaseSet() {
1338 FD_DC( "TBaseSet(" << this << ")::TBaseSet()");
1343 Read(rFileName,rLabel);
1350 FD_DC( "TBaseSet(" << this << ")::~TBaseSet()");
1353 pHostSet->DetachClient( this);
1354 if(mpClients) delete mpClients;
1357 typename std::set< Iterator* >::const_iterator iit;
1358 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1359 (**iit).Invalidate();
1362 if(mpSet) delete mpSet;
1364 for( aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait)
1366 delete mpAttributes;
1373 FD_DC( "TBaseSet(" << this << "[" << this->Name() << "])::DoCopy(rOtherSet " << &rSourceSet << "): shallow copy -- src attr# " << rSourceSet.pAttributes->size());
1374 FD_DC( "TBaseSet():DoCopy(): " << typeid(*this->AttributeType()).name() << " <== " << typeid(*rSourceSet.AttributeType()).name());
1375#ifdef FAUDES_DEBUG_CODE
1376 DValid( "PreFakeCopyment");
1379 if( this==&rSourceSet) {
1380 FD_DC( "TBaseSet():DoCopy(): bail out on identical objects");
1384 mObjectName=rSourceSet.mObjectName;
1385 mElementTagDef=rSourceSet.mElementTagDef;
1387 if(pHostSet==rSourceSet.pHostSet) return;
1390 pHostSet->DetachClient( this);
1397 for( aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait)
1399 delete mpAttributes;
1407 if( typeid(*rSourceSet.AttributeType())== typeid(*this->AttributeType())) {
1408 pHostSet=rSourceSet.pHostSet;
1409 pHostSet->AttachClient( this);
1410 pSet=rSourceSet.pSet;
1411 pAttributes=rSourceSet.pAttributes;
1415 mpSet = new std::set<T,Cmp>();
1416 *mpSet = *rSourceSet.pSet;
1418 mpAttributes = new std::map<T,AttributeVoid*>();
1419 if( typeid(*this->AttributeType()) != typeid( const AttributeVoid)) {
1420 for( aiterator ait=rSourceSet.pAttributes->begin(); ait!=rSourceSet.pAttributes->end(); ++ait) {
1422 (*mpAttributes)[ait->first]=attr;
1426 pAttributes = mpAttributes;
1428 mpClients= new std::list< TBaseSet<T,Cmp>* >;
1431 typename std::set< Iterator* >::iterator iit;
1432 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1433 (**iit).Invalidate();
1443#ifdef FAUDES_DEBUG_CODE
1444 DValid( "PostFakeCopyment");
1446 FD_DC( "TBaseSet(" << this << ")::DoCopy(rOtherSet " << &rSourceSet << "): fake copy -- done with attr# " << pAttributes->size());
1452 FD_DF( "TBaseSet(" << this << ")::DoMove(void): fallback to DoCopy()");
1458 FD_DC( "TBaseSet(" << this << ")::Detach(void)");
1459#ifdef FAUDES_DEBUG_CODE
1460 DValid( "PreDetach");
1465 if(flag==SetOnly) pAttributes->clear();
1470 THIS* fake_const = const_cast< THIS* >( this);
1472#ifdef FAUDES_DEBUG_CODE
1477 if(mpClients->empty()) {
1478 FD_ERR( "TBaseSet(" << this << ")::Detach(): missed detach (?)");
1480 fake_const->mDetached= true;
1485 std::set<T,Cmp>* scopy = new std::set<T,Cmp>();
1489 std::map<T,AttributeVoid*>* acopy = new std::map<T,AttributeVoid*>();
1490 if(flag==AttrIncl) {
1491 for( aiterator ait=pAttributes->begin(); ait!=pAttributes->end(); ++ait) {
1493 (*acopy)[ait->first]=attr;
1502 FD_DC( "TBaseSet(" << this << ")::Detach(): allocate and copy, strategie A");
1504 THIS* newhost = *mpClients->begin();
1505#ifdef FAUDES_DEBUG_CODE
1506 if(newhost->mpClients)
1507 FD_ERR( "TBaseSet(" << this << ")::Detach(): new host used to have clients (?)");
1509 newhost->pHostSet=newhost;
1510 newhost->mpSet=scopy;
1511 newhost->pSet=scopy;
1512 newhost->mpAttributes=acopy;
1513 newhost->pAttributes=acopy;
1514 newhost->mpClients=mpClients;
1515 newhost->DetachClient(newhost);
1516 fake_const->mpClients=NULL;
1518 typename std::list< THIS* >::const_iterator rit;
1519 for(rit=newhost->mpClients->begin();rit!=newhost->mpClients->end(); ++rit) {
1520 (*rit)->pHostSet=newhost;
1521 (*rit)->pSet=newhost->pSet;
1522 (*rit)->pAttributes=newhost->pAttributes;
1525 typename std::set< Iterator* >::iterator iit;
1526 for(rit=newhost->mpClients->begin(); rit!=newhost->mpClients->end(); ++rit) {
1527 for(iit=(*rit)->mIterators.begin(); iit!=(*rit)->mIterators.end(); ++iit) {
1528 if((**iit).StlIterator()==pSet->end())
1529 **iit= Iterator( this, scopy->end());
1531 **iit= Iterator( this, scopy->find(***iit));
1535 for(iit=newhost->mIterators.begin(); iit!=newhost->mIterators.end(); ++iit) {
1536 if((**iit).StlIterator()==pSet->end())
1537 **iit= Iterator( this, scopy->end());
1539 **iit= Iterator( this, scopy->find(***iit));
1542 fake_const->mpSet=pSet;
1543 fake_const->mpAttributes=pAttributes;
1544 fake_const->mpClients= new std::list< TBaseSet<T,Cmp>* >;
1545 fake_const->mDetached= true;
1547 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit)
1549 fake_const->mIterators.clear();
1557 FD_DC( "TBaseSet(" << this << ")::Detach(): allocate and copy, strategie B");
1559 fake_const->RelinkClients();
1560 pHostSet->DetachClient(fake_const);
1562 fake_const->mpSet = scopy;
1563 fake_const->mpAttributes=acopy;
1565 typename std::set< Iterator* >::iterator iit;
1566 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1567 if((**iit).StlIterator()==pSet->end())
1568 **iit= Iterator( this, mpSet->end());
1570 **iit= Iterator( this, mpSet->find(***iit));
1573 fake_const->pHostSet=fake_const;
1574 fake_const->pSet=mpSet;
1575 fake_const->pAttributes=mpAttributes;
1576 fake_const->mDetached= true;
1577 if(fake_const->mpClients) delete fake_const->mpClients;
1578 fake_const->mpClients= new std::list< TBaseSet<T,Cmp>* >;
1582#ifdef FAUDES_DEBUG_CODE
1583 DValid( "PostDetach");
1585 FD_DC( "TBaseSet(" << this << ")::Detach(): done");
1590 FD_DC( "TBaseSet(" << this << ")::Lock(void)");
1591#ifdef FAUDES_DEBUG_CODE
1601 THIS* fake_const = const_cast< THIS* >( this);
1604 typename std::set< Iterator* >::const_iterator iit;
1605 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1608 fake_const->mIterators.clear();
1611 fake_const->mLocked= true;
1613#ifdef FAUDES_DEBUG_CODE
1620TEMP inline void THIS::RelinkClients( void) {
1621 FD_DC( "TBaseSet::RelinkClients(" << this << ")")
1622#ifdef FAUDES_DEBUG_CODE
1623 DValid( "PreRelink");
1627 if(!mpClients) return;
1629 if(mpClients->empty()) return;
1631 FD_DC( "TBaseSet::RelinkClients(" << this << "): doit")
1634 THIS* newhost = *mpClients->begin();
1635#ifdef FAUDES_DEBUG_CODE
1636 if(newhost->pHostSet!= this)
1637 FD_ERR( "BaseSet::RelinkRefernces: old reference must have this as provider");
1638 if(newhost->mpClients)
1639 FD_ERR( "TBaseSet(" << this << ")::RelinkClients(void): client is a host (?)");
1641 newhost->pHostSet=newhost;
1642 newhost->mpSet=mpSet;
1644 newhost->mpAttributes=mpAttributes;
1645 newhost->pAttributes=pAttributes;
1646 newhost->mpClients=mpClients;
1647 newhost->DetachClient(newhost);
1650 typename std::list< THIS* >::const_iterator rit;
1651 for(rit=newhost->mpClients->begin();rit!=newhost->mpClients->end(); ++rit) {
1652 (*rit)->pHostSet=newhost;
1658 pAttributes=newhost->pAttributes;
1660 newhost->AttachClient( this);
1661#ifdef FAUDES_DEBUG_CODE
1662 DValid( "PostRelink");
1664 FD_DC( "TBaseSet::RelinkClients(" << this << "): done")
1671 const_cast< THIS* >( this)->mpClients->push_back(pRef);
1673 const_cast< THIS* >( this)->mDetached= false;
1678 FD_DC( "TBaseSet::DetachClient(" << this << "):" << pRef);
1680 if(!mpClients) return;
1681 if(mpClients->empty()) return;
1684 THIS* fake_const = const_cast< THIS* >( this);
1685#ifdef FAUDES_DEBUG_CODE
1687 typename std::list< TBaseSet<T,Cmp>* >::iterator cit;
1689 for(cit=fake_const->mpClients->begin(); cit!=fake_const->mpClients->end(); ++cit) {
1690 if(*cit==pRef) cf= true;
1693 FD_ERR( "TBaseSet::DetachClient(" << this << "): client not found " << pRef);
1706 typename std::list< TBaseSet<T,Cmp>* >::iterator rit;
1707 for(rit=fake_const->mpClients->begin(); rit!=fake_const->mpClients->end(); ++rit) {
1708 if(*rit!=pRef) continue;
1709 fake_const->mpClients->erase(rit);
1713 if(mpClients->empty() && (pSet!=pGes)) fake_const->mDetached= true;
1714 FD_DC( "TBaseSet::DetachClient(" << this << "): done.");
1721 FD_DC( "TBaseSet::AttachIterator(" << this << "):" << pFit)
1722 const_cast< THIS* >( this)->mIterators.insert(pFit);
1728 FD_DC( "TBaseSet::DetachIterator(" << this << "):" << pFit)
1729 const_cast< THIS* >( this)->mIterators.erase(pFit);
1733TEMP void THIS::DValid( const std::string& rMessage) const {
1734 typename std::set< Iterator* >::const_iterator iit;
1735 typename std::list< THIS* >::const_iterator rit;
1736#ifdef FAUDES_DEBUG_CONTAINER
1737 std::cerr << "TBaseSet(" << this << ")::DValid(): " << rMessage <<
1738 " host " << pHostSet << (pHostSet == this ? " +s+ " : " ") <<
1739 (pHostSet->pSet==pHostSet->pGes ? "+e+ " : "+f+ ") <<
1740 (mLocked ? "+l+ " : " ") << (mDetached ? "+d+" : " ")
1741 << " stl at " << pSet << " own data " << mpSet << " ges " << pGes;
1742 std::cerr << " -- refs ";
1743 if(pHostSet->mpClients)
1744 for(rit=pHostSet->mpClients->begin(); rit!=pHostSet->mpClients->end(); ++rit)
1745 std::cerr << *rit << " ";
1746 std::cerr << "-- its ";
1747 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit)
1748 std::cerr << *iit << " ";
1749 std::cerr << "-- attr at " << pAttributes;
1750 std::cerr << "(#" << pAttributes->size() << ") ";
1751 if(mpAttributes) std::cerr << "(" << mpAttributes->size() << ") ";
1752 else std::cerr << " ";
1753 std::cerr << (pAttributes==pGea ? "+e+ " : "+f+ ") << std::endl;
1756 if(pGes!=GlobalEmptySet()) {
1757 FD_WARN( "BaseSet("<< this << "," << rMessage << "): lost empty set: " << pGes);
1761 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1762 if((*iit)->pBaseSet!= this) {
1763 FD_WARN( "BaseSet("<< this << "," << rMessage << "): invalid iterator (baseset): "<< *iit);
1768 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1769 if(!(*iit)->mAttached) {
1770 FD_WARN( "BaseSet("<< this << "," << rMessage << "): invalid iterator (attached): "<< *iit);
1775 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1776 typename std::set<T,Cmp>::const_iterator vit;
1777 for(vit=pSet->begin(); vit!= pSet->end(); ++vit) {
1778 if(vit==(**iit).StlIterator()) break;
1780 if(vit!=(**iit).StlIterator()) {
1781 FD_WARN( "BaseSet("<< this << "," << rMessage << "): invalid iterator (stl) "<< *iit);
1782 (**iit).StlIterator(pSet->end());
1787 if(pHostSet==NULL) {
1788 FD_WARN( "BaseSet(" << this << "," << rMessage << "): no host found");
1792 if(pHostSet->pHostSet != pHostSet) {
1793 FD_WARN( "BaseSet(" << this << "," << rMessage << "): inconsistent host");
1797 if((mpSet!=NULL) && (pHostSet != this)) {
1798 FD_WARN( "BaseSet(" << this << "," << rMessage << "): double data");
1802 if(pHostSet!= this && mpClients!=NULL) {
1803 FD_WARN( "BaseSet(" << this << "," << rMessage << "): cannot be client and have clients oneself");
1807 if(pHostSet->mpClients==NULL) {
1808 FD_WARN( "BaseSet(" << this << "," << rMessage << "): refers to invalid host (a)");
1812 if(pHostSet!= this && pHostSet->mpClients->empty()) {
1813 FD_WARN( "BaseSet(" << this << "," << rMessage << "): refers to invalid host (b)");
1817 if((pHostSet == this) && (mpSet==NULL) && (pSet!=pGes)) {
1818 FD_WARN( "BaseSet(" << this << "," << rMessage << "): no data");
1822 if((pHostSet== this) && (pSet!=pGes) && (mpClients==NULL)) {
1823 FD_WARN( "BaseSet(" << this << "," << rMessage << "): host with no client list");
1827 if((pHostSet == this) && (pSet != mpSet) && (pSet!=pGes)) {
1828 FD_WARN( "BaseSet(" << this << "," << rMessage << "): data pointer mismatch A");
1832 if(pSet != pHostSet->pSet) {
1833 FD_WARN( "BaseSet(" << this << "," << rMessage << "): data pointer mismatch B");
1838 for(rit=pHostSet->mpClients->begin(); rit!=pHostSet->mpClients->end(); ++rit) {
1839 if((*rit)== this) hf= true;
1840 if((*rit)->pHostSet== pHostSet) continue;
1841 FD_WARN( "BaseSet(" << this << "," << rMessage << "): invalid client " << (*rit));
1844 if(!hf && (pHostSet!= this)) {
1845 FD_WARN( "BaseSet(" << this << "," << rMessage << "): client not registered with host");
1849 if(pHostSet!= this && *mClientRecord!= this) {
1850 FD_WARN( "BaseSet(" << this << "," << rMessage << "): refers to invalid host (c)");
1854 if(mDetached && mpClients==NULL) {
1855 FD_WARN( "BaseSet(" << this << "," << rMessage << "): invalid detached flag A");
1859 if(mDetached && !mpClients->empty()) {
1860 FD_WARN( "BaseSet(" << this << "," << rMessage << "): invalid detached flag B");
1864 if(mDetached && (pSet==pHostSet->pGes)) {
1865 FD_WARN( "BaseSet(" << this << "," << rMessage << "): detached empty set");
1869 if(mLocked && (mpClients==NULL)) {
1870 FD_WARN( "BaseSet(" << this << "," << rMessage << "): locked reference (a)");
1874 if(!pGes->empty()) {
1875 FD_WARN( "BaseSet(" << this << "," << rMessage << "): invalid empty set");
1879 if(!GlobalEmptyAttributes()->empty()) {
1880 FD_WARN( "BaseSet(" << this << "," << rMessage << "): invalid empty attributes");
1883#ifdef FAUDES_DEBUG_CONTAINER
1884 std::cerr << "TBaseSet(" << this << ")::DValid(): passed" << std::endl;
1890TEMP std::string THIS::Str( const T& rElem) const {
1892 std::string res= "E";
1897TEMP std::string THIS::Str( void) const {
1898 std::stringstream str;
1899 str << "[" << Name() << "]{ ";
1902 if(Size()>0) while( true) {
1903 str << Str(*(eit++));
1904 if(eit==eit_end) break;
1913 return ( Idx) pSet->size();
1918 return pSet->empty();
1922TEMP void THIS::DoWriteElement( TokenWriter& rTw, const T& rElem, const std::string& rLabel, const Type* pContext) const {
1926 ep-> Write(rTw,rLabel,pContext);
1930 std::stringstream errstr;
1931 errstr << "used but not reimplemented" << typeid( this).name() << std::endl;
1932 throw Exception( "BaseSet::DoWriteElement", errstr.str(), 61);
1936TEMP void THIS::DoXWriteElement( TokenWriter& rTw, const T& rElem, const std::string& rLabel, const Type* pContext) const {
1940 ep-> XWrite(rTw,rLabel,pContext);
1944 std::stringstream errstr;
1945 errstr << "used but not reimplemented" << typeid( this).name() << std::endl;
1946 throw Exception( "BaseSet::DoXWriteElement", errstr.str(), 61);
1950TEMP void THIS::DoDWriteElement( TokenWriter& rTw, const T& rElem, const std::string& rLabel, const Type* pContext) const {
1954 ep-> DWrite(rTw,rLabel,pContext);
1958 std::stringstream errstr;
1959 errstr << "used but not reimplemented" << typeid( this).name() << std::endl;
1960 throw Exception( "BaseSet::DoDWriteElement", errstr.str(), 61);
1965 std::string label=rLabel;
1966 if(label== "") label=Name();
1967 if(label== "") label= "BaseSet";
1968 std::string etstr=ElementTag();
1969 FD_DC( "TBaseSet(" << this << ")::DoWrite(..): section " << label << " #" << Size());
1973 for (it = Begin(); it != End(); ++it) {
1974 DoWriteElement(rTw, *it, etstr, pContext);
1983 Token btag=XBeginTag(rLabel, "BaseSet");
1985 FD_DC( "BaseSet(" << this << ")::DoXWrite(..): section " << btag. StringValue() << " #" << Size());
1987 std::string etstr=ElementTag();
1989 for (it = Begin(); it != End(); ++it) {
1990 DoXWriteElement(rTw, *it, etstr, pContext);
1997 std::string label=rLabel;
1998 if(label== "") label=Name();
1999 if(label== "") label= "BaseSet";
2000 std::string etstr=ElementTag();
2001 FD_DC( "TBaseSet(" << this << ")::DoDWrite(..): section " << label << " #" << Size());
2004 BASE::DoSWrite(rTw);
2006 if(pHostSet->mpClients) shares=pHostSet->mpClients->size();
2013#ifdef FAUDES_DEBUG_CODE
2018 for (it = Begin(); it != End(); ++it) {
2019 DoDWriteElement(rTw, *it, etstr, pContext);
2026 BASE::DoSWrite(rTw);
2028 if(pHostSet->mpClients) shares=pHostSet->mpClients->size();
2031 if(pAttributes->size()!=0)
2033 if(pAttributes->size()!=0) {
2045 ep-> Read(rTr,rLabel,pContext);
2049 std::stringstream errstr;
2050 errstr << "used but not reimplemented" << typeid( this).name() << std::endl;
2051 throw Exception( "BaseSet::DoReadElement", errstr.str(), 61);
2057 std::string label=rLabel;
2059 std::string etstr=ElementTag();
2061 std::string etype= "";
2071 if(label== "") label=ftype;
2077 FD_DC( "BaseSet(" << typeid(*this).name() << ")::DoRead(..): section " << label << " elements " << etstr);
2079 while(!rTr. Eos(label)) {
2083 FD_DC( "TBaseSet(" << typeid(*this).name() << ")::DoRead(..): inserting element");
2086 DoReadElement(rTr,elem,etstr,pContext);
2088 FD_DC( "TBaseSet(" << typeid(*this).name() << ")::DoRead(..): inserting element: ok");
2092 std::stringstream errstr;
2093 errstr << "Invalid token of type " << token. Str() << " at " << rTr. FileLine();
2094 throw Exception( "BaseSet::DoRead", errstr.str(), 50);
2097 FD_DC( "BaseSet(" << this << ")::DoRead(tr," << label << ", " << pContext << "): done");
2101TEMP typename THIS::Iterator THIS::ThisIterator( const typename std::set<T,Cmp>::const_iterator& sit) const {
2106TEMP inline typename THIS::Iterator THIS::Begin( void) const {
2107 return ThisIterator(pSet->begin());
2111TEMP inline typename THIS::Iterator THIS::End( void) const {
2112 return ThisIterator(pSet->end());
2118 FD_DC( "TBaseSet(" << this << ")::Clear()");
2119#ifdef FAUDES_DEBUG_CODE
2123 if(pSet==pHostSet->pGes) return;
2125 FD_DC( "TBaseSet(" << this << ")::Clear(): doit");
2126 FD_DC( "TBaseSet(" << this << ")::Clear(): type " << typeid(*this).name());
2128 if(mLocked) Detach(SetOnly);
2131 pHostSet->DetachClient( this);
2134 if(!mpClients) mpClients= new std::list< TBaseSet<T,Cmp>* >;
2143 for( aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait) {
2144 FD_DC( "TBaseSet(" << this << ")::Clear(): del attr " << ait->second);
2147 delete mpAttributes;
2152 pAttributes=GlobalEmptyAttributes();
2154 typename std::set< Iterator* >::iterator iit;
2155 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
2156 (**iit).Invalidate();
2161#ifdef FAUDES_DEBUG_CODE
2162 DValid( "PostClear");
2164 FD_DC( "TBaseSet(" << this << ")::Clear(): done");
2169TEMP bool THIS::IsDefault( void) const {
2170 return pSet->empty();
2174TEMP inline bool THIS::Valid( const T& rElem) const {
2185TEMP bool THIS::Insert( const T& rElem) {
2186#ifdef FAUDES_CHECKED
2188 std::stringstream errstr;
2189 errstr << "refuse to insert invalid element" << std::endl;
2190 throw Exception( "BaseSet::Insert", errstr.str(), 61);
2193 if(!mDetached) Detach();
2194 return pSet->insert(rElem).second;
2198TEMP typename THIS::Iterator THIS::Inject( const Iterator& pos, const T& rElem) {
2199 if(!mDetached) Detach();
2201 return ThisIterator(pSet->insert(dst,rElem));
2206TEMP void THIS::Inject( const T& rElem) {
2207 if(!mDetached) Detach();
2208 pSet->insert(pSet->end(),rElem);
2213 FD_DC( "TBaseSet(" << this << ")::InsertSet(" << &rOtherSet << ")");
2214 if(!mDetached) Detach();
2223 while ((it1 != pSet->end()) && (it2 != rOtherSet. pSet->end())) {
2227 else if (*it1 == *it2) {
2236 while (it2 != rOtherSet. pSet->end()) {
2244TEMP bool THIS::Erase( const T& rElem) {
2245 if(!mDetached) Detach();
2246 return (pSet->erase(rElem)!=0);
2252#ifdef FAUDES_CHECKED
2254 std::stringstream errstr;
2255 errstr << "iterator out of range " << std::endl;
2256 throw Exception( "BaseSet::Erase", errstr.str(), 62);
2262 return ThisIterator(del);
2268 FD_DC( "TBaseSet(" << this << ")::EraseSet(" << &rOtherSet << ")");
2269 if(!mDetached) Detach();
2273 while ((it != pSet->end()) && (oit != rOtherSet. pSet->end())) {
2275 it=pSet->lower_bound(*oit);
2277 else if (*it == *oit) {
2282 oit=rOtherSet. pSet->lower_bound(*it);
2290 FD_DC( "TBaseSet(" << this << ")::RestrictSet(" << &rOtherSet << ")");
2291 if(!mDetached) Detach();
2295 while ((it != pSet->end()) && (oit != rOtherSet. pSet->end())) {
2299 else if (*it == *oit) {
2304 oit=rOtherSet. pSet->lower_bound(*it);
2307 while(it != pSet->end()) {
2315 FD_DC( "TBaseSet(" << this << ")::Disjoint(" << &rOtherSet << ")");
2317 if(pSet->empty()) return true;
2318 if(rOtherSet. pSet->empty()) return true;
2319 if(*pSet->rbegin()<*rOtherSet. pSet->begin()) return true;
2320 if(*rOtherSet. pSet->rbegin()<*pSet->begin()) return true;
2321 if(rOtherSet. pSet==pSet) return false;
2325 while ((it != pSet->end()) && (oit != rOtherSet. pSet->end())) {
2326 if (*it < *oit) { it++; continue;}
2327 if (*it == *oit) { return false; }
2335TEMP typename THIS::Iterator THIS::Find( const T& rElem) const {
2336 return ThisIterator(pSet->find(rElem));
2340TEMP bool THIS::Exists( const T& rElem) const {
2341 return pSet->find(rElem) != pSet->end();
2370 FD_DC( "TBaseSet::DoEqual()");
2372 if(pSet == rOtherSet. pSet) return true;
2374 return ( *pSet == *rOtherSet. pSet );
2379 FD_DC( "BaseSet::op<=()");
2380 return ( std::includes(rOtherSet. pSet->begin(), rOtherSet. pSet->end(), pSet->begin(), pSet->end()) ) ;
2385 FD_DC( "BaseSet::op>=()");
2386 return ( std::includes(pSet->begin(), pSet->end(), rOtherSet. pSet->begin(), rOtherSet. pSet->end()) );
2391 return *pSet < *rOtherSet. pSet;
2402TEMP bool THIS::AttributeTest( const Type& rAttr) const {
2403 return AttributeType()-> Cast(&rAttr)!=NULL;
2408 return ( Idx) pAttributes->size();
2412TEMP void THIS::ClearAttributes( void) {
2414 if(this->pAttributes->size()==0) return;
2416 this->Detach(SetOnly);
2422 FD_DC( "TBaseSet::EqualAttributes(TBaseSet)");
2424 FD_DC( "TBaseSet::EqualAttributes(TBaseSet): 1");
2425 if( typeid(*rOtherSet. AttributeType())!= typeid(*this->AttributeType()))
2428 FD_DC( "TBaseSet::EqualAttributes(TBaseSet): 2");
2432 FD_DC( "TBaseSet::EqualAttributes(TBaseSet): 3");
2434 if(this->AttributesSize()==0)
2439 while ((ait1 != pAttributes->end()) && (ait2 != rOtherSet. pAttributes->end())) {
2440 if (ait1->first < ait2->first) {
2443 else if (ait1->first == ait2->first) {
2444 FD_DC( "TBaseSet::EqualAttributes(TBaseSet): cmp " << ait1->second->ToString()
2445 << " vs " << ait2->second->ToString());
2446 if( ! ait1->second->Equal(*ait2->second)) return false;
2455 FD_DC( "TBaseSet::EqualAttributes(TBaseSet): pass");
2464 this->DoCopy(rSourceSet);
2466 this->Detach(SetOnly);
2472 FD_DC( "TBaseSet::Attributes("<< this<< ")");
2475 std::stringstream errstr;
2476 errstr << "cannot cast attribute " << std::endl;
2477 throw Exception( "TBaseSet::Attributes(otherset)", errstr.str(), 63);
2480 if( typeid(*this->AttributeType())== typeid( const AttributeVoid)) return;
2482 this->Detach(AttrIncl);
2485 while ((it1 != pSet->end()) && (it2 != rOtherSet. pSet->end())) {
2489 else if (*it1 == *it2) {
2490 DoAttribute(*it1,&rOtherSet. Attribute(*it2));
2498 FD_DC( "TBaseSet::Attributes(): copy ok");
2506 std::stringstream errstr;
2507 errstr << "cannot get attribute for TBaseSet \"" << mObjectName << "\" type " << typeid(*this).name();
2508 throw Exception( "TBaseSet::Attributep(rElem)", errstr.str(), 63);
2522TEMP void THIS::Attribute( const T& rElem, const Type& rAttr) {
2525#ifdef FAUDES_CHECKED
2526 if (!Exists(rElem)) {
2527 std::stringstream errstr;
2528 errstr << "element not member of set" << std::endl;
2529 throw Exception( "TBaseSet::Attribute(elem,attr)", errstr.str(), 60);
2532 if(!AttributeTest(rAttr)) {
2533 std::stringstream errstr;
2534 errstr << "cannot cast attribute " << std::endl;
2535 throw Exception( "TBaseSet::Attribute(elem,attr)", errstr.str(), 63);
2542TEMP void THIS::ClrAttribute( const T& rElem) {
2551 ait=this->pAttributes->find(rElem);
2552 if(ait==this->pAttributes->end()) return NULL;
2558 FD_DC( "TBaseSet::DoAttributeExplicit(elem)");
2559#ifdef FAUDES_DEBUG_CODE
2560 if(this->pAttributes!=this->mpAttributes) {
2561 FD_ERR( "TBaseSet::DoAttributeExplicit(elem): attributes not detached");
2566 ait=this->pAttributes->find(rElem);
2567 if(ait!=this->pAttributes->end())
2571 FD_DC( "TBaseSet::DoAttributeExplicit(Elem): inserting explicit default " << attr << " type " << typeid(*attr).name());
2572 (*this->pAttributes)[rElem]=attr;
2577TEMP void THIS::DoAttribute( const T& rElem, const Type* pAttr) {
2578 FD_DC( "TBaseSet::DoAttribute([v] " << this->EStr(rElem) << ", ...)");
2579#ifdef FAUDES_DEBUG_CODE
2580 if(this->pAttributes!=this->mpAttributes) {
2581 FD_ERR( "TBaseSet::DoAttribute([v] set): attributes not detached");
2587 if(!this->AttributeType()->Cast(pAttr)) newattr=NULL;
2591 ait=this->pAttributes->find(rElem);
2592 if(ait!=this->pAttributes->end() )
2593 oldattr=ait->second;
2596 FD_DC( "TBaseSet::DoAttribute([v] " << this->EStr(rElem) << ", ...): default 1");
2597 if(oldattr==NULL) return;
2599 this->pAttributes->erase(ait);
2604 FD_DC( "TBaseSet::DoAttribute([v] " << this->EStr(rElem) << ", ...): default 2");
2605 if(oldattr==NULL) return;
2607 this->pAttributes->erase(ait);
2610 FD_DC( "TBaseSet::DoAttribute([v] " << this->EStr(rElem) << ", ...): " << newattr-> ToString());
2614 attr-> Copy(*newattr);
2615 (*this->pAttributes)[rElem]=attr;
2619 FD_DC( "TBaseSet::DoAttribute([v] " << this->EStr(rElem) << ", ...): " << newattr-> ToString());
2620 oldattr-> Copy(*newattr);
2624TEMP void THIS::FromStl( const std::set<T,Cmp>& rStlSet) {
2626 typename std::set<T,Cmp>::const_iterator it;
2628 while(it!=rStlSet.end())
2633TEMP 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_MOVE(ftype, ctype, cbase, ctemp)
#define FAUDES_TYPE_TIMPLEMENTATION_ASSIGN(ftype, ctype, cbase, ctemp)
#define FAUDES_TYPE_TIMPLEMENTATION_NEWCOPY(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
Iterator begin(void) const
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)
std::string Str(void) const
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()
virtual Type * NewCpy(void) const
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 Type & Copy(const Type &rSrc)
virtual void XWrite(const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0) const
virtual Type * New(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 & CopyWithoutAttributes(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
bool IsEnd(const Iterator &pos) const
virtual void DoXWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
void DoMove(TBaseSet &rSourceSet)
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)
void DoCopy(const TBaseSet &rSourceSet)
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 & TypeName(const Type &rObject)
std::string ToStringInteger(Int number)
std::string CollapsString(const std::string &rString, unsigned int len)
libFAUDES 2.34g
--- 2026.04.09
--- c++ api documentaion by doxygen
|