|
|
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;
1024 typedef typename std::map<T,AttributeVoid*>::iterator aiterator;
1075 std::map< T, AttributeVoid* >* pGea;
1092template< class T, class Cmp>
1094 FD_DC( "FAUDES_DEBUG_CONTAINER: SetUnion(TBaseSet<T,Cmp>): res at " << &rRes);
1098 if(&rSetA==&rSetB && &rSetA==&rRes) {rRes. Name(name); return;}
1100 if(&rSetA==&rSetB) {rRes. Copy(rSetA); rRes. Name(name); return;}
1102 if(&rSetA==&rRes) {rRes. InsertSet(rSetB); rRes. Name(name); return;};
1104 if(&rSetB==&rRes) {rRes. InsertSet(rSetA); rRes. Name(name); return;};
1109 FD_DC( "FAUDES_DEBUG_CONTAINER: SetUnion(TBaseSet<T,Cmp>): done, res at " << &rRes << " #" << rRes. Size());
1122template< class T, class Cmp >
1127 if(&rSetA==&rSetB && &rSetA==&rRes) {rRes. Name(name); return;}
1129 if(&rSetA==&rSetB) { rRes. Copy(rSetA); rRes. Name(name); return;}
1131 if(&rSetA==&rRes) {rRes. RestrictSet(rSetB); rRes. Name(name); return;};
1133 if(&rSetB==&rRes) {rRes. RestrictSet(rSetA); rRes. Name(name); return;};
1151template< class T, class Cmp >
1156 if(&rSetA==&rSetB) { rRes. Clear(); rRes. Name(name); return;}
1158 if(&rSetA==&rRes) {rRes. EraseSet(rSetB); rRes. Name(name); return;};
1185template< class T, class Cmp >
1187 return rSetA==rSetB;
1201template< class T, class Cmp >
1203 return rSetA<=rSetB;
1225#define THIS TBaseSet<T,Cmp>
1226#define TEMP template<class T, class Cmp>
1247 static std::set<T,Cmp> ges;
1248#ifdef FAUDES_DEBUG_CODE
1249 static bool done= false;
1251 std::cerr << "BaseSet::GlobalEmptySet(): for " << typeid(ges).name() << " at " << &ges << std::endl;
1259TEMP std::map< T,AttributeVoid* > * THIS::GlobalEmptyAttributes( void) {
1260 static std::map<T,AttributeVoid*> gea;
1261#ifdef FAUDES_DEBUG_CODE
1262 static bool done= false;
1264 std::cerr << "BaseSetGlobalEmptyAttributes(): for " << typeid(gea).name() << " at " << &gea << std::endl;
1275 pSet(GlobalEmptySet()),
1277 pAttributes(GlobalEmptyAttributes()),
1280 mpClients(new std::list< TBaseSet<T,Cmp>* >),
1283 pGes(GlobalEmptySet()),
1284 pGea(GlobalEmptyAttributes())
1287 FD_DC( "TBaseSet(" << this << ")::TBaseSet(): as " << typeid(*this).name() );
1291#ifdef FAUDES_DEBUG_CODE
1297TEMP THIS::TBaseSet( const std::string& rFileName, const std::string& rLabel) :
1299 pSet(GlobalEmptySet()),
1301 pAttributes(GlobalEmptyAttributes()),
1304 mpClients(new std::list< TBaseSet<T,Cmp>* >),
1307 pGes(GlobalEmptySet()),
1308 pGea(GlobalEmptyAttributes())
1311 FD_DC( "TBaseSet(" << this << ")::TBaseSet()");
1316 Read(rFileName,rLabel);
1322 pSet(GlobalEmptySet()),
1324 pAttributes(GlobalEmptyAttributes()),
1327 mpClients(new std::list< TBaseSet<T,Cmp>* >),
1330 pGes(GlobalEmptySet()),
1331 pGea(GlobalEmptyAttributes())
1334 FD_DC( "TBaseSet(" << this << ")::TBaseSet(rOtherSet " << &rOtherSet << "): fake copy construct");
1340#ifdef FAUDES_DEBUG_CODE
1348 FD_DC( "TBaseSet(" << this << ")::~TBaseSet()");
1351 pHostSet->DetachClient( this);
1352 if(mpClients) delete mpClients;
1355 typename std::set< Iterator* >::const_iterator iit;
1356 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1357 (**iit).Invalidate();
1360 if(mpSet) delete mpSet;
1362 for( aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait)
1364 delete mpAttributes;
1371 FD_DC( "TBaseSet(" << this << "[" << this->Name() << "])::DoCopy(rOtherSet " << &rSourceSet << "): shallow copy -- src attr# " << rSourceSet.pAttributes->size());
1372 FD_DC( "TBaseSet():DoCopy(): " << typeid(*this->AttributeType()).name() << " <== " << typeid(*rSourceSet.AttributeType()).name());
1373#ifdef FAUDES_DEBUG_CODE
1374 DValid( "PreFakeCopyment");
1377 if( this==&rSourceSet) {
1378 FD_DC( "TBaseSet():DoCopy(): bail out on identical objects");
1382 mObjectName=rSourceSet.mObjectName;
1383 mElementTagDef=rSourceSet.mElementTagDef;
1385 if(pHostSet==rSourceSet.pHostSet) return;
1388 pHostSet->DetachClient( this);
1395 for( aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait)
1397 delete mpAttributes;
1405 if( typeid(*rSourceSet.AttributeType())== typeid(*this->AttributeType())) {
1406 pHostSet=rSourceSet.pHostSet;
1407 pHostSet->AttachClient( this);
1408 pSet=rSourceSet.pSet;
1409 pAttributes=rSourceSet.pAttributes;
1413 mpSet = new std::set<T,Cmp>();
1414 *mpSet = *rSourceSet.pSet;
1416 mpAttributes = new std::map<T,AttributeVoid*>();
1417 if( typeid(*this->AttributeType()) != typeid( const AttributeVoid)) {
1418 for( aiterator ait=rSourceSet.pAttributes->begin(); ait!=rSourceSet.pAttributes->end(); ++ait) {
1420 (*mpAttributes)[ait->first]=attr;
1424 pAttributes = mpAttributes;
1426 mpClients= new std::list< TBaseSet<T,Cmp>* >;
1429 typename std::set< Iterator* >::iterator iit;
1430 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1431 (**iit).Invalidate();
1441#ifdef FAUDES_DEBUG_CODE
1442 DValid( "PostFakeCopyment");
1444 FD_DC( "TBaseSet(" << this << ")::DoCopy(rOtherSet " << &rSourceSet << "): fake copy -- done with attr# " << pAttributes->size());
1450 FD_DF( "TBaseSet(" << this << ")::DoMove(void): fallback to DoCopy()");
1456 FD_DC( "TBaseSet(" << this << ")::Detach(void)");
1457#ifdef FAUDES_DEBUG_CODE
1458 DValid( "PreDetach");
1463 if(flag==SetOnly) pAttributes->clear();
1468 THIS* fake_const = const_cast< THIS* >( this);
1470#ifdef FAUDES_DEBUG_CODE
1475 if(mpClients->empty()) {
1476 FD_ERR( "TBaseSet(" << this << ")::Detach(): missed detach (?)");
1478 fake_const->mDetached= true;
1483 std::set<T,Cmp>* scopy = new std::set<T,Cmp>();
1487 std::map<T,AttributeVoid*>* acopy = new std::map<T,AttributeVoid*>();
1488 if(flag==AttrIncl) {
1489 for( aiterator ait=pAttributes->begin(); ait!=pAttributes->end(); ++ait) {
1491 (*acopy)[ait->first]=attr;
1500 FD_DC( "TBaseSet(" << this << ")::Detach(): allocate and copy, strategie A");
1502 THIS* newhost = *mpClients->begin();
1503#ifdef FAUDES_DEBUG_CODE
1504 if(newhost->mpClients)
1505 FD_ERR( "TBaseSet(" << this << ")::Detach(): new host used to have clients (?)");
1507 newhost->pHostSet=newhost;
1508 newhost->mpSet=scopy;
1509 newhost->pSet=scopy;
1510 newhost->mpAttributes=acopy;
1511 newhost->pAttributes=acopy;
1512 newhost->mpClients=mpClients;
1513 newhost->DetachClient(newhost);
1514 fake_const->mpClients=NULL;
1516 typename std::list< THIS* >::const_iterator rit;
1517 for(rit=newhost->mpClients->begin();rit!=newhost->mpClients->end(); ++rit) {
1518 (*rit)->pHostSet=newhost;
1519 (*rit)->pSet=newhost->pSet;
1520 (*rit)->pAttributes=newhost->pAttributes;
1523 typename std::set< Iterator* >::iterator iit;
1524 for(rit=newhost->mpClients->begin(); rit!=newhost->mpClients->end(); ++rit) {
1525 for(iit=(*rit)->mIterators.begin(); iit!=(*rit)->mIterators.end(); ++iit) {
1526 if((**iit).StlIterator()==pSet->end())
1527 **iit= Iterator( this, scopy->end());
1529 **iit= Iterator( this, scopy->find(***iit));
1533 for(iit=newhost->mIterators.begin(); iit!=newhost->mIterators.end(); ++iit) {
1534 if((**iit).StlIterator()==pSet->end())
1535 **iit= Iterator( this, scopy->end());
1537 **iit= Iterator( this, scopy->find(***iit));
1540 fake_const->mpSet=pSet;
1541 fake_const->mpAttributes=pAttributes;
1542 fake_const->mpClients= new std::list< TBaseSet<T,Cmp>* >;
1543 fake_const->mDetached= true;
1545 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit)
1547 fake_const->mIterators.clear();
1555 FD_DC( "TBaseSet(" << this << ")::Detach(): allocate and copy, strategie B");
1557 fake_const->RelinkClients();
1558 pHostSet->DetachClient(fake_const);
1560 fake_const->mpSet = scopy;
1561 fake_const->mpAttributes=acopy;
1563 typename std::set< Iterator* >::iterator iit;
1564 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1565 if((**iit).StlIterator()==pSet->end())
1566 **iit= Iterator( this, mpSet->end());
1568 **iit= Iterator( this, mpSet->find(***iit));
1571 fake_const->pHostSet=fake_const;
1572 fake_const->pSet=mpSet;
1573 fake_const->pAttributes=mpAttributes;
1574 fake_const->mDetached= true;
1575 if(fake_const->mpClients) delete fake_const->mpClients;
1576 fake_const->mpClients= new std::list< TBaseSet<T,Cmp>* >;
1580#ifdef FAUDES_DEBUG_CODE
1581 DValid( "PostDetach");
1583 FD_DC( "TBaseSet(" << this << ")::Detach(): done");
1588 FD_DC( "TBaseSet(" << this << ")::Lock(void)");
1589#ifdef FAUDES_DEBUG_CODE
1599 THIS* fake_const = const_cast< THIS* >( this);
1602 typename std::set< Iterator* >::const_iterator iit;
1603 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1606 fake_const->mIterators.clear();
1609 fake_const->mLocked= true;
1611#ifdef FAUDES_DEBUG_CODE
1618TEMP inline void THIS::RelinkClients( void) {
1619 FD_DC( "TBaseSet::RelinkClients(" << this << ")")
1620#ifdef FAUDES_DEBUG_CODE
1621 DValid( "PreRelink");
1625 if(!mpClients) return;
1627 if(mpClients->empty()) return;
1629 FD_DC( "TBaseSet::RelinkClients(" << this << "): doit")
1632 THIS* newhost = *mpClients->begin();
1633#ifdef FAUDES_DEBUG_CODE
1634 if(newhost->pHostSet!= this)
1635 FD_ERR( "BaseSet::RelinkRefernces: old reference must have this as provider");
1636 if(newhost->mpClients)
1637 FD_ERR( "TBaseSet(" << this << ")::RelinkClients(void): client is a host (?)");
1639 newhost->pHostSet=newhost;
1640 newhost->mpSet=mpSet;
1642 newhost->mpAttributes=mpAttributes;
1643 newhost->pAttributes=pAttributes;
1644 newhost->mpClients=mpClients;
1645 newhost->DetachClient(newhost);
1648 typename std::list< THIS* >::const_iterator rit;
1649 for(rit=newhost->mpClients->begin();rit!=newhost->mpClients->end(); ++rit) {
1650 (*rit)->pHostSet=newhost;
1656 pAttributes=newhost->pAttributes;
1658 newhost->AttachClient( this);
1659#ifdef FAUDES_DEBUG_CODE
1660 DValid( "PostRelink");
1662 FD_DC( "TBaseSet::RelinkClients(" << this << "): done")
1669 const_cast< THIS* >( this)->mpClients->push_back(pRef);
1671 const_cast< THIS* >( this)->mDetached= false;
1676 FD_DC( "TBaseSet::DetachClient(" << this << "):" << pRef);
1678 if(!mpClients) return;
1679 if(mpClients->empty()) return;
1682 THIS* fake_const = const_cast< THIS* >( this);
1683#ifdef FAUDES_DEBUG_CODE
1685 typename std::list< TBaseSet<T,Cmp>* >::iterator cit;
1687 for(cit=fake_const->mpClients->begin(); cit!=fake_const->mpClients->end(); ++cit) {
1688 if(*cit==pRef) cf= true;
1691 FD_ERR( "TBaseSet::DetachClient(" << this << "): client not found " << pRef);
1704 typename std::list< TBaseSet<T,Cmp>* >::iterator rit;
1705 for(rit=fake_const->mpClients->begin(); rit!=fake_const->mpClients->end(); ++rit) {
1706 if(*rit!=pRef) continue;
1707 fake_const->mpClients->erase(rit);
1711 if(mpClients->empty() && (pSet!=pGes)) fake_const->mDetached= true;
1712 FD_DC( "TBaseSet::DetachClient(" << this << "): done.");
1719 FD_DC( "TBaseSet::AttachIterator(" << this << "):" << pFit)
1720 const_cast< THIS* >( this)->mIterators.insert(pFit);
1726 FD_DC( "TBaseSet::DetachIterator(" << this << "):" << pFit)
1727 const_cast< THIS* >( this)->mIterators.erase(pFit);
1731TEMP void THIS::DValid( const std::string& rMessage) const {
1732 typename std::set< Iterator* >::const_iterator iit;
1733 typename std::list< THIS* >::const_iterator rit;
1734#ifdef FAUDES_DEBUG_CONTAINER
1735 std::cerr << "TBaseSet(" << this << ")::DValid(): " << rMessage <<
1736 " host " << pHostSet << (pHostSet == this ? " +s+ " : " ") <<
1737 (pHostSet->pSet==pHostSet->pGes ? "+e+ " : "+f+ ") <<
1738 (mLocked ? "+l+ " : " ") << (mDetached ? "+d+" : " ")
1739 << " stl at " << pSet << " own data " << mpSet << " ges " << pGes;
1740 std::cerr << " -- refs ";
1741 if(pHostSet->mpClients)
1742 for(rit=pHostSet->mpClients->begin(); rit!=pHostSet->mpClients->end(); ++rit)
1743 std::cerr << *rit << " ";
1744 std::cerr << "-- its ";
1745 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit)
1746 std::cerr << *iit << " ";
1747 std::cerr << "-- attr at " << pAttributes;
1748 std::cerr << "(#" << pAttributes->size() << ") ";
1749 if(mpAttributes) std::cerr << "(" << mpAttributes->size() << ") ";
1750 else std::cerr << " ";
1751 std::cerr << (pAttributes==pGea ? "+e+ " : "+f+ ") << std::endl;
1754 if(pGes!=GlobalEmptySet()) {
1755 FD_WARN( "BaseSet("<< this << "," << rMessage << "): lost empty set: " << pGes);
1759 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1760 if((*iit)->pBaseSet!= this) {
1761 FD_WARN( "BaseSet("<< this << "," << rMessage << "): invalid iterator (baseset): "<< *iit);
1766 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1767 if(!(*iit)->mAttached) {
1768 FD_WARN( "BaseSet("<< this << "," << rMessage << "): invalid iterator (attached): "<< *iit);
1773 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1774 typename std::set<T,Cmp>::const_iterator vit;
1775 for(vit=pSet->begin(); vit!= pSet->end(); ++vit) {
1776 if(vit==(**iit).StlIterator()) break;
1778 if(vit!=(**iit).StlIterator()) {
1779 FD_WARN( "BaseSet("<< this << "," << rMessage << "): invalid iterator (stl) "<< *iit);
1780 (**iit).StlIterator(pSet->end());
1785 if(pHostSet==NULL) {
1786 FD_WARN( "BaseSet(" << this << "," << rMessage << "): no host found");
1790 if(pHostSet->pHostSet != pHostSet) {
1791 FD_WARN( "BaseSet(" << this << "," << rMessage << "): inconsistent host");
1795 if((mpSet!=NULL) && (pHostSet != this)) {
1796 FD_WARN( "BaseSet(" << this << "," << rMessage << "): double data");
1800 if(pHostSet!= this && mpClients!=NULL) {
1801 FD_WARN( "BaseSet(" << this << "," << rMessage << "): cannot be client and have clients oneself");
1805 if(pHostSet->mpClients==NULL) {
1806 FD_WARN( "BaseSet(" << this << "," << rMessage << "): refers to invalid host (a)");
1810 if(pHostSet!= this && pHostSet->mpClients->empty()) {
1811 FD_WARN( "BaseSet(" << this << "," << rMessage << "): refers to invalid host (b)");
1815 if((pHostSet == this) && (mpSet==NULL) && (pSet!=pGes)) {
1816 FD_WARN( "BaseSet(" << this << "," << rMessage << "): no data");
1820 if((pHostSet== this) && (pSet!=pGes) && (mpClients==NULL)) {
1821 FD_WARN( "BaseSet(" << this << "," << rMessage << "): host with no client list");
1825 if((pHostSet == this) && (pSet != mpSet) && (pSet!=pGes)) {
1826 FD_WARN( "BaseSet(" << this << "," << rMessage << "): data pointer mismatch A");
1830 if(pSet != pHostSet->pSet) {
1831 FD_WARN( "BaseSet(" << this << "," << rMessage << "): data pointer mismatch B");
1836 for(rit=pHostSet->mpClients->begin(); rit!=pHostSet->mpClients->end(); ++rit) {
1837 if((*rit)== this) hf= true;
1838 if((*rit)->pHostSet== pHostSet) continue;
1839 FD_WARN( "BaseSet(" << this << "," << rMessage << "): invalid client " << (*rit));
1842 if(!hf && (pHostSet!= this)) {
1843 FD_WARN( "BaseSet(" << this << "," << rMessage << "): client not registered with host");
1847 if(pHostSet!= this && *mClientRecord!= this) {
1848 FD_WARN( "BaseSet(" << this << "," << rMessage << "): refers to invalid host (c)");
1852 if(mDetached && mpClients==NULL) {
1853 FD_WARN( "BaseSet(" << this << "," << rMessage << "): invalid detached flag A");
1857 if(mDetached && !mpClients->empty()) {
1858 FD_WARN( "BaseSet(" << this << "," << rMessage << "): invalid detached flag B");
1862 if(mDetached && (pSet==pHostSet->pGes)) {
1863 FD_WARN( "BaseSet(" << this << "," << rMessage << "): detached empty set");
1867 if(mLocked && (mpClients==NULL)) {
1868 FD_WARN( "BaseSet(" << this << "," << rMessage << "): locked reference (a)");
1872 if(!pGes->empty()) {
1873 FD_WARN( "BaseSet(" << this << "," << rMessage << "): invalid empty set");
1877 if(!GlobalEmptyAttributes()->empty()) {
1878 FD_WARN( "BaseSet(" << this << "," << rMessage << "): invalid empty attributes");
1881#ifdef FAUDES_DEBUG_CONTAINER
1882 std::cerr << "TBaseSet(" << this << ")::DValid(): passed" << std::endl;
1888TEMP std::string THIS::Str( const T& rElem) const {
1890 std::string res= "E";
1895TEMP std::string THIS::Str( void) const {
1896 std::stringstream str;
1897 str << "[" << Name() << "]{ ";
1900 if(Size()>0) while( true) {
1901 str << Str(*(eit++));
1902 if(eit==eit_end) break;
1911 return ( Idx) pSet->size();
1916 return pSet->empty();
1920TEMP void THIS::DoWriteElement( TokenWriter& rTw, const T& rElem, const std::string& rLabel, const Type* pContext) const {
1924 ep-> Write(rTw,rLabel,pContext);
1928 std::stringstream errstr;
1929 errstr << "used but not reimplemented" << typeid( this).name() << std::endl;
1930 throw Exception( "BaseSet::DoWriteElement", errstr.str(), 61);
1934TEMP void THIS::DoXWriteElement( TokenWriter& rTw, const T& rElem, const std::string& rLabel, const Type* pContext) const {
1938 ep-> XWrite(rTw,rLabel,pContext);
1942 std::stringstream errstr;
1943 errstr << "used but not reimplemented" << typeid( this).name() << std::endl;
1944 throw Exception( "BaseSet::DoXWriteElement", errstr.str(), 61);
1948TEMP void THIS::DoDWriteElement( TokenWriter& rTw, const T& rElem, const std::string& rLabel, const Type* pContext) const {
1952 ep-> DWrite(rTw,rLabel,pContext);
1956 std::stringstream errstr;
1957 errstr << "used but not reimplemented" << typeid( this).name() << std::endl;
1958 throw Exception( "BaseSet::DoDWriteElement", errstr.str(), 61);
1963 std::string label=rLabel;
1964 if(label== "") label=Name();
1965 if(label== "") label= "BaseSet";
1966 std::string etstr=ElementTag();
1967 FD_DC( "TBaseSet(" << this << ")::DoWrite(..): section " << label << " #" << Size());
1971 for (it = Begin(); it != End(); ++it) {
1972 DoWriteElement(rTw, *it, etstr, pContext);
1981 Token btag=XBeginTag(rLabel, "BaseSet");
1983 FD_DC( "BaseSet(" << this << ")::DoXWrite(..): section " << btag. StringValue() << " #" << Size());
1985 std::string etstr=ElementTag();
1987 for (it = Begin(); it != End(); ++it) {
1988 DoXWriteElement(rTw, *it, etstr, pContext);
1995 std::string label=rLabel;
1996 if(label== "") label=Name();
1997 if(label== "") label= "BaseSet";
1998 std::string etstr=ElementTag();
1999 FD_DC( "TBaseSet(" << this << ")::DoDWrite(..): section " << label << " #" << Size());
2002 BASE::DoSWrite(rTw);
2004 if(pHostSet->mpClients) shares=pHostSet->mpClients->size();
2011#ifdef FAUDES_DEBUG_CODE
2016 for (it = Begin(); it != End(); ++it) {
2017 DoDWriteElement(rTw, *it, etstr, pContext);
2024 BASE::DoSWrite(rTw);
2026 if(pHostSet->mpClients) shares=pHostSet->mpClients->size();
2029 if(pAttributes->size()!=0)
2031 if(pAttributes->size()!=0) {
2043 ep-> Read(rTr,rLabel,pContext);
2047 std::stringstream errstr;
2048 errstr << "used but not reimplemented" << typeid( this).name() << std::endl;
2049 throw Exception( "BaseSet::DoReadElement", errstr.str(), 61);
2055 std::string label=rLabel;
2056 std::string ftype=TypeName();
2057 std::string etstr=ElementTag();
2059 std::string etype= "";
2069 if(label== "") label=ftype;
2075 FD_DC( "BaseSet(" << typeid(*this).name() << ")::DoRead(..): section " << label << " elements " << etstr);
2077 while(!rTr. Eos(label)) {
2081 FD_DC( "TBaseSet(" << typeid(*this).name() << ")::DoRead(..): inserting element");
2084 DoReadElement(rTr,elem,etstr,pContext);
2086 FD_DC( "TBaseSet(" << typeid(*this).name() << ")::DoRead(..): inserting element: ok");
2090 std::stringstream errstr;
2091 errstr << "Invalid token of type " << token. Type() << " at " << rTr. FileLine();
2092 throw Exception( "BaseSet::DoRead", errstr.str(), 50);
2095 FD_DC( "BaseSet(" << this << ")::DoRead(tr," << label << ", " << pContext << "): done");
2099TEMP typename THIS::Iterator THIS::ThisIterator( const typename std::set<T,Cmp>::const_iterator& sit) const {
2104TEMP inline typename THIS::Iterator THIS::Begin( void) const {
2105 return ThisIterator(pSet->begin());
2109TEMP inline typename THIS::Iterator THIS::End( void) const {
2110 return ThisIterator(pSet->end());
2116 FD_DC( "TBaseSet(" << this << ")::Clear()");
2117#ifdef FAUDES_DEBUG_CODE
2121 if(pSet==pHostSet->pGes) return;
2123 FD_DC( "TBaseSet(" << this << ")::Clear(): doit");
2124 FD_DC( "TBaseSet(" << this << ")::Clear(): type " << typeid(*this).name());
2126 if(mLocked) Detach(SetOnly);
2129 pHostSet->DetachClient( this);
2132 if(!mpClients) mpClients= new std::list< TBaseSet<T,Cmp>* >;
2141 for( aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait) {
2142 FD_DC( "TBaseSet(" << this << ")::Clear(): del attr " << ait->second);
2145 delete mpAttributes;
2150 pAttributes=GlobalEmptyAttributes();
2152 typename std::set< Iterator* >::iterator iit;
2153 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
2154 (**iit).Invalidate();
2159#ifdef FAUDES_DEBUG_CODE
2160 DValid( "PostClear");
2162 FD_DC( "TBaseSet(" << this << ")::Clear(): done");
2167TEMP bool THIS::IsDefault( void) const {
2168 return pSet->empty();
2172TEMP inline bool THIS::Valid( const T& rElem) const {
2178TEMP bool THIS::Insert( const T& rElem) {
2179#ifdef FAUDES_CHECKED
2181 std::stringstream errstr;
2182 errstr << "refuse to insert invalid element" << std::endl;
2183 throw Exception( "BaseSet::Insert", errstr.str(), 61);
2186 if(!mDetached) Detach();
2187 return pSet->insert(rElem).second;
2191TEMP typename THIS::Iterator THIS::Inject( const Iterator& pos, const T& rElem) {
2192 if(!mDetached) Detach();
2194 return ThisIterator(pSet->insert(dst,rElem));
2199TEMP void THIS::Inject( const T& rElem) {
2200 if(!mDetached) Detach();
2201 pSet->insert(pSet->end(),rElem);
2206 FD_DC( "TBaseSet(" << this << ")::InsertSet(" << &rOtherSet << ")");
2207 if(!mDetached) Detach();
2216 while ((it1 != pSet->end()) && (it2 != rOtherSet. pSet->end())) {
2220 else if (*it1 == *it2) {
2229 while (it2 != rOtherSet. pSet->end()) {
2237TEMP bool THIS::Erase( const T& rElem) {
2238 if(!mDetached) Detach();
2239 return (pSet->erase(rElem)!=0);
2245#ifdef FAUDES_CHECKED
2247 std::stringstream errstr;
2248 errstr << "iterator out of range " << std::endl;
2249 throw Exception( "BaseSet::Erase", errstr.str(), 62);
2255 return ThisIterator(del);
2261 FD_DC( "TBaseSet(" << this << ")::EraseSet(" << &rOtherSet << ")");
2262 if(!mDetached) Detach();
2266 while ((it != pSet->end()) && (oit != rOtherSet. pSet->end())) {
2268 it=pSet->lower_bound(*oit);
2270 else if (*it == *oit) {
2275 oit=rOtherSet. pSet->lower_bound(*it);
2283 FD_DC( "TBaseSet(" << this << ")::RestrictSet(" << &rOtherSet << ")");
2284 if(!mDetached) Detach();
2288 while ((it != pSet->end()) && (oit != rOtherSet. pSet->end())) {
2292 else if (*it == *oit) {
2297 oit=rOtherSet. pSet->lower_bound(*it);
2300 while(it != pSet->end()) {
2308 FD_DC( "TBaseSet(" << this << ")::Disjoint(" << &rOtherSet << ")");
2310 if(pSet->empty()) return true;
2311 if(rOtherSet. pSet->empty()) return true;
2312 if(*pSet->rbegin()<*rOtherSet. pSet->begin()) return true;
2313 if(*rOtherSet. pSet->rbegin()<*pSet->begin()) return true;
2314 if(rOtherSet. pSet==pSet) return false;
2318 while ((it != pSet->end()) && (oit != rOtherSet. pSet->end())) {
2319 if (*it < *oit) { it++; continue;}
2320 if (*it == *oit) { return false; }
2328TEMP typename THIS::Iterator THIS::Find( const T& rElem) const {
2329 return ThisIterator(pSet->find(rElem));
2333TEMP bool THIS::Exists( const T& rElem) const {
2334 return pSet->find(rElem) != pSet->end();
2363 FD_DC( "TBaseSet::DoEqual()");
2365 if(pSet == rOtherSet. pSet) return true;
2367 return ( *pSet == *rOtherSet. pSet );
2372 FD_DC( "BaseSet::op<=()");
2373 return ( std::includes(rOtherSet. pSet->begin(), rOtherSet. pSet->end(), pSet->begin(), pSet->end()) ) ;
2378 FD_DC( "BaseSet::op>=()");
2379 return ( std::includes(pSet->begin(), pSet->end(), rOtherSet. pSet->begin(), rOtherSet. pSet->end()) );
2384 return *pSet < *rOtherSet. pSet;
2395TEMP bool THIS::AttributeTest( const Type& rAttr) const {
2396 return AttributeType()-> Cast(&rAttr)!=NULL;
2401 return ( Idx) pAttributes->size();
2405TEMP void THIS::ClearAttributes( void) {
2407 if(this->pAttributes->size()==0) return;
2409 this->Detach(SetOnly);
2415 FD_DC( "TBaseSet::EqualAttributes(TBaseSet)");
2417 FD_DC( "TBaseSet::EqualAttributes(TBaseSet): 1");
2418 if( typeid(*rOtherSet. AttributeType())!= typeid(*this->AttributeType()))
2421 FD_DC( "TBaseSet::EqualAttributes(TBaseSet): 2");
2425 FD_DC( "TBaseSet::EqualAttributes(TBaseSet): 3");
2427 if(this->AttributesSize()==0)
2432 while ((ait1 != pAttributes->end()) && (ait2 != rOtherSet. pAttributes->end())) {
2433 if (ait1->first < ait2->first) {
2436 else if (ait1->first == ait2->first) {
2437 FD_DC( "TBaseSet::EqualAttributes(TBaseSet): cmp " << ait1->second->ToString()
2438 << " vs " << ait2->second->ToString());
2439 if( ! ait1->second->Equal(*ait2->second)) return false;
2448 FD_DC( "TBaseSet::EqualAttributes(TBaseSet): pass");
2457 this->DoCopy(rSourceSet);
2459 this->Detach(SetOnly);
2465 FD_DC( "TBaseSet::Attributes("<< this<< ")");
2468 std::stringstream errstr;
2469 errstr << "cannot cast attribute " << std::endl;
2470 throw Exception( "TBaseSet::Attributes(otherset)", errstr.str(), 63);
2473 if( typeid(*this->AttributeType())== typeid( const AttributeVoid)) return;
2475 this->Detach(AttrIncl);
2478 while ((it1 != pSet->end()) && (it2 != rOtherSet. pSet->end())) {
2482 else if (*it1 == *it2) {
2483 DoAttribute(*it1,&rOtherSet. Attribute(*it2));
2491 FD_DC( "TBaseSet::Attributes(): copy ok");
2499 std::stringstream errstr;
2500 errstr << "cannot get attribute for TBaseSet \"" << mObjectName << "\" type " << typeid(*this).name();
2501 throw Exception( "TBaseSet::Attributep(rElem)", errstr.str(), 63);
2515TEMP void THIS::Attribute( const T& rElem, const Type& rAttr) {
2518#ifdef FAUDES_CHECKED
2519 if (!Exists(rElem)) {
2520 std::stringstream errstr;
2521 errstr << "element not member of set" << std::endl;
2522 throw Exception( "TBaseSet::Attribute(elem,attr)", errstr.str(), 60);
2525 if(!AttributeTest(rAttr)) {
2526 std::stringstream errstr;
2527 errstr << "cannot cast attribute " << std::endl;
2528 throw Exception( "TBaseSet::Attribute(elem,attr)", errstr.str(), 63);
2535TEMP void THIS::ClrAttribute( const T& rElem) {
2544 ait=this->pAttributes->find(rElem);
2545 if(ait==this->pAttributes->end()) return NULL;
2551 FD_DC( "TBaseSet::DoAttributeExplicit(elem)");
2552#ifdef FAUDES_DEBUG_CODE
2553 if(this->pAttributes!=this->mpAttributes) {
2554 FD_ERR( "TBaseSet::DoAttributeExplicit(elem): attributes not detached");
2559 ait=this->pAttributes->find(rElem);
2560 if(ait!=this->pAttributes->end())
2564 FD_DC( "TBaseSet::DoAttributeExplicit(Elem): inserting explicit default " << attr << " type " << typeid(*attr).name());
2565 (*this->pAttributes)[rElem]=attr;
2570TEMP void THIS::DoAttribute( const T& rElem, const Type* pAttr) {
2571 FD_DC( "TBaseSet::DoAttribute([v] " << this->EStr(rElem) << ", ...)");
2572#ifdef FAUDES_DEBUG_CODE
2573 if(this->pAttributes!=this->mpAttributes) {
2574 FD_ERR( "TBaseSet::DoAttribute([v] set): attributes not detached");
2580 if(!this->AttributeType()->Cast(pAttr)) newattr=NULL;
2584 ait=this->pAttributes->find(rElem);
2585 if(ait!=this->pAttributes->end() )
2586 oldattr=ait->second;
2589 FD_DC( "TBaseSet::DoAttribute([v] " << this->EStr(rElem) << ", ...): default 1");
2590 if(oldattr==NULL) return;
2592 this->pAttributes->erase(ait);
2597 FD_DC( "TBaseSet::DoAttribute([v] " << this->EStr(rElem) << ", ...): default 2");
2598 if(oldattr==NULL) return;
2600 this->pAttributes->erase(ait);
2603 FD_DC( "TBaseSet::DoAttribute([v] " << this->EStr(rElem) << ", ...): " << newattr-> ToString());
2607 attr-> Copy(*newattr);
2608 (*this->pAttributes)[rElem]=attr;
2612 FD_DC( "TBaseSet::DoAttribute([v] " << this->EStr(rElem) << ", ...): " << newattr-> ToString());
2613 oldattr-> Copy(*newattr);
2617TEMP void THIS::FromStl( const std::set<T,Cmp>& rStlSet) {
2619 typename std::set<T,Cmp>::const_iterator it;
2621 while(it!=rStlSet.end())
2626TEMP 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
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()
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
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 & FaudesTypeName(const Type &rObject)
std::string ToStringInteger(Int number)
std::string CollapsString(const std::string &rString, unsigned int len)
libFAUDES 2.34e
--- 2026.03.16
--- c++ api documentaion by doxygen
|