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 ExtType::operator=;
105 using ExtType::operator==;
106 using ExtType::operator!=;
109 template<
class TP,
class AP,
class CP>
friend class TAttrMap;
135 TBaseSet(
const std::string& rFilename,
const std::string& rLabel =
"BaseSet");
178 virtual std::string
Str(
const T& rElem)
const;
223 virtual bool Valid(
const T& rElem)
const;
245 virtual Iterator
Erase(
const Iterator& pos);
293 virtual Iterator
Inject(
const Iterator& pos,
const T& rElem);
334 Iterator
Find(
const T& rElem)
const;
371 void DValid(
const std::string& rMessage=
"")
const;
406 const typename std::set<T,Cmp>::const_iterator& sit,
412 if(pBaseSet && att) {
421 pBaseSet(fit.pBaseSet),
425 pBaseSet->AttachIterator(
this);
432 if(mAttached) pBaseSet->DetachIterator(
this);
437 std::stringstream rstr;
438 rstr <<
"[dit base " << pBaseSet <<
" a" << mAttached <<
" data " << pBaseSet->pSet;
439 if(pBaseSet) rstr <<
" elem " << pBaseSet->Str(**
this);
446 #ifdef FAUDES_DEBUG_CODE
448 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator= invalid iterator: no baseset");
453 if(mAttached)
if(pBaseSet==rSrc.
pBaseSet) {
454 std::set<T,Cmp>::const_iterator::operator= (rSrc);
458 if(mAttached) pBaseSet->DetachIterator(
this);
459 std::set<T,Cmp>::const_iterator::operator= (rSrc);
471 void StlIterator(
const typename std::set<T,Cmp>::const_iterator& sit) {
472 std::set<T,Cmp>::const_iterator::operator= (sit);
476 const typename std::set<T,Cmp>::const_iterator&
StlIterator(
void)
const {
495 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):DValid(): invalid iterator: no baseset");
498 pBaseSet->DValid(
"Iterator");
502 const T* operator-> (
void)
const {
503 #ifdef FAUDES_DEBUG_CODE
505 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator->: invalid iterator: no baseset");
509 return std::set<T,Cmp>::const_iterator::operator-> ();
513 const T& operator* (
void)
const {
514 #ifdef FAUDES_DEBUG_CODE
516 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator*: invalid iterator: no baseset");
520 return std::set<T,Cmp>::const_iterator::operator* ();
525 #ifdef FAUDES_DEBUG_CODE
527 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator==: invalid iterator: no baseset");
531 return *
static_cast< const typename std::set<T,Cmp>::const_iterator *
>(
this) == rOther;
536 #ifdef FAUDES_DEBUG_CODE
538 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator!=: invalid iterator: no baseset");
542 return *
static_cast< const typename std::set<T,Cmp>::const_iterator *
>(
this) != rOther;
547 #ifdef FAUDES_DEBUG_CODE
549 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator++: invalid iterator: no baseset");
554 std::set<T,Cmp>::const_iterator::operator++ (step);
560 #ifdef FAUDES_DEBUG_CODE
562 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator++: invalid iterator: no baseset");
566 std::set<T,Cmp>::const_iterator::operator++ ();
572 #ifdef FAUDES_DEBUG_CODE
574 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator--: invalid iterator: no baseset");
578 Iterator old(pBaseSet, *
this,
true);
579 std::set<T,Cmp>::const_iterator::operator-- (step);
585 #ifdef FAUDES_DEBUG_CODE
587 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator--: invalid iterator: no baseset");
591 std::set<T,Cmp>::const_iterator::operator-- ();
610 #ifdef DONT_TRACK_REFERENCES
621 std::set<T,Cmp>::const_iterator()
625 Iterator(
const Iterator& fit) :
626 std::set<T,Cmp>::const_iterator(fit)
630 Iterator(
const typename std::set<T,Cmp>::const_iterator& sit) :
631 std::set<T,Cmp>::const_iterator(sit)
636 const TBaseSet<T,Cmp>* pBaseSet,
637 const typename std::set<T,Cmp>::const_iterator& sit) :
638 std::set<T,Cmp>::const_iterator(sit)
642 void StlIterator(
const typename std::set<T,Cmp>::const_iterator& sit) {
643 std::set<T,Cmp>::const_iterator::operator= (sit);
647 const typename std::set<T,Cmp>::const_iterator& StlIterator(
void)
const {
652 void Invalidate(
void) {};
785 virtual void AttributeTry(
const T& rElem,
const Type& rAttr) { (void) rElem; (void) rAttr; };
953 typedef typename std::set<T,Cmp>::iterator
iterator;
970 typedef typename std::map<T,AttributeVoid*>::iterator
aiterator;
1036 template<
class T,
class Cmp>
1038 FD_DC(
"FAUDES_DEBUG_CONTAINER: SetUnion(TBaseSet<T,Cmp>): res at " << &rRes);
1042 if(&rSetA==&rSetB && &rSetA==&rRes) {rRes.
Name(name);
return;}
1044 if(&rSetA==&rSetB) {rRes.
Assign(rSetA); rRes.
Name(name);
return;}
1046 if(&rSetA==&rRes) {rRes.
InsertSet(rSetB); rRes.
Name(name);
return;};
1048 if(&rSetB==&rRes) {rRes.
InsertSet(rSetA); rRes.
Name(name);
return;};
1053 FD_DC(
"FAUDES_DEBUG_CONTAINER: SetUnion(TBaseSet<T,Cmp>): done, res at " << &rRes <<
" #" << rRes.
Size());
1066 template<
class T,
class Cmp >
1071 if(&rSetA==&rSetB && &rSetA==&rRes) {rRes.
Name(name);
return;}
1073 if(&rSetA==&rSetB) { rRes.
Assign(rSetA); rRes.
Name(name);
return;}
1075 if(&rSetA==&rRes) {rRes.
RestrictSet(rSetB); rRes.
Name(name);
return;};
1077 if(&rSetB==&rRes) {rRes.
RestrictSet(rSetA); rRes.
Name(name);
return;};
1095 template<
class T,
class Cmp >
1100 if(&rSetA==&rSetB) { rRes.
Clear(); rRes.
Name(name);
return;}
1102 if(&rSetA==&rRes) {rRes.
EraseSet(rSetB); rRes.
Name(name);
return;};
1129 template<
class T,
class Cmp >
1131 return rSetA==rSetB;
1145 template<
class T,
class Cmp >
1147 return rSetA<=rSetB;
1169 #define THIS TBaseSet<T,Cmp>
1170 #define TEMP template<class T, class Cmp>
1189 TEMP std::set<T,Cmp> THIS::msEmptySet=std::set<T,Cmp>();
1190 TEMP std::map<T,AttributeVoid*> THIS::msEmptyAttributes=std::map<T,AttributeVoid*>();
1197 pAttributes(&msEmptyAttributes),
1200 mpClients(new std::list<
TBaseSet<T,Cmp>* >),
1205 FD_DC(
"TBaseSet(" <<
this <<
")::TBaseSet()");
1212 TEMP THIS::TBaseSet(
const std::string& rFileName,
const std::string& rLabel) :
1216 pAttributes(&msEmptyAttributes),
1219 mpClients(new std::list<
TBaseSet<T,Cmp>* >),
1224 FD_DC(
"TBaseSet(" <<
this <<
")::TBaseSet()");
1229 Read(rFileName,rLabel);
1237 pAttributes(&msEmptyAttributes),
1240 mpClients(new std::list<
TBaseSet<T,Cmp>* >),
1245 FD_DC(
"TBaseSet(" <<
this <<
")::TBaseSet(rOtherSet " << &rOtherSet <<
"): fake copy construct");
1251 #ifdef FAUDES_DEBUG_CODE
1259 FD_DC(
"TBaseSet(" <<
this <<
")::~TBaseSet()");
1262 pHostSet->DetachClient(
this);
1263 if(mpClients)
delete mpClients;
1266 typename std::set< Iterator* >::const_iterator iit;
1267 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1268 (**iit).Invalidate();
1271 if(mpSet)
delete mpSet;
1273 for(
aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait)
1275 delete mpAttributes;
1282 FD_DC(
"TBaseSet(" <<
this <<
"/" << this->Name() <<
")::DoAssign(rOtherSet " << &rSourceSet <<
"): shallow copy -- src attr# " << rSourceSet.pAttributes->size());
1283 FD_DC(
"TBaseSet():DoAssign(): " <<
typeid(*this->AttributeType()).name() <<
" <== " <<
typeid(*rSourceSet.AttributeType()).name());
1285 if(
this==&rSourceSet)
return;
1287 mObjectName=rSourceSet.mObjectName;
1288 mElementTagDef=rSourceSet.mObjectName;
1290 if(pHostSet==rSourceSet.pHostSet)
return;
1293 pHostSet->DetachClient(
this);
1300 for(
aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait)
1302 delete mpAttributes;
1310 if(
typeid(*rSourceSet.AttributeType())==
typeid(*this->AttributeType())) {
1311 pHostSet=rSourceSet.pHostSet;
1312 pHostSet->AttachClient(
this);
1313 pSet=rSourceSet.pSet;
1314 pAttributes=rSourceSet.pAttributes;
1318 mpSet =
new std::set<T,Cmp>();
1319 *mpSet = *rSourceSet.pSet;
1321 mpAttributes =
new std::map<T,AttributeVoid*>();
1322 if(
typeid(*this->AttributeType()) !=
typeid(
const AttributeVoid)) {
1323 for(
aiterator ait=rSourceSet.pAttributes->begin(); ait!=rSourceSet.pAttributes->end(); ++ait) {
1325 (*mpAttributes)[ait->first]=attr;
1329 pAttributes = mpAttributes;
1333 typename std::set< Iterator* >::iterator iit;
1334 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1335 (**iit).Invalidate();
1345 #ifdef FAUDES_DEBUG_CODE
1346 DValid(
"PostFakeAssignment");
1348 FD_DC(
"TBaseSet(" <<
this <<
")::DoAssign(rOtherSet " << &rSourceSet <<
"): fake copy -- done with attr# " << pAttributes->size());
1353 FD_DC(
"TBaseSet(" <<
this <<
")::Detach(void)");
1354 #ifdef FAUDES_DEBUG_CODE
1355 DValid(
"PreDetach");
1360 if(flag==SetOnly) pAttributes->clear();
1365 THIS* fake_const =
const_cast< THIS*
>(
this);
1367 #ifdef FAUDES_DEBUG_CODE
1370 if(pSet!=&msEmptySet)
1372 if(mpClients->empty()) {
1373 FD_ERR(
"TBaseSet(" <<
this <<
")::Detach(): missed detach (?)");
1375 fake_const->mDetached=
true;
1380 std::set<T,Cmp>* scopy =
new std::set<T,Cmp>();
1384 std::map<T,AttributeVoid*>* acopy =
new std::map<T,AttributeVoid*>();
1385 if(flag==AttrIncl) {
1386 for(
aiterator ait=pAttributes->begin(); ait!=pAttributes->end(); ++ait) {
1388 (*acopy)[ait->first]=attr;
1397 FD_DC(
"TBaseSet(" <<
this <<
")::Detach(): allocate and copy, strategie A");
1399 THIS* newhost = *mpClients->begin();
1400 #ifdef FAUDES_DEBUG_CODE
1401 if(newhost->mpClients)
1402 FD_ERR(
"TBaseSet(" <<
this <<
")::Detach(): new host used to heve clients (?)");
1404 newhost->pHostSet=newhost;
1405 newhost->mpSet=scopy;
1406 newhost->pSet=scopy;
1407 newhost->mpAttributes=acopy;
1408 newhost->pAttributes=acopy;
1409 newhost->mpClients=mpClients;
1410 newhost->DetachClient(newhost);
1412 typename std::list< THIS* >::const_iterator rit;
1413 for(rit=newhost->mpClients->begin();rit!=newhost->mpClients->end(); ++rit) {
1414 (*rit)->pHostSet=newhost;
1415 (*rit)->pSet=newhost->pSet;
1416 (*rit)->pAttributes=newhost->pAttributes;
1419 typename std::set< Iterator* >::iterator iit;
1420 for(rit=newhost->mpClients->begin(); rit!=newhost->mpClients->end(); ++rit) {
1421 for(iit=(*rit)->mIterators.begin(); iit!=(*rit)->mIterators.end(); ++iit) {
1422 if((**iit).StlIterator()==pSet->end())
1423 **iit=
Iterator(
this, scopy->end());
1425 **iit=
Iterator(
this, scopy->find(***iit));
1429 for(iit=newhost->mIterators.begin(); iit!=newhost->mIterators.end(); ++iit) {
1430 if((**iit).StlIterator()==pSet->end())
1431 **iit=
Iterator(
this, scopy->end());
1433 **iit=
Iterator(
this, scopy->find(***iit));
1436 fake_const->mpSet=pSet;
1437 fake_const->mpAttributes=pAttributes;
1438 fake_const->mpClients=
new std::list< TBaseSet<T,Cmp>* >;
1439 fake_const->mDetached=
true;
1441 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit)
1443 fake_const->mIterators.clear();
1451 FD_DC(
"TBaseSet(" <<
this <<
")::Detach(): allocate and copy, strategie B");
1453 fake_const->RelinkClients();
1454 pHostSet->DetachClient(fake_const);
1456 fake_const->mpSet = scopy;
1457 fake_const->mpAttributes=acopy;
1459 typename std::set< Iterator* >::iterator iit;
1460 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1461 if((**iit).StlIterator()==pSet->end())
1462 **iit=
Iterator(
this, mpSet->end());
1464 **iit=
Iterator(
this, mpSet->find(***iit));
1467 fake_const->pHostSet=fake_const;
1468 fake_const->pSet=mpSet;
1469 fake_const->pAttributes=mpAttributes;
1470 fake_const->mDetached=
true;
1471 if(fake_const->mpClients)
delete fake_const->mpClients;
1472 fake_const->mpClients=
new std::list< TBaseSet<T,Cmp>* >;
1476 #ifdef FAUDES_DEBUG_CODE
1477 DValid(
"PostDetach");
1479 FD_DC(
"TBaseSet(" <<
this <<
")::Detach(): done");
1484 FD_DC(
"TBaseSet(" <<
this <<
")::Lock(void)");
1485 #ifdef FAUDES_DEBUG_CODE
1495 THIS* fake_const =
const_cast< THIS*
>(
this);
1498 typename std::set< Iterator* >::const_iterator iit;
1499 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1502 fake_const->mIterators.clear();
1505 fake_const->mLocked=
true;
1507 #ifdef FAUDES_DEBUG_CODE
1514 TEMP inline void THIS::RelinkClients(
void) {
1515 FD_DC(
"TBaseSet::RelinkClients(" <<
this <<
")")
1516 #ifdef FAUDES_DEBUG_CODE
1517 DValid(
"PreRelink");
1521 if(!mpClients)
return;
1523 if(mpClients->empty())
return;
1525 FD_DC(
"TBaseSet::RelinkClients(" <<
this <<
"): doit")
1528 THIS* newhost = *mpClients->begin();
1529 #ifdef FAUDES_DEBUG_CODE
1530 if(newhost->pHostSet!=
this)
1531 FD_ERR(
"BaseSet::RelinkRefernces: old reference must have this as provider");
1532 if(newhost->mpClients)
1533 FD_ERR(
"TBaseSet(" <<
this <<
")::RelinkClients(void): client is a host (?)");
1535 newhost->pHostSet=newhost;
1536 newhost->mpSet=mpSet;
1538 newhost->mpAttributes=mpAttributes;
1539 newhost->pAttributes=pAttributes;
1540 newhost->mpClients=mpClients;
1541 newhost->DetachClient(newhost);
1543 typename std::list< THIS* >::const_iterator rit;
1544 for(rit=newhost->mpClients->begin();rit!=newhost->mpClients->end(); ++rit) {
1545 (*rit)->pHostSet=newhost;
1551 pAttributes=newhost->pAttributes;
1553 newhost->AttachClient(
this);
1555 #ifdef FAUDES_DEBUG_CODE
1556 DValid(
"PostRelink");
1558 FD_DC(
"TBaseSet::RelinkClients(" <<
this <<
"): done")
1565 const_cast< THIS*
>(
this)->mpClients->push_back(pRef);
1567 const_cast< THIS*
>(
this)->mDetached=
false;
1572 FD_DC(
"TBaseSet::DetachClient(" <<
this <<
"):" << pRef);
1574 if(!mpClients)
return;
1575 if(mpClients->empty())
return;
1578 THIS* fake_const =
const_cast< THIS*
>(
this);
1579 #ifdef FAUDES_DEBUG_CODE
1581 typename std::list< TBaseSet<T,Cmp>* >
::iterator cit;
1583 for(cit=fake_const->mpClients->begin(); cit!=fake_const->mpClients->end(); ++cit) {
1584 if(*cit==pRef) cf=
true;
1587 FD_ERR(
"TBaseSet::DetachClient(" <<
this <<
"): client not found " << pRef);
1600 typename std::list< TBaseSet<T,Cmp>* >
::iterator rit;
1601 for(rit=fake_const->mpClients->begin(); rit!=fake_const->mpClients->end(); ++rit) {
1602 if(*rit!=pRef)
continue;
1603 fake_const->mpClients->erase(rit);
1607 if(mpClients->empty() && (pSet!=&msEmptySet)) fake_const->mDetached=
true;
1608 FD_DC(
"TBaseSet::DetachClient(" <<
this <<
"): done.");
1615 FD_DC(
"TBaseSet::AttachIterator(" <<
this <<
"):" << pFit)
1616 const_cast< THIS*
>(
this)->mIterators.insert(pFit);
1622 FD_DC(
"TBaseSet::DetachIterator(" <<
this <<
"):" << pFit)
1623 const_cast< THIS*
>(
this)->mIterators.erase(pFit);
1627 TEMP void THIS::DValid(
const std::string& rMessage)
const {
1628 typename std::set< Iterator* >::const_iterator iit;
1629 typename std::list< THIS* >::const_iterator rit;
1630 #ifdef FAUDES_DEBUG_CONTAINER
1631 std::cerr <<
"TBaseSet(" <<
this <<
")::DValid(): " << rMessage <<
" source "
1632 << pHostSet <<
" " << (pHostSet->pSet==&msEmptySet ?
"+e+" :
"+f+") <<
1633 (mLocked ?
" +l+" :
" ") << (mDetached ?
" +d+" :
" ") <<
" -- refs ";
1634 if(pHostSet->mpClients)
1635 for(rit=pHostSet->mpClients->begin(); rit!=pHostSet->mpClients->end(); ++rit)
1636 std::cerr << *rit <<
" ";
1637 std::cerr <<
"-- its ";
1638 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit)
1639 std::cerr << *iit <<
" ";
1640 std::cerr <<
"-- attr #" << pAttributes->size();
1641 if(mpAttributes) std::cerr <<
"(" << mpAttributes->size() <<
") ";
1642 else std::cerr <<
" ";
1643 std::cerr << (pAttributes==&msEmptyAttributes ?
"+e+ " :
"+f+ ") << std::endl;
1646 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1647 if((*iit)->pBaseSet!=
this) {
1648 FD_WARN(
"BaseSet("<<
this <<
"," << rMessage <<
"): invalid iterator (baseset): "<< *iit);
1653 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1654 if(!(*iit)->mAttached) {
1655 FD_WARN(
"BaseSet("<<
this <<
"," << rMessage <<
"): invalid iterator (attached): "<< *iit);
1660 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1661 typename std::set<T,Cmp>::const_iterator vit;
1662 for(vit=pSet->begin(); vit!= pSet->end(); ++vit) {
1663 if(vit==(**iit).StlIterator())
break;
1665 if(vit!=(**iit).StlIterator()) {
1666 FD_WARN(
"BaseSet("<<
this <<
"," << rMessage <<
"): invalid iterator (stl) "<< *iit);
1667 (**iit).StlIterator(pSet->end());
1672 if(pHostSet==NULL) {
1673 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): no host found");
1677 if(pHostSet->pHostSet != pHostSet) {
1678 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): inconsistent host");
1682 if((mpSet!=NULL) && (pHostSet !=
this)) {
1683 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): double data");
1687 if(pHostSet!=
this && mpClients!=NULL) {
1688 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): cannot be client and have clients oneself");
1692 if(pHostSet->mpClients==NULL) {
1693 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): refers to invalid host (a)");
1697 if(pHostSet!=
this && pHostSet->mpClients->empty()) {
1698 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): refers to invalid host (b)");
1702 if((pHostSet ==
this) && (mpSet==NULL) && (pSet!=&msEmptySet)) {
1703 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): no data");
1707 if((pHostSet==
this) && (pSet!=&msEmptySet) && (mpClients==NULL)) {
1708 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): host with no client list");
1712 if((pHostSet ==
this) && (pSet != mpSet) && (pSet!=&msEmptySet)) {
1713 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): data pointer mismatch A");
1717 if(pSet != pHostSet->pSet) {
1718 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): data pointer mismatch B");
1723 for(rit=pHostSet->mpClients->begin(); rit!=pHostSet->mpClients->end(); ++rit) {
1724 if((*rit)==
this) hf=
true;
1725 if((*rit)->pHostSet== pHostSet)
continue;
1726 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): invalid client " << (*rit));
1729 if(!hf && (pHostSet!=
this)) {
1730 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): client not registered with host");
1734 if(pHostSet!=
this && *mClientRecord!=
this) {
1735 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): refers to invalid host (c)");
1739 if(mDetached && mpClients==NULL) {
1740 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): invalid detached flag A");
1744 if(mDetached && !mpClients->empty()) {
1745 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): invalid detached flag B");
1749 if(mDetached && (pSet==&msEmptySet)) {
1750 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): detached empty set");
1754 if(mLocked && (mpClients==NULL)) {
1755 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): locked reference (a)");
1759 if(!msEmptySet.empty()) {
1760 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): invalid empty set");
1764 if(!msEmptyAttributes.empty()) {
1765 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): invalid empty attributes");
1768 #ifdef FAUDES_DEBUG_CONTAINER
1769 std::cerr <<
"TBaseSet(" <<
this <<
")::DValid(): passed" << std::endl;
1775 TEMP std::string THIS::Str(
const T& rElem)
const {
1783 return (
Idx) pSet->size();
1787 TEMP bool THIS::Empty(
void)
const {
1788 return pSet->empty();
1792 TEMP void THIS::DoWriteElement(
TokenWriter& rTw,
const T& rElem,
const std::string& rLabel,
const Type* pContext)
const {
1796 ep->
Write(rTw,rLabel,pContext);
1800 std::stringstream errstr;
1801 errstr <<
"used but not reimplemented" <<
typeid(
this).name() << std::endl;
1802 throw Exception(
"BaseSet::DoWriteElement", errstr.str(), 61);
1806 TEMP void THIS::DoXWriteElement(
TokenWriter& rTw,
const T& rElem,
const std::string& rLabel,
const Type* pContext)
const {
1810 ep->
XWrite(rTw,rLabel,pContext);
1814 std::stringstream errstr;
1815 errstr <<
"used but not reimplemented" <<
typeid(
this).name() << std::endl;
1816 throw Exception(
"BaseSet::DoXWriteElement", errstr.str(), 61);
1821 std::string label=rLabel;
1822 if(label==
"") label=Name();
1823 if(label==
"") label=
"BaseSet";
1824 std::string etstr=ElementTag();
1825 FD_DC(
"TBaseSet(" <<
this <<
")::DoWrite(..): section " << label <<
" #" << Size());
1829 for (it = Begin(); it != End(); ++it) {
1830 DoWriteElement(rTw, *it, etstr, pContext);
1839 Token btag=XBeginTag(rLabel,
"BaseSet");
1841 FD_DC(
"BaseSet(" <<
this <<
")::DoXWrite(..): section " << btag.
StringValue() <<
" #" << Size());
1843 std::string etstr=ElementTag();
1845 for (it = Begin(); it != End(); ++it) {
1846 DoXWriteElement(rTw, *it, etstr, pContext);
1855 BASE::DoSWrite(rTw);
1857 if(pHostSet->mpClients) shares=pHostSet->mpClients->size();
1864 #ifdef FAUDES_DEBUG_CODE
1871 BASE::DoSWrite(rTw);
1873 if(pHostSet->mpClients) shares=pHostSet->mpClients->size();
1876 if(pAttributes->size()!=0)
1878 if(pAttributes->size()!=0) {
1890 ep->
Read(rTr,rLabel,pContext);
1894 std::stringstream errstr;
1895 errstr <<
"used but not reimplemented" <<
typeid(
this).name() << std::endl;
1896 throw Exception(
"BaseSet::DoReadElement", errstr.str(), 61);
1902 std::string label=rLabel;
1903 std::string ftype=TypeName();
1904 std::string etstr=ElementTag();
1906 std::string etype=
"";
1916 if(label==
"") label=ftype;
1922 FD_DC(
"BaseSet(" <<
typeid(*this).name() <<
")::DoRead(..): section " << label <<
" elements " << etstr);
1924 while(!rTr.
Eos(label)) {
1928 FD_DC(
"TBaseSet(" <<
typeid(*this).name() <<
")::DoRead(..): inserting element");
1931 DoReadElement(rTr,elem,etstr,pContext);
1933 FD_DC(
"TBaseSet(" <<
typeid(*this).name() <<
")::DoRead(..): inserting element: ok");
1937 std::stringstream errstr;
1938 errstr <<
"Invalid token of type " << token.
Type() <<
" at " << rTr.
FileLine();
1939 throw Exception(
"BaseSet::DoRead", errstr.str(), 50);
1942 FD_DC(
"BaseSet(" <<
this <<
")::DoRead(tr," << label <<
", " << pContext <<
"): done");
1946 TEMP typename THIS::Iterator THIS::ThisIterator(
const typename std::set<T,Cmp>::const_iterator& sit)
const {
1951 TEMP inline typename THIS::Iterator THIS::Begin(
void)
const {
1952 return ThisIterator(pSet->begin());
1956 TEMP inline typename THIS::Iterator THIS::End(
void)
const {
1957 return ThisIterator(pSet->end());
1963 FD_DC(
"TBaseSet(" <<
this <<
")::Clear()");
1964 #ifdef FAUDES_DEBUG_CODE
1968 if(pSet==&msEmptySet)
return;
1970 FD_DC(
"TBaseSet(" <<
this <<
")::Clear(): doit");
1971 FD_DC(
"TBaseSet(" <<
this <<
")::Clear(): type " <<
typeid(*this).name());
1973 if(mLocked) Detach(SetOnly);
1976 pHostSet->DetachClient(
this);
1979 if(!mpClients) mpClients=
new std::list< TBaseSet<T,Cmp>* >;
1988 for(
aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait) {
1989 FD_DC(
"TBaseSet(" <<
this <<
")::Clear(): del attr " << ait->second);
1992 delete mpAttributes;
1997 pAttributes=&msEmptyAttributes;
1999 typename std::set< Iterator* >::iterator iit;
2000 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
2001 (**iit).Invalidate();
2006 #ifdef FAUDES_DEBUG_CODE
2007 DValid(
"PostClear");
2009 FD_DC(
"TBaseSet(" <<
this <<
")::Clear(): done");
2014 TEMP bool THIS::IsDefault(
void)
const {
2015 return pSet->empty();
2019 TEMP inline bool THIS::Valid(
const T& rElem)
const {
2025 TEMP bool THIS::Insert(
const T& rElem) {
2026 #ifdef FAUDES_CHECKED
2028 std::stringstream errstr;
2029 errstr <<
"refuse to insert invalid element" << std::endl;
2030 throw Exception(
"BaseSet::Insert", errstr.str(), 61);
2033 if(!mDetached) Detach();
2034 return pSet->insert(rElem).second;
2038 TEMP typename THIS::Iterator THIS::Inject(
const Iterator& pos,
const T& rElem) {
2039 if(!mDetached) Detach();
2041 return ThisIterator(pSet->insert(dst,rElem));
2046 TEMP void THIS::Inject(
const T& rElem) {
2047 if(!mDetached) Detach();
2048 pSet->insert(pSet->end(),rElem);
2053 FD_DC(
"TBaseSet(" <<
this <<
")::InsertSet(" << &rOtherSet <<
")");
2054 if(!mDetached) Detach();
2063 while ((it1 != pSet->end()) && (it2 != rOtherSet.
pSet->end())) {
2067 else if (*it1 == *it2) {
2076 while (it2 != rOtherSet.
pSet->end()) {
2084 TEMP bool THIS::Erase(
const T& rElem) {
2085 if(!mDetached) Detach();
2086 return (pSet->erase(rElem)!=0);
2092 #ifdef FAUDES_CHECKED
2094 std::stringstream errstr;
2095 errstr <<
"iterator out of range " << std::endl;
2096 throw Exception(
"BaseSet::Erase", errstr.str(), 62);
2102 return ThisIterator(del);
2108 FD_DC(
"TBaseSet(" <<
this <<
")::EraseSet(" << &rOtherSet <<
")");
2109 if(!mDetached) Detach();
2113 while ((it != pSet->end()) && (oit != rOtherSet.
pSet->end())) {
2115 it=pSet->lower_bound(*oit);
2117 else if (*it == *oit) {
2122 oit=rOtherSet.
pSet->lower_bound(*it);
2130 FD_DC(
"TBaseSet(" <<
this <<
")::RestrictSet(" << &rOtherSet <<
")");
2131 if(!mDetached) Detach();
2135 while ((it != pSet->end()) && (oit != rOtherSet.
pSet->end())) {
2139 else if (*it == *oit) {
2144 oit=rOtherSet.
pSet->lower_bound(*it);
2147 while(it != pSet->end()) {
2155 FD_DC(
"TBaseSet(" <<
this <<
")::Disjoint(" << &rOtherSet <<
")");
2157 if(pSet->empty())
return true;
2158 if(rOtherSet.
pSet->empty())
return true;
2159 if(*pSet->rbegin()<*rOtherSet.
pSet->begin())
return true;
2160 if(*rOtherSet.
pSet->rbegin()<*pSet->begin())
return true;
2161 if(rOtherSet.
pSet==pSet)
return false;
2165 while ((it != pSet->end()) && (oit != rOtherSet.
pSet->end())) {
2166 if (*it < *oit) { it++;
continue;}
2167 if (*it == *oit) {
return false; }
2175 TEMP typename THIS::Iterator THIS::Find(
const T& rElem)
const {
2176 return ThisIterator(pSet->find(rElem));
2180 TEMP bool THIS::Exists(
const T& rElem)
const {
2181 return pSet->find(rElem) != pSet->end();
2210 FD_DC(
"TBaseSet::DoEqual()");
2212 if(pSet == rOtherSet.
pSet)
return true;
2214 return ( *pSet == *rOtherSet.
pSet );
2219 FD_DC(
"BaseSet::op<=()");
2220 return ( std::includes(rOtherSet.
pSet->begin(), rOtherSet.
pSet->end(), pSet->begin(), pSet->end()) ) ;
2225 FD_DC(
"BaseSet::op>=()");
2226 return ( std::includes(pSet->begin(), pSet->end(), rOtherSet.
pSet->begin(), rOtherSet.
pSet->end()) );
2231 return *pSet < *rOtherSet.
pSet;
2242 TEMP bool THIS::AttributeTest(
const Type& rAttr)
const {
2243 return AttributeType()->Cast(&rAttr)!=NULL;
2248 return (
Idx) pAttributes->size();
2252 TEMP void THIS::ClearAttributes(
void) {
2254 if(this->pAttributes->size()==0)
return;
2256 this->Detach(SetOnly);
2262 FD_DC(
"TBaseSet::EqualAttributes(TBaseSet)");
2264 FD_DC(
"TBaseSet::EqualAttributes(TBaseSet): 1");
2265 if(
typeid(*rOtherSet.
AttributeType())!=
typeid(*this->AttributeType()))
2268 FD_DC(
"TBaseSet::EqualAttributes(TBaseSet): 2");
2272 FD_DC(
"TBaseSet::EqualAttributes(TBaseSet): 3");
2274 if(this->AttributesSize()==0)
2279 while ((ait1 != pAttributes->end()) && (ait2 != rOtherSet.
pAttributes->end())) {
2280 if (ait1->first < ait2->first) {
2283 else if (ait1->first == ait2->first) {
2284 FD_DC(
"TBaseSet::EqualAttributes(TBaseSet): cmp " << ait1->second->ToString()
2285 <<
" vs " << ait2->second->ToString());
2286 if( ! ait1->second->Equal(*ait2->second))
return false;
2295 FD_DC(
"TBaseSet::EqualAttributes(TBaseSet): pass");
2304 this->DoAssign(rSourceSet);
2306 this->Detach(SetOnly);
2312 FD_DC(
"TBaseSet::Attributes("<<
this<<
")");
2315 std::stringstream errstr;
2316 errstr <<
"cannot cast attribute " << std::endl;
2317 throw Exception(
"TBaseSet::Attributes(otherset)", errstr.str(), 63);
2320 if(
typeid(*this->AttributeType())==
typeid(
const AttributeVoid))
return;
2322 this->Detach(AttrIncl);
2325 while ((it1 != pSet->end()) && (it2 != rOtherSet.
pSet->end())) {
2329 else if (*it1 == *it2) {
2330 DoAttribute(*it1,&rOtherSet.
Attribute(*it2));
2338 FD_DC(
"TBaseSet::Attributes(): copy ok");
2346 std::stringstream errstr;
2347 errstr <<
"cannot get attribute for TBaseSet \"" << mObjectName <<
"\" type " <<
typeid(*this).name();
2348 throw Exception(
"TBaseSet::Attributep(rElem)", errstr.str(), 63);
2362 TEMP void THIS::Attribute(
const T& rElem,
const Type& rAttr) {
2365 #ifdef FAUDES_CHECKED
2366 if (!Exists(rElem)) {
2367 std::stringstream errstr;
2368 errstr <<
"element not member of set" << std::endl;
2369 throw Exception(
"TBaseSet::Attribute(elem,attr)", errstr.str(), 60);
2372 if(!AttributeTest(rAttr)) {
2373 std::stringstream errstr;
2374 errstr <<
"cannot cast attribute " << std::endl;
2375 throw Exception(
"TBaseSet::Attribute(elem,attr)", errstr.str(), 63);
2382 TEMP void THIS::ClrAttribute(
const T& rElem) {
2391 ait=this->pAttributes->find(rElem);
2392 if(ait==this->pAttributes->end())
return NULL;
2398 FD_DC(
"TBaseSet::DoAttributeExplicit(elem)");
2399 #ifdef FAUDES_DEBUG_CODE
2400 if(this->pAttributes!=this->mpAttributes) {
2401 FD_ERR(
"TBaseSet::DoAttributeExplicit(elem): attributes not detached");
2406 ait=this->pAttributes->find(rElem);
2407 if(ait!=this->pAttributes->end())
2411 FD_DC(
"TBaseSet::DoAttributeExplicit(Elem): inserting explicit default " << attr <<
" type " <<
typeid(*attr).name());
2412 (*this->pAttributes)[rElem]=attr;
2417 TEMP void THIS::DoAttribute(
const T& rElem,
const Type* pAttr) {
2418 FD_DC(
"TBaseSet::DoAttribute([v] " << this->Str(rElem) <<
", ...)");
2419 #ifdef FAUDES_DEBUG_CODE
2420 if(this->pAttributes!=this->mpAttributes) {
2421 FD_ERR(
"TBaseSet::DoAttribute([v] set): attributes not detached");
2427 if(!this->AttributeType()->Cast(pAttr)) newattr=NULL;
2431 ait=this->pAttributes->find(rElem);
2432 if(ait!=this->pAttributes->end() )
2433 oldattr=ait->second;
2436 FD_DC(
"TBaseSet::DoAttribute([v] " << this->Str(rElem) <<
", ...): default 1");
2437 if(oldattr==NULL)
return;
2439 this->pAttributes->erase(ait);
2444 FD_DC(
"TBaseSet::DoAttribute([v] " << this->Str(rElem) <<
", ...): default 2");
2445 if(oldattr==NULL)
return;
2447 this->pAttributes->erase(ait);
2450 FD_DC(
"TBaseSet::DoAttribute([v] " << this->Str(rElem) <<
", ...): " << newattr->
ToString());
2455 (*this->pAttributes)[rElem]=attr;
2459 FD_DC(
"TBaseSet::DoAttribute([v] " << this->Str(rElem) <<
", ...): " << newattr->
ToString());
2460 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
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 * > * mpAttributes
std::list< TBaseSet< T, Cmp > * >::iterator mClientRecord
std::set< Iterator * > mIterators
std::set< T, Cmp >::iterator iterator
std::set< T, Cmp > * mpSet
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
std::string FileLine(void) const
bool Eos(const std::string &rLabel)
void ReadEnd(const std::string &rLabel)
void ReadBegin(const std::string &rLabel)
void WriteComment(const std::string &rComment)
void Write(Token &rToken)
void WriteEnd(const std::string &rLabel)
void WriteBegin(const std::string &rLabel)
const std::string & StringValue(void) const
@ Begin
<label> (begin of section)
bool ExistsAttributeString(const std::string &name)
const std::string & AttributeStringValue(const std::string &name)
TokenType Type(void) const
void ElementType(const std::string &rTypeName, const std::string &rElementType)
static TypeRegistry * G()
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
virtual void XWrite(const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0) const
virtual Type & Assign(const Type &rSrc)
virtual Type * New(void) const
virtual Type * Copy(void) const
void Write(const Type *pContext=0) const
virtual bool Insert(const T &rElem)
bool DoEqual(const TBaseSet &rOtherSet) const
virtual const AttributeVoid * AttributeType(void) const
void DoAttribute(const T &rElem, const Type *pAttr)
virtual TBaseSet & AssignWithoutAttributes(const TBaseSet &rSourceSet)
void DoAssign(const TBaseSet &rSourceSet)
void Detach(DetachMode flag=AttrIncl) const
bool SetInclusion(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB)
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
void AttachClient(TBaseSet *pRef) const
bool SetEquality(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB)
virtual void DoReadElement(TokenReader &rTr, T &rElem, const std::string &rLabel, const Type *pContext)
void DetachClient(TBaseSet *pRef) const
void SetDifference(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB, TBaseSet< T, Cmp > &rRes)
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
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
static std::set< T, Cmp > msEmptySet
virtual bool AttributeTest(const Type &rAttr) const
TBaseSet(const std::string &rFilename, const std::string &rLabel="BaseSet")
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 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 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)