25 #ifndef FAUDES_BASESET_H
26 #define FAUDES_BASESET_H
48 template<
class T,
class Attr,
class Cmp>
class TAttrMap;
97 template<
class T,
class Cmp=std::less<T> >
104 using Type::operator=;
105 using Type::operator==;
106 using Type::operator!=;
109 template<
class TP,
class AP,
class CP>
friend class TAttrMap;
135 TBaseSet(
const std::string& rFilename,
const std::string& rLabel =
"BaseSet");
148 const std::string&
Name(
void)
const;
156 void Name(
const std::string& rName);
190 virtual std::string
Str(
const T& rElem)
const;
225 virtual bool Valid(
const T& rElem)
const;
247 virtual Iterator
Erase(
const Iterator& pos);
295 virtual Iterator
Inject(
const Iterator& pos,
const T& rElem);
336 Iterator
Find(
const T& rElem)
const;
373 void DValid(
const std::string& rMessage=
"")
const;
408 const typename std::set<T,Cmp>::const_iterator& sit,
414 if(pBaseSet && att) {
423 pBaseSet(fit.pBaseSet),
427 pBaseSet->AttachIterator(
this);
434 if(mAttached) pBaseSet->DetachIterator(
this);
439 std::stringstream rstr;
440 rstr <<
"[dit base " << pBaseSet <<
" a" << mAttached <<
" data " << pBaseSet->pSet;
441 if(pBaseSet) rstr <<
" elem " << pBaseSet->Str(**
this);
448 #ifdef FAUDES_DEBUG_CODE
450 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator= invalid iterator: no baseset");
455 if(mAttached)
if(pBaseSet==rSrc.
pBaseSet) {
456 std::set<T,Cmp>::const_iterator::operator= (rSrc);
460 if(mAttached) pBaseSet->DetachIterator(
this);
461 std::set<T,Cmp>::const_iterator::operator= (rSrc);
473 void StlIterator(
const typename std::set<T,Cmp>::const_iterator& sit) {
474 std::set<T,Cmp>::const_iterator::operator= (sit);
478 const typename std::set<T,Cmp>::const_iterator&
StlIterator(
void)
const {
497 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):DValid(): invalid iterator: no baseset");
500 pBaseSet->DValid(
"Iterator");
504 const T* operator-> (
void)
const {
505 #ifdef FAUDES_DEBUG_CODE
507 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator->: invalid iterator: no baseset");
511 return std::set<T,Cmp>::const_iterator::operator-> ();
515 const T& operator* (
void)
const {
516 #ifdef FAUDES_DEBUG_CODE
518 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator*: invalid iterator: no baseset");
522 return std::set<T,Cmp>::const_iterator::operator* ();
527 #ifdef FAUDES_DEBUG_CODE
529 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator==: invalid iterator: no baseset");
533 return *
static_cast< const typename std::set<T,Cmp>::const_iterator *
>(
this) == rOther;
538 #ifdef FAUDES_DEBUG_CODE
540 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator!=: invalid iterator: no baseset");
544 return *
static_cast< const typename std::set<T,Cmp>::const_iterator *
>(
this) != rOther;
549 #ifdef FAUDES_DEBUG_CODE
551 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator++: invalid iterator: no baseset");
556 std::set<T,Cmp>::const_iterator::operator++ (step);
562 #ifdef FAUDES_DEBUG_CODE
564 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator++: invalid iterator: no baseset");
568 std::set<T,Cmp>::const_iterator::operator++ ();
574 #ifdef FAUDES_DEBUG_CODE
576 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator--: invalid iterator: no baseset");
580 Iterator old(pBaseSet, *
this,
true);
581 std::set<T,Cmp>::const_iterator::operator-- (step);
587 #ifdef FAUDES_DEBUG_CODE
589 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator--: invalid iterator: no baseset");
593 std::set<T,Cmp>::const_iterator::operator-- ();
612 #ifdef DONT_TRACK_REFERENCES
623 std::set<T,Cmp>::const_iterator()
627 Iterator(
const Iterator& fit) :
628 std::set<T,Cmp>::const_iterator(fit)
632 Iterator(
const typename std::set<T,Cmp>::const_iterator& sit) :
633 std::set<T,Cmp>::const_iterator(sit)
638 const TBaseSet<T,Cmp>* pBaseSet,
639 const typename std::set<T,Cmp>::const_iterator& sit) :
640 std::set<T,Cmp>::const_iterator(sit)
644 void StlIterator(
const typename std::set<T,Cmp>::const_iterator& sit) {
645 std::set<T,Cmp>::const_iterator::operator= (sit);
649 const typename std::set<T,Cmp>::const_iterator& StlIterator(
void)
const {
654 void Invalidate(
void) {};
787 virtual void AttributeTry(
const T& rElem,
const Type& rAttr) { (void) rElem; (void) rAttr; };
925 typedef typename std::set<T,Cmp>::iterator
iterator;
942 typedef typename std::map<T,AttributeVoid*>::iterator
aiterator;
1032 template<
class T,
class Cmp>
1034 FD_DC(
"FAUDES_DEBUG_CONTAINER: SetUnion(TBaseSet<T,Cmp>): res at " << &rRes);
1038 if(&rSetA==&rSetB && &rSetA==&rRes) {rRes.
Name(name);
return;}
1040 if(&rSetA==&rSetB) {rRes.
Assign(rSetA); rRes.
Name(name);
return;}
1042 if(&rSetA==&rRes) {rRes.
InsertSet(rSetB); rRes.
Name(name);
return;};
1044 if(&rSetB==&rRes) {rRes.
InsertSet(rSetA); rRes.
Name(name);
return;};
1049 FD_DC(
"FAUDES_DEBUG_CONTAINER: SetUnion(TBaseSet<T,Cmp>): done, res at " << &rRes <<
" #" << rRes.
Size());
1062 template<
class T,
class Cmp >
1067 if(&rSetA==&rSetB && &rSetA==&rRes) {rRes.
Name(name);
return;}
1069 if(&rSetA==&rSetB) { rRes.
Assign(rSetA); rRes.
Name(name);
return;}
1071 if(&rSetA==&rRes) {rRes.
RestrictSet(rSetB); rRes.
Name(name);
return;};
1073 if(&rSetB==&rRes) {rRes.
RestrictSet(rSetA); rRes.
Name(name);
return;};
1091 template<
class T,
class Cmp >
1096 if(&rSetA==&rSetB) { rRes.
Clear(); rRes.
Name(name);
return;}
1098 if(&rSetA==&rRes) {rRes.
EraseSet(rSetB); rRes.
Name(name);
return;};
1125 template<
class T,
class Cmp >
1127 return rSetA==rSetB;
1141 template<
class T,
class Cmp >
1143 return rSetA<=rSetB;
1165 #define THIS TBaseSet<T,Cmp>
1166 #define TEMP template<class T, class Cmp>
1185 TEMP std::set<T,Cmp> THIS::msEmptySet=std::set<T,Cmp>();
1186 TEMP std::map<T,AttributeVoid*> THIS::msEmptyAttributes=std::map<T,AttributeVoid*>();
1193 pAttributes(&msEmptyAttributes),
1196 mpClients(new std::list<
TBaseSet<T,Cmp>* >),
1199 pTypeDefinition(NULL),
1200 mXElementTagDef(
"Element")
1203 FD_DC(
"TBaseSet(" <<
this <<
")::TBaseSet()");
1209 TEMP THIS::TBaseSet(
const std::string& rFileName,
const std::string& rLabel) :
1213 pAttributes(&msEmptyAttributes),
1216 mpClients(new std::list<
TBaseSet<T,Cmp>* >),
1219 pTypeDefinition(NULL),
1220 mXElementTagDef(
"Element")
1223 FD_DC(
"TBaseSet(" <<
this <<
")::TBaseSet()");
1227 Read(rFileName,rLabel);
1235 pAttributes(&msEmptyAttributes),
1238 mpClients(new std::list<
TBaseSet<T,Cmp>* >),
1241 pTypeDefinition(NULL),
1242 mXElementTagDef(
"Element")
1245 FD_DC(
"TBaseSet(" <<
this <<
")::TBaseSet(rOtherSet " << &rOtherSet <<
"): fake copy construct");
1248 #ifdef FAUDES_DEBUG_CODE
1256 FD_DC(
"TBaseSet(" <<
this <<
")::~TBaseSet()");
1259 pHostSet->DetachClient(
this);
1260 if(mpClients)
delete mpClients;
1263 typename std::set< Iterator* >::const_iterator iit;
1264 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1265 (**iit).Invalidate();
1268 if(mpSet)
delete mpSet;
1270 for(
aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait)
1272 delete mpAttributes;
1279 FD_DC(
"TBaseSet(" <<
this <<
"/" << this->Name() <<
")::DoAssign(rOtherSet " << &rSourceSet <<
"): shallow copy -- src attr# " << rSourceSet.pAttributes->size());
1280 FD_DC(
"TBaseSet():DoAssign(): " <<
typeid(*this->AttributeType()).name() <<
" <== " <<
typeid(*rSourceSet.AttributeType()).name());
1282 if(
this==&rSourceSet)
return;
1284 mMyName=rSourceSet.mMyName;
1286 if(pHostSet==rSourceSet.pHostSet)
return;
1289 pHostSet->DetachClient(
this);
1296 for(
aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait)
1298 delete mpAttributes;
1307 if(
typeid(*rSourceSet.AttributeType())==
typeid(*this->AttributeType())) {
1308 pHostSet=rSourceSet.pHostSet;
1309 pHostSet->AttachClient(
this);
1310 pSet=rSourceSet.pSet;
1311 pAttributes=rSourceSet.pAttributes;
1315 mpSet =
new std::set<T,Cmp>();
1316 *mpSet = *rSourceSet.pSet;
1318 mpAttributes =
new std::map<T,AttributeVoid*>();
1319 if(
typeid(*this->AttributeType()) !=
typeid(
const AttributeVoid)) {
1320 for(
aiterator ait=rSourceSet.pAttributes->begin(); ait!=rSourceSet.pAttributes->end(); ++ait) {
1322 (*mpAttributes)[ait->first]=attr;
1325 pAttributes = mpAttributes;
1329 typename std::set< Iterator* >::iterator iit;
1330 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1331 (**iit).Invalidate();
1341 #ifdef FAUDES_DEBUG_CODE
1342 DValid(
"PostFakeAssignment");
1344 FD_DC(
"TBaseSet(" <<
this <<
")::DoAssign(rOtherSet " << &rSourceSet <<
"): fake copy -- done with attr# " << pAttributes->size());
1349 FD_DC(
"TBaseSet(" <<
this <<
")::Detach(void)");
1350 #ifdef FAUDES_DEBUG_CODE
1351 DValid(
"PreDetach");
1356 if(flag==SetOnly) pAttributes->clear();
1361 THIS* fake_const =
const_cast< THIS*
>(
this);
1363 #ifdef FAUDES_DEBUG_CODE
1366 if(pSet!=&msEmptySet)
1368 if(mpClients->empty()) {
1369 FD_ERR(
"TBaseSet(" <<
this <<
")::Detach(): missed detach (?)");
1371 fake_const->mDetached=
true;
1376 std::set<T,Cmp>* scopy =
new std::set<T,Cmp>();
1380 std::map<T,AttributeVoid*>* acopy =
new std::map<T,AttributeVoid*>();
1381 if(flag==AttrIncl) {
1382 for(
aiterator ait=pAttributes->begin(); ait!=pAttributes->end(); ++ait) {
1384 (*acopy)[ait->first]=attr;
1393 FD_DC(
"TBaseSet(" <<
this <<
")::Detach(): allocate and copy, strategie A");
1395 THIS* newhost = *mpClients->begin();
1396 #ifdef FAUDES_DEBUG_CODE
1397 if(newhost->mpClients)
1398 FD_ERR(
"TBaseSet(" <<
this <<
")::Detach(): new host used to heve clients (?)");
1400 newhost->pHostSet=newhost;
1401 newhost->mpSet=scopy;
1402 newhost->pSet=scopy;
1403 newhost->mpAttributes=acopy;
1404 newhost->pAttributes=acopy;
1405 newhost->mpClients=mpClients;
1406 newhost->DetachClient(newhost);
1408 typename std::list< THIS* >::const_iterator rit;
1409 for(rit=newhost->mpClients->begin();rit!=newhost->mpClients->end(); ++rit) {
1410 (*rit)->pHostSet=newhost;
1411 (*rit)->pSet=newhost->pSet;
1412 (*rit)->pAttributes=newhost->pAttributes;
1415 typename std::set< Iterator* >::iterator iit;
1416 for(rit=newhost->mpClients->begin(); rit!=newhost->mpClients->end(); ++rit) {
1417 for(iit=(*rit)->mIterators.begin(); iit!=(*rit)->mIterators.end(); ++iit) {
1418 if((**iit).StlIterator()==pSet->end())
1419 **iit=
Iterator(
this, scopy->end());
1421 **iit=
Iterator(
this, scopy->find(***iit));
1425 for(iit=newhost->mIterators.begin(); iit!=newhost->mIterators.end(); ++iit) {
1426 if((**iit).StlIterator()==pSet->end())
1427 **iit=
Iterator(
this, scopy->end());
1429 **iit=
Iterator(
this, scopy->find(***iit));
1432 fake_const->mpSet=pSet;
1433 fake_const->mpAttributes=pAttributes;
1434 fake_const->mpClients=
new std::list< TBaseSet<T,Cmp>* >;
1435 fake_const->mDetached=
true;
1437 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit)
1439 fake_const->mIterators.clear();
1447 FD_DC(
"TBaseSet(" <<
this <<
")::Detach(): allocate and copy, strategie B");
1449 fake_const->RelinkClients();
1450 pHostSet->DetachClient(fake_const);
1452 fake_const->mpSet = scopy;
1453 fake_const->mpAttributes=acopy;
1455 typename std::set< Iterator* >::iterator iit;
1456 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1457 if((**iit).StlIterator()==pSet->end())
1458 **iit=
Iterator(
this, mpSet->end());
1460 **iit=
Iterator(
this, mpSet->find(***iit));
1463 fake_const->pHostSet=fake_const;
1464 fake_const->pSet=mpSet;
1465 fake_const->pAttributes=mpAttributes;
1466 fake_const->mDetached=
true;
1467 if(fake_const->mpClients)
delete fake_const->mpClients;
1468 fake_const->mpClients=
new std::list< TBaseSet<T,Cmp>* >;
1472 #ifdef FAUDES_DEBUG_CODE
1473 DValid(
"PostDetach");
1475 FD_DC(
"TBaseSet(" <<
this <<
")::Detach(): done");
1480 FD_DC(
"TBaseSet(" <<
this <<
")::Lock(void)");
1481 #ifdef FAUDES_DEBUG_CODE
1491 THIS* fake_const =
const_cast< THIS*
>(
this);
1494 typename std::set< Iterator* >::const_iterator iit;
1495 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1498 fake_const->mIterators.clear();
1501 fake_const->mLocked=
true;
1503 #ifdef FAUDES_DEBUG_CODE
1510 TEMP inline void THIS::RelinkClients(
void) {
1511 FD_DC(
"TBaseSet::RelinkClients(" <<
this <<
")")
1512 #ifdef FAUDES_DEBUG_CODE
1513 DValid(
"PreRelink");
1517 if(!mpClients)
return;
1519 if(mpClients->empty())
return;
1521 FD_DC(
"TBaseSet::RelinkClients(" <<
this <<
"): doit")
1524 THIS* newhost = *mpClients->begin();
1525 #ifdef FAUDES_DEBUG_CODE
1526 if(newhost->pHostSet!=
this)
1527 FD_ERR(
"BaseSet::RelinkRefernces: old reference must have this as provider");
1528 if(newhost->mpClients)
1529 FD_ERR(
"TBaseSet(" <<
this <<
")::RelinkClients(void): client is a host (?)");
1531 newhost->pHostSet=newhost;
1532 newhost->mpSet=mpSet;
1534 newhost->mpAttributes=mpAttributes;
1535 newhost->pAttributes=pAttributes;
1536 newhost->mpClients=mpClients;
1537 newhost->DetachClient(newhost);
1539 typename std::list< THIS* >::const_iterator rit;
1540 for(rit=newhost->mpClients->begin();rit!=newhost->mpClients->end(); ++rit) {
1541 (*rit)->pHostSet=newhost;
1547 pAttributes=newhost->pAttributes;
1549 newhost->AttachClient(
this);
1551 #ifdef FAUDES_DEBUG_CODE
1552 DValid(
"PostRelink");
1554 FD_DC(
"TBaseSet::RelinkClients(" <<
this <<
"): done")
1561 const_cast< THIS*
>(
this)->mpClients->push_back(pRef);
1563 const_cast< THIS*
>(
this)->mDetached=
false;
1568 FD_DC(
"TBaseSet::DetachClient(" <<
this <<
"):" << pRef);
1570 if(!mpClients)
return;
1571 if(mpClients->empty())
return;
1574 THIS* fake_const =
const_cast< THIS*
>(
this);
1575 #ifdef FAUDES_DEBUG_CODE
1577 typename std::list< TBaseSet<T,Cmp>* >
::iterator cit;
1579 for(cit=fake_const->mpClients->begin(); cit!=fake_const->mpClients->end(); ++cit) {
1580 if(*cit==pRef) cf=
true;
1583 FD_ERR(
"TBaseSet::DetachClient(" <<
this <<
"): client not found " << pRef);
1596 typename std::list< TBaseSet<T,Cmp>* >
::iterator rit;
1597 for(rit=fake_const->mpClients->begin(); rit!=fake_const->mpClients->end(); ++rit) {
1598 if(*rit!=pRef)
continue;
1599 fake_const->mpClients->erase(rit);
1603 if(mpClients->empty() && (pSet!=&msEmptySet)) fake_const->mDetached=
true;
1604 FD_DC(
"TBaseSet::DetachClient(" <<
this <<
"): done.");
1611 FD_DC(
"TBaseSet::AttachIterator(" <<
this <<
"):" << pFit)
1612 const_cast< THIS*
>(
this)->mIterators.insert(pFit);
1618 FD_DC(
"TBaseSet::DetachIterator(" <<
this <<
"):" << pFit)
1619 const_cast< THIS*
>(
this)->mIterators.erase(pFit);
1623 TEMP void THIS::DValid(
const std::string& rMessage)
const {
1624 typename std::set< Iterator* >::const_iterator iit;
1625 typename std::list< THIS* >::const_iterator rit;
1626 #ifdef FAUDES_DEBUG_CONTAINER
1627 std::cerr <<
"TBaseSet(" <<
this <<
")::DValid(): " << rMessage <<
" source "
1628 << pHostSet <<
" " << (pHostSet->pSet==&msEmptySet ?
"+e+" :
"+f+") <<
1629 (mLocked ?
" +l+" :
" ") << (mDetached ?
" +d+" :
" ") <<
" -- refs ";
1630 if(pHostSet->mpClients)
1631 for(rit=pHostSet->mpClients->begin(); rit!=pHostSet->mpClients->end(); ++rit)
1632 std::cerr << *rit <<
" ";
1633 std::cerr <<
"-- its ";
1634 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit)
1635 std::cerr << *iit <<
" ";
1636 std::cerr <<
"-- attr #" << pAttributes->size();
1637 if(mpAttributes) std::cerr <<
"(" << mpAttributes->size() <<
") ";
1638 else std::cerr <<
" ";
1639 std::cerr << (pAttributes==&msEmptyAttributes ?
"+e+ " :
"+f+ ") << std::endl;
1642 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1643 if((*iit)->pBaseSet!=
this) {
1644 FD_WARN(
"BaseSet("<<
this <<
"," << rMessage <<
"): invalid iterator (baseset): "<< *iit);
1649 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1650 if(!(*iit)->mAttached) {
1651 FD_WARN(
"BaseSet("<<
this <<
"," << rMessage <<
"): invalid iterator (attached): "<< *iit);
1656 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1657 typename std::set<T,Cmp>::const_iterator vit;
1658 for(vit=pSet->begin(); vit!= pSet->end(); ++vit) {
1659 if(vit==(**iit).StlIterator())
break;
1661 if(vit!=(**iit).StlIterator()) {
1662 FD_WARN(
"BaseSet("<<
this <<
"," << rMessage <<
"): invalid iterator (stl) "<< *iit);
1663 (**iit).StlIterator(pSet->end());
1668 if(pHostSet==NULL) {
1669 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): no host found");
1673 if(pHostSet->pHostSet != pHostSet) {
1674 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): inconsistent host");
1678 if((mpSet!=NULL) && (pHostSet !=
this)) {
1679 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): double data");
1683 if(pHostSet!=
this && mpClients!=NULL) {
1684 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): cannot be client and have clients oneself");
1688 if(pHostSet->mpClients==NULL) {
1689 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): refers to invalid host (a)");
1693 if(pHostSet!=
this && pHostSet->mpClients->empty()) {
1694 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): refers to invalid host (b)");
1698 if((pHostSet ==
this) && (mpSet==NULL) && (pSet!=&msEmptySet)) {
1699 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): no data");
1703 if((pHostSet==
this) && (pSet!=&msEmptySet) && (mpClients==NULL)) {
1704 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): host with no client list");
1708 if((pHostSet ==
this) && (pSet != mpSet) && (pSet!=&msEmptySet)) {
1709 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): data pointer mismatch A");
1713 if(pSet != pHostSet->pSet) {
1714 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): data pointer mismatch B");
1719 for(rit=pHostSet->mpClients->begin(); rit!=pHostSet->mpClients->end(); ++rit) {
1720 if((*rit)==
this) hf=
true;
1721 if((*rit)->pHostSet== pHostSet)
continue;
1722 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): invalid client " << (*rit));
1725 if(!hf && (pHostSet!=
this)) {
1726 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): client not registered with host");
1730 if(pHostSet!=
this && *mClientRecord!=
this) {
1731 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): refers to invalid host (c)");
1735 if(mDetached && mpClients==NULL) {
1736 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): invalid detached flag A");
1740 if(mDetached && !mpClients->empty()) {
1741 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): invalid detached flag B");
1745 if(mDetached && (pSet==&msEmptySet)) {
1746 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): detached empty set");
1750 if(mLocked && (mpClients==NULL)) {
1751 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): locked reference (a)");
1755 if(!msEmptySet.empty()) {
1756 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): invalid empty set");
1760 if(!msEmptyAttributes.empty()) {
1761 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): invalid empty attributes");
1764 #ifdef FAUDES_DEBUG_CONTAINER
1765 std::cerr <<
"TBaseSet(" <<
this <<
")::DValid(): passed" << std::endl;
1772 TEMP const std::string& THIS::Name(
void)
const {
1777 TEMP void THIS::Name(
const std::string& rName) {
1785 if(!pTypeDefinition) {
1787 THIS* fake_const =
const_cast< THIS*
>(
this);
1790 return pTypeDefinition;
1794 TEMP const std::string& THIS::XElementTag(
void)
const {
1795 if(mXElementTag.empty()) {
1797 THIS* fake_const =
const_cast< THIS*
>(
this);
1798 fake_const->mXElementTag=mXElementTagDef;
1802 return mXElementTag;
1806 TEMP void THIS::XElementTag(
const std::string& rTag) {
1812 TEMP const std::string& THIS::TypeName(
void)
const {
1813 if(mFaudesTypeName.empty()) {
1815 THIS* fake_const =
const_cast< THIS*
>(
this);
1817 if(fdp) fake_const->mFaudesTypeName=fdp->
Name();
1819 return mFaudesTypeName;
1823 TEMP void THIS::TypeName(
const std::string& rType) {
1824 mFaudesTypeName=rType;
1829 TEMP std::string THIS::Str(
const T& rElem)
const {
1837 return (
Idx) pSet->size();
1841 TEMP bool THIS::Empty(
void)
const {
1842 return pSet->empty();
1849 std::string label=rLabel;
1850 if(label==
"") label=Name();
1851 if(label==
"") label=
"BaseSet";
1852 FD_DC(
"TBaseSet(" <<
this <<
")::DoWrite(..): section " << label <<
" #" << Size());
1862 BASE::DoSWrite(rTw);
1864 if(pHostSet->mpClients) shares=pHostSet->mpClients->size();
1871 #ifdef FAUDES_DEBUG_CODE
1878 BASE::DoSWrite(rTw);
1880 if(pHostSet->mpClients) shares=pHostSet->mpClients->size();
1883 if(pAttributes->size()!=0)
1885 if(pAttributes->size()!=0) {
1894 std::string label=rLabel;
1895 if(label==
"") label=Name();
1896 if(label==
"") label=
"BaseSet";
1903 TEMP typename THIS::Iterator THIS::ThisIterator(
const typename std::set<T,Cmp>::const_iterator& sit)
const {
1908 TEMP inline typename THIS::Iterator THIS::Begin(
void)
const {
1909 return ThisIterator(pSet->begin());
1913 TEMP inline typename THIS::Iterator THIS::End(
void)
const {
1914 return ThisIterator(pSet->end());
1920 FD_DC(
"TBaseSet(" <<
this <<
")::Clear()");
1921 #ifdef FAUDES_DEBUG_CODE
1925 if(pSet==&msEmptySet)
return;
1927 FD_DC(
"TBaseSet(" <<
this <<
")::Clear(): doit");
1928 FD_DC(
"TBaseSet(" <<
this <<
")::Clear(): type " <<
typeid(*this).name());
1930 if(mLocked) Detach(SetOnly);
1933 pHostSet->DetachClient(
this);
1936 if(!mpClients) mpClients=
new std::list< TBaseSet<T,Cmp>* >;
1945 for(
aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait) {
1946 FD_DC(
"TBaseSet(" <<
this <<
")::Clear(): del attr " << ait->second);
1949 delete mpAttributes;
1954 pAttributes=&msEmptyAttributes;
1956 typename std::set< Iterator* >::iterator iit;
1957 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1958 (**iit).Invalidate();
1963 #ifdef FAUDES_DEBUG_CODE
1964 DValid(
"PostClear");
1966 FD_DC(
"TBaseSet(" <<
this <<
")::Clear(): done");
1971 TEMP inline bool THIS::Valid(
const T& rElem)
const {
1977 TEMP bool THIS::Insert(
const T& rElem) {
1978 #ifdef FAUDES_CHECKED
1980 std::stringstream errstr;
1981 errstr <<
"refuse to insert invalid element" << std::endl;
1982 throw Exception(
"BaseSet::Insert", errstr.str(), 61);
1985 if(!mDetached) Detach();
1986 return pSet->insert(rElem).second;
1990 TEMP typename THIS::Iterator THIS::Inject(
const Iterator& pos,
const T& rElem) {
1991 if(!mDetached) Detach();
1993 return ThisIterator(pSet->insert(dst,rElem));
1998 TEMP void THIS::Inject(
const T& rElem) {
1999 if(!mDetached) Detach();
2000 pSet->insert(pSet->end(),rElem);
2005 FD_DC(
"TBaseSet(" <<
this <<
")::InsertSet(" << &rOtherSet <<
")");
2006 if(!mDetached) Detach();
2015 while ((it1 != pSet->end()) && (it2 != rOtherSet.
pSet->end())) {
2019 else if (*it1 == *it2) {
2028 while (it2 != rOtherSet.
pSet->end()) {
2036 TEMP bool THIS::Erase(
const T& rElem) {
2037 if(!mDetached) Detach();
2038 return (pSet->erase(rElem)!=0);
2044 #ifdef FAUDES_CHECKED
2046 std::stringstream errstr;
2047 errstr <<
"iterator out of range " << std::endl;
2048 throw Exception(
"BaseSet::Erase", errstr.str(), 62);
2054 return ThisIterator(del);
2060 FD_DC(
"TBaseSet(" <<
this <<
")::EraseSet(" << &rOtherSet <<
")");
2061 if(!mDetached) Detach();
2065 while ((it != pSet->end()) && (oit != rOtherSet.
pSet->end())) {
2067 it=pSet->lower_bound(*oit);
2069 else if (*it == *oit) {
2074 oit=rOtherSet.
pSet->lower_bound(*it);
2082 FD_DC(
"TBaseSet(" <<
this <<
")::RestrictSet(" << &rOtherSet <<
")");
2083 if(!mDetached) Detach();
2087 while ((it != pSet->end()) && (oit != rOtherSet.
pSet->end())) {
2091 else if (*it == *oit) {
2096 oit=rOtherSet.
pSet->lower_bound(*it);
2099 while(it != pSet->end()) {
2107 FD_DC(
"TBaseSet(" <<
this <<
")::Disjoint(" << &rOtherSet <<
")");
2109 if(pSet->empty())
return true;
2110 if(rOtherSet.
pSet->empty())
return true;
2111 if(*pSet->rbegin()<*rOtherSet.
pSet->begin())
return true;
2112 if(*rOtherSet.
pSet->rbegin()<*pSet->begin())
return true;
2113 if(rOtherSet.
pSet==pSet)
return false;
2117 while ((it != pSet->end()) && (oit != rOtherSet.
pSet->end())) {
2118 if (*it < *oit) { it++;
continue;}
2119 if (*it == *oit) {
return false; }
2127 TEMP typename THIS::Iterator THIS::Find(
const T& rElem)
const {
2128 return ThisIterator(pSet->find(rElem));
2132 TEMP bool THIS::Exists(
const T& rElem)
const {
2133 return pSet->find(rElem) != pSet->end();
2162 FD_DC(
"TBaseSet::DoEqual()");
2164 if(pSet == rOtherSet.
pSet)
return true;
2166 return ( *pSet == *rOtherSet.
pSet );
2171 FD_DC(
"BaseSet::op<=()");
2172 return ( std::includes(rOtherSet.
pSet->begin(), rOtherSet.
pSet->end(), pSet->begin(), pSet->end()) ) ;
2177 FD_DC(
"BaseSet::op>=()");
2178 return ( std::includes(pSet->begin(), pSet->end(), rOtherSet.
pSet->begin(), rOtherSet.
pSet->end()) );
2183 return *pSet < *rOtherSet.
pSet;
2194 TEMP bool THIS::AttributeTest(
const Type& rAttr)
const {
2195 return AttributeType()->Cast(&rAttr)!=NULL;
2200 return (
Idx) pAttributes->size();
2204 TEMP void THIS::ClearAttributes(
void) {
2206 if(this->pAttributes->size()==0)
return;
2208 this->Detach(SetOnly);
2214 FD_DC(
"TBaseSet::EqualAttributes(TBaseSet)");
2216 FD_DC(
"TBaseSet::EqualAttributes(TBaseSet): 1");
2217 if(
typeid(*rOtherSet.
AttributeType())!=
typeid(*this->AttributeType()))
2220 FD_DC(
"TBaseSet::EqualAttributes(TBaseSet): 2");
2224 FD_DC(
"TBaseSet::EqualAttributes(TBaseSet): 3");
2226 if(this->AttributesSize()==0)
2231 while ((ait1 != pAttributes->end()) && (ait2 != rOtherSet.
pAttributes->end())) {
2232 if (ait1->first < ait2->first) {
2235 else if (ait1->first == ait2->first) {
2236 FD_DC(
"TBaseSet::EqualAttributes(TBaseSet): cmp " << ait1->second->ToString()
2237 <<
" vs " << ait2->second->ToString());
2238 if( ! ait1->second->Equal(*ait2->second))
return false;
2247 FD_DC(
"TBaseSet::EqualAttributes(TBaseSet): pass");
2256 this->DoAssign(rSourceSet);
2258 this->Detach(SetOnly);
2264 FD_DC(
"TBaseSet::Attributes("<<
this<<
")");
2267 std::stringstream errstr;
2268 errstr <<
"cannot cast attribute " << std::endl;
2269 throw Exception(
"TBaseSet::Attributes(otherset)", errstr.str(), 63);
2272 if(
typeid(*this->AttributeType())==
typeid(
const AttributeVoid))
return;
2274 this->Detach(AttrIncl);
2277 while ((it1 != pSet->end()) && (it2 != rOtherSet.
pSet->end())) {
2281 else if (*it1 == *it2) {
2282 DoAttribute(*it1,&rOtherSet.
Attribute(*it2));
2290 FD_DC(
"TBaseSet::Attributes(): copy ok");
2298 std::stringstream errstr;
2299 errstr <<
"cannot get attribute for TBaseSet \"" << mMyName <<
"\" type " <<
typeid(*this).name();
2300 throw Exception(
"TBaseSet::Attributep(rElem)", errstr.str(), 63);
2314 TEMP void THIS::Attribute(
const T& rElem,
const Type& rAttr) {
2317 #ifdef FAUDES_CHECKED
2318 if (!Exists(rElem)) {
2319 std::stringstream errstr;
2320 errstr <<
"element not member of set" << std::endl;
2321 throw Exception(
"TBaseSet::Attribute(elem,attr)", errstr.str(), 60);
2324 if(!AttributeTest(rAttr)) {
2325 std::stringstream errstr;
2326 errstr <<
"cannot cast attribute " << std::endl;
2327 throw Exception(
"TBaseSet::Attribute(elem,attr)", errstr.str(), 63);
2334 TEMP void THIS::ClrAttribute(
const T& rElem) {
2343 ait=this->pAttributes->find(rElem);
2344 if(ait==this->pAttributes->end())
return NULL;
2350 FD_DC(
"TBaseSet::DoAttributeExplicit(elem)");
2351 #ifdef FAUDES_DEBUG_CODE
2352 if(this->pAttributes!=this->mpAttributes) {
2353 FD_ERR(
"TBaseSet::DoAttributeExplicit(elem): attributes not detached");
2358 ait=this->pAttributes->find(rElem);
2359 if(ait!=this->pAttributes->end())
2363 FD_DC(
"TBaseSet::DoAttributeExplicit(Elem): inserting explicit default " << attr <<
" type " <<
typeid(*attr).name());
2364 (*this->pAttributes)[rElem]=attr;
2369 TEMP void THIS::DoAttribute(
const T& rElem,
const Type* pAttr) {
2370 FD_DC(
"TBaseSet::DoAttribute([v] " << this->Str(rElem) <<
", ...)");
2371 #ifdef FAUDES_DEBUG_CODE
2372 if(this->pAttributes!=this->mpAttributes) {
2373 FD_ERR(
"TBaseSet::DoAttribute([v] set): attributes not detached");
2379 if(!this->AttributeType()->Cast(pAttr)) newattr=NULL;
2383 ait=this->pAttributes->find(rElem);
2384 if(ait!=this->pAttributes->end() )
2385 oldattr=ait->second;
2388 FD_DC(
"TBaseSet::DoAttribute([v] " << this->Str(rElem) <<
", ...): default 1");
2389 if(oldattr==NULL)
return;
2391 this->pAttributes->erase(ait);
2396 FD_DC(
"TBaseSet::DoAttribute([v] " << this->Str(rElem) <<
", ...): default 2");
2397 if(oldattr==NULL)
return;
2399 this->pAttributes->erase(ait);
2402 FD_DC(
"TBaseSet::DoAttribute([v] " << this->Str(rElem) <<
", ...): " << newattr->
ToString());
2407 (*this->pAttributes)[rElem]=attr;
2411 FD_DC(
"TBaseSet::DoAttribute([v] " << this->Str(rElem) <<
", ...): " << newattr->
ToString());
2412 oldattr->
Assign(*newattr);
#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
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 * > * mpAttributes
std::list< TBaseSet< T, Cmp > * >::iterator mClientRecord
std::string mXElementTagDef
std::set< Iterator * > mIterators
std::set< T, Cmp >::iterator iterator
std::set< T, Cmp > * mpSet
std::string mFaudesTypeName
const TypeDefinition * pTypeDefinition
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::set< T, Cmp > * pSet
TBaseSet< T, Cmp > * pHostSet
void ReadEnd(const std::string &rLabel)
void ReadBegin(const std::string &rLabel)
void WriteComment(const std::string &rComment)
void WriteEnd(const std::string &rLabel)
void WriteBegin(const std::string &rLabel)
const std::string & XElementTag(void) const
static TypeRegistry * G()
const TypeDefinition * Definitionp(const std::string &rTypeName) 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 & Assign(const Type &rSrc)
virtual Type * New(void) const
virtual Type * Copy(void) const
virtual bool Insert(const T &rElem)
bool DoEqual(const TBaseSet &rOtherSet) const
virtual const AttributeVoid * AttributeType(void) const
virtual const std::string & XElementTag(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 TypeName(const std::string &rType)
void DetachClient(TBaseSet *pRef) const
void SetDifference(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB, TBaseSet< T, Cmp > &rRes)
bool Exists(const T &rElem) const
virtual void Attributes(const TBaseSet &rOtherSet)
virtual void Attribute(const T &rElem, const Type &rAttr)
virtual bool Disjoint(const TBaseSet &rOtherSet) const
void Name(const std::string &rName)
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
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
virtual void XElementTag(const std::string &rTag)
Idx AttributesSize(void) const
static std::set< T, Cmp > msEmptySet
virtual bool AttributeTest(const Type &rAttr) const
TBaseSet(const std::string &rFilename, const std::string &rLabel="BaseSet")
virtual const TypeDefinition * TypeDefinitionp(void) 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 const std::string & TypeName(void) 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)
const std::string & Name(void) const
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 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)
static std::map< T, AttributeVoid * > msEmptyAttributes
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)