25 #ifndef FAUDES_BASESET_H
26 #define FAUDES_BASESET_H
43 template<
class T,
class Attr,
class Cmp>
class TAttrMap;
92 template<
class T,
class Cmp=std::less<T> >
100 template<
class TP,
class AP,
class CP>
friend class TAttrMap;
126 TBaseSet(
const std::string& rFilename,
const std::string& rLabel =
"BaseSet");
139 const std::string&
Name(
void)
const;
147 void Name(
const std::string& rName);
153 virtual void Clear(
void);
169 bool Empty(
void)
const;
181 virtual std::string
Str(
const T& rElem)
const;
195 Iterator
Begin(
void)
const;
203 Iterator
End(
void)
const;
216 virtual bool Valid(
const T& rElem)
const;
227 virtual bool Erase(
const T& rElem);
238 virtual Iterator
Erase(
const Iterator& pos);
266 virtual bool Insert(
const T& rElem);
279 virtual Iterator
Inject(
const Iterator& pos,
const T& rElem);
288 virtual void Inject(
const T& rElem);
309 bool Exists(
const T& rElem)
const;
320 Iterator
Find(
const T& rElem)
const;
357 void DValid(
const std::string& rMessage=
"")
const;
364 void Lock(
void)
const;
392 const typename std::set<T,Cmp>::const_iterator& sit,
398 if(pBaseSet && att) {
423 std::stringstream rstr;
432 #ifdef FAUDES_DEBUG_CODE
434 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator= invalid iterator: no baseset");
457 void StlIterator(
const typename std::set<T,Cmp>::const_iterator& sit) {
462 const typename std::set<T,Cmp>::const_iterator&
StlIterator(
void)
const {
481 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):DValid(): invalid iterator: no baseset");
489 #ifdef FAUDES_DEBUG_CODE
491 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator->: invalid iterator: no baseset");
500 #ifdef FAUDES_DEBUG_CODE
502 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator*: invalid iterator: no baseset");
511 #ifdef FAUDES_DEBUG_CODE
513 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator==: invalid iterator: no baseset");
517 return *
static_cast< const typename std::set<T,Cmp>::const_iterator *
>(
this) == rOther;
522 #ifdef FAUDES_DEBUG_CODE
524 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator!=: invalid iterator: no baseset");
528 return *
static_cast< const typename std::set<T,Cmp>::const_iterator *
>(
this) != rOther;
533 #ifdef FAUDES_DEBUG_CODE
535 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator++: invalid iterator: no baseset");
546 #ifdef FAUDES_DEBUG_CODE
548 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator++: invalid iterator: no baseset");
558 #ifdef FAUDES_DEBUG_CODE
560 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator--: invalid iterator: no baseset");
571 #ifdef FAUDES_DEBUG_CODE
573 FD_ERR(
"TBaseSet<T,Cmp>::Iterator(" <<
this <<
"):operator--: invalid iterator: no baseset");
596 #ifdef DONT_TRACK_REFERENCES
616 Iterator(
const typename std::set<T,Cmp>::const_iterator& sit) :
623 const typename std::set<T,Cmp>::const_iterator& sit) :
628 void StlIterator(
const typename std::set<T,Cmp>::const_iterator& sit) {
633 const typename std::set<T,Cmp>::const_iterator&
StlIterator(
void)
const {
731 virtual AttributeVoid*
Attributep(
const T& rElem);
743 virtual const AttributeVoid&
Attribute(
const T& rElem)
const;
771 virtual void AttributeTry(
const T& rElem,
const Type& rAttr) { (void) rElem; (void) rAttr; };
803 virtual const std::string&
TypeName(
void)
const;
812 virtual void TypeName(
const std::string& rType);
909 typedef typename std::set<T,Cmp>::iterator
iterator;
926 typedef typename std::map<T,AttributeVoid*>::iterator
aiterator;
973 virtual const std::string&
XElementTag(
void)
const;
1011 template<
class T,
class Cmp>
1013 FD_DC(
"FAUDES_DEBUG_CONTAINER: SetUnion(TBaseSet<T,Cmp>): res at " << &rRes);
1017 if(&rSetA==&rSetB && &rSetA==&rRes) {rRes.
Name(name);
return;}
1019 if(&rSetA==&rSetB) {rRes.
Assign(rSetA); rRes.
Name(name);
return;}
1021 if(&rSetA==&rRes) {rRes.
InsertSet(rSetB); rRes.
Name(name);
return;};
1023 if(&rSetB==&rRes) {rRes.
InsertSet(rSetA); rRes.
Name(name);
return;};
1028 FD_DC(
"FAUDES_DEBUG_CONTAINER: SetUnion(TBaseSet<T,Cmp>): done, res at " << &rRes <<
" #" << rRes.
Size());
1041 template<
class T,
class Cmp >
1046 if(&rSetA==&rSetB && &rSetA==&rRes) {rRes.
Name(name);
return;}
1048 if(&rSetA==&rSetB) { rRes.
Assign(rSetA); rRes.
Name(name);
return;}
1050 if(&rSetA==&rRes) {rRes.
RestrictSet(rSetB); rRes.
Name(name);
return;};
1052 if(&rSetB==&rRes) {rRes.
RestrictSet(rSetA); rRes.
Name(name);
return;};
1070 template<
class T,
class Cmp >
1075 if(&rSetA==&rSetB) { rRes.
Clear(); rRes.
Name(name);
return;}
1077 if(&rSetA==&rRes) {rRes.
EraseSet(rSetB); rRes.
Name(name);
return;};
1104 template<
class T,
class Cmp >
1106 return rSetA==rSetB;
1120 template<
class T,
class Cmp >
1122 return rSetA<=rSetB;
1145 #define THIS TBaseSet<T,Cmp>
1146 #define TEMP template<class T, class Cmp>
1165 TEMP std::set<T,Cmp> THIS::msEmptySet=std::set<T,Cmp>();
1166 TEMP std::map<T,AttributeVoid*> THIS::msEmptyAttributes=std::map<T,AttributeVoid*>();
1173 pAttributes(&msEmptyAttributes),
1176 mpClients(new std::list<
TBaseSet<T,Cmp>* >),
1179 pTypeDefinition(NULL)
1182 FD_DC(
"TBaseSet(" <<
this <<
")::TBaseSet()");
1188 TEMP THIS::TBaseSet(
const std::string& rFileName,
const std::string& rLabel) :
1192 pAttributes(&msEmptyAttributes),
1195 mpClients(new std::list<
TBaseSet<T,Cmp>* >),
1198 pTypeDefinition(NULL)
1201 FD_DC(
"TBaseSet(" <<
this <<
")::TBaseSet()");
1205 Read(rFileName,rLabel);
1213 pAttributes(&msEmptyAttributes),
1216 mpClients(new std::list<
TBaseSet<T,Cmp>* >),
1219 pTypeDefinition(NULL)
1222 FD_DC(
"TBaseSet(" <<
this <<
")::TBaseSet(rOtherSet " << &rOtherSet <<
"): fake copy construct");
1225 #ifdef FAUDES_DEBUG_CODE
1233 FD_DC(
"TBaseSet(" <<
this <<
")::~TBaseSet()");
1236 pHostSet->DetachClient(
this);
1237 if(mpClients)
delete mpClients;
1240 typename std::set< Iterator* >::const_iterator iit;
1241 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1242 (**iit).Invalidate();
1245 if(mpSet)
delete mpSet;
1247 for(
aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait)
1249 delete mpAttributes;
1256 FD_DC(
"TBaseSet(" <<
this <<
"/" << this->Name() <<
")::DoAssign(rOtherSet " << &rSourceSet <<
"): shallow copy -- src attr# " << rSourceSet.pAttributes->size());
1257 FD_DC(
"TBaseSet():DoAssign(): " <<
typeid(*this->AttributeType()).name() <<
" <== " <<
typeid(*rSourceSet.AttributeType()).name());
1259 if(
this==&rSourceSet)
return;
1261 mMyName=rSourceSet.mMyName;
1263 if(pHostSet==rSourceSet.pHostSet)
return;
1266 pHostSet->DetachClient(
this);
1273 for(
aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait)
1275 delete mpAttributes;
1284 if(
typeid(*rSourceSet.AttributeType())==
typeid(*this->AttributeType())) {
1285 pHostSet=rSourceSet.pHostSet;
1286 pHostSet->AttachClient(
this);
1287 pSet=rSourceSet.pSet;
1288 pAttributes=rSourceSet.pAttributes;
1292 mpSet =
new std::set<T,Cmp>();
1293 *mpSet = *rSourceSet.pSet;
1295 mpAttributes =
new std::map<T,AttributeVoid*>();
1296 if(
typeid(*this->AttributeType()) !=
typeid(
const AttributeVoid)) {
1297 for(
aiterator ait=rSourceSet.pAttributes->begin(); ait!=rSourceSet.pAttributes->end(); ++ait) {
1299 (*mpAttributes)[ait->first]=attr;
1302 pAttributes = mpAttributes;
1306 typename std::set< Iterator* >::iterator iit;
1307 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1308 (**iit).Invalidate();
1318 #ifdef FAUDES_DEBUG_CODE
1319 DValid(
"PostFakeAssignment");
1321 FD_DC(
"TBaseSet(" <<
this <<
")::DoAssign(rOtherSet " << &rSourceSet <<
"): fake copy -- done with attr# " << pAttributes->size());
1326 FD_DC(
"TBaseSet(" <<
this <<
")::Detach(void)");
1327 #ifdef FAUDES_DEBUG_CODE
1328 DValid(
"PreDetach");
1333 if(flag==SetOnly) pAttributes->clear();
1338 THIS* fake_const =
const_cast< THIS*
>(
this);
1340 #ifdef FAUDES_DEBUG_CODE
1343 if(pSet!=&msEmptySet)
1345 if(mpClients->empty()) {
1346 FD_ERR(
"TBaseSet(" <<
this <<
")::Detach(): missed detach (?)");
1348 fake_const->mDetached=
true;
1353 std::set<T,Cmp>* scopy =
new std::set<T,Cmp>();
1357 std::map<T,AttributeVoid*>* acopy =
new std::map<T,AttributeVoid*>();
1358 if(flag==AttrIncl) {
1359 for(
aiterator ait=pAttributes->begin(); ait!=pAttributes->end(); ++ait) {
1361 (*acopy)[ait->first]=attr;
1370 FD_DC(
"TBaseSet(" <<
this <<
")::Detach(): allocate and copy, strategie A");
1372 THIS* newhost = *mpClients->begin();
1373 #ifdef FAUDES_DEBUG_CODE
1374 if(newhost->mpClients)
1375 FD_ERR(
"TBaseSet(" <<
this <<
")::Detach(): new host used to heve clients (?)");
1377 newhost->pHostSet=newhost;
1378 newhost->mpSet=scopy;
1379 newhost->pSet=scopy;
1380 newhost->mpAttributes=acopy;
1381 newhost->pAttributes=acopy;
1382 newhost->mpClients=mpClients;
1383 newhost->DetachClient(newhost);
1385 typename std::list< THIS* >::const_iterator rit;
1386 for(rit=newhost->mpClients->begin();rit!=newhost->mpClients->end(); ++rit) {
1387 (*rit)->pHostSet=newhost;
1388 (*rit)->pSet=newhost->pSet;
1389 (*rit)->pAttributes=newhost->pAttributes;
1392 typename std::set< Iterator* >::iterator iit;
1393 for(rit=newhost->mpClients->begin(); rit!=newhost->mpClients->end(); ++rit) {
1394 for(iit=(*rit)->mIterators.begin(); iit!=(*rit)->mIterators.end(); ++iit) {
1395 if((**iit).StlIterator()==pSet->end())
1396 **iit=
Iterator(
this, scopy->end());
1398 **iit=
Iterator(
this, scopy->find(***iit));
1402 for(iit=newhost->mIterators.begin(); iit!=newhost->mIterators.end(); ++iit) {
1403 if((**iit).StlIterator()==pSet->end())
1404 **iit=
Iterator(
this, scopy->end());
1406 **iit=
Iterator(
this, scopy->find(***iit));
1409 fake_const->mpSet=pSet;
1410 fake_const->mpAttributes=pAttributes;
1411 fake_const->mpClients=
new std::list< TBaseSet<T,Cmp>* >;
1412 fake_const->mDetached=
true;
1414 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit)
1416 fake_const->mIterators.clear();
1424 FD_DC(
"TBaseSet(" <<
this <<
")::Detach(): allocate and copy, strategie B");
1426 fake_const->RelinkClients();
1427 pHostSet->DetachClient(fake_const);
1429 fake_const->mpSet = scopy;
1430 fake_const->mpAttributes=acopy;
1432 typename std::set< Iterator* >::iterator iit;
1433 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1434 if((**iit).StlIterator()==pSet->end())
1435 **iit=
Iterator(
this, mpSet->end());
1437 **iit=
Iterator(
this, mpSet->find(***iit));
1440 fake_const->pHostSet=fake_const;
1441 fake_const->pSet=mpSet;
1442 fake_const->pAttributes=mpAttributes;
1443 fake_const->mDetached=
true;
1444 if(fake_const->mpClients)
delete fake_const->mpClients;
1445 fake_const->mpClients=
new std::list< TBaseSet<T,Cmp>* >;
1449 #ifdef FAUDES_DEBUG_CODE
1450 DValid(
"PostDetach");
1452 FD_DC(
"TBaseSet(" <<
this <<
")::Detach(): done");
1457 FD_DC(
"TBaseSet(" <<
this <<
")::Lock(void)");
1458 #ifdef FAUDES_DEBUG_CODE
1468 THIS* fake_const =
const_cast< THIS*
>(
this);
1471 typename std::set< Iterator* >::const_iterator iit;
1472 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1475 fake_const->mIterators.clear();
1478 fake_const->mLocked=
true;
1480 #ifdef FAUDES_DEBUG_CODE
1487 TEMP inline void THIS::RelinkClients(
void) {
1488 FD_DC(
"TBaseSet::RelinkClients(" <<
this <<
")")
1489 #ifdef FAUDES_DEBUG_CODE
1490 DValid(
"PreRelink");
1494 if(!mpClients)
return;
1496 if(mpClients->empty())
return;
1498 FD_DC(
"TBaseSet::RelinkClients(" <<
this <<
"): doit")
1501 THIS* newhost = *mpClients->begin();
1502 #ifdef FAUDES_DEBUG_CODE
1503 if(newhost->pHostSet!=
this)
1504 FD_ERR(
"BaseSet::RelinkRefernces: old reference must have this as provider");
1505 if(newhost->mpClients)
1506 FD_ERR(
"TBaseSet(" <<
this <<
")::RelinkClients(void): client is a host (?)");
1508 newhost->pHostSet=newhost;
1509 newhost->mpSet=mpSet;
1511 newhost->mpAttributes=mpAttributes;
1512 newhost->pAttributes=pAttributes;
1513 newhost->mpClients=mpClients;
1514 newhost->DetachClient(newhost);
1516 typename std::list< THIS* >::const_iterator rit;
1517 for(rit=newhost->mpClients->begin();rit!=newhost->mpClients->end(); ++rit) {
1518 (*rit)->pHostSet=newhost;
1524 pAttributes=newhost->pAttributes;
1526 newhost->AttachClient(
this);
1528 #ifdef FAUDES_DEBUG_CODE
1529 DValid(
"PostRelink");
1531 FD_DC(
"TBaseSet::RelinkClients(" <<
this <<
"): done")
1538 const_cast< THIS*
>(
this)->mpClients->push_back(pRef);
1540 const_cast< THIS*
>(
this)->mDetached=
false;
1545 FD_DC(
"TBaseSet::DetachClient(" <<
this <<
"):" << pRef);
1547 if(!mpClients)
return;
1548 if(mpClients->empty())
return;
1551 THIS* fake_const =
const_cast< THIS*
>(
this);
1552 #ifdef FAUDES_DEBUG_CODE
1554 typename std::list< TBaseSet<T,Cmp>* >
::iterator cit;
1556 for(cit=fake_const->mpClients->begin(); cit!=fake_const->mpClients->end(); ++cit) {
1557 if(*cit==pRef) cf=
true;
1560 FD_ERR(
"TBaseSet::DetachClient(" <<
this <<
"): client not found " << pRef);
1573 typename std::list< TBaseSet<T,Cmp>* >
::iterator rit;
1574 for(rit=fake_const->mpClients->begin(); rit!=fake_const->mpClients->end(); ++rit) {
1575 if(*rit!=pRef)
continue;
1576 fake_const->mpClients->erase(rit);
1580 if(mpClients->empty() && (pSet!=&msEmptySet)) fake_const->mDetached=
true;
1581 FD_DC(
"TBaseSet::DetachClient(" <<
this <<
"): done.");
1588 FD_DC(
"TBaseSet::AttachIterator(" <<
this <<
"):" << pFit)
1589 const_cast< THIS*
>(
this)->mIterators.insert(pFit);
1595 FD_DC(
"TBaseSet::DetachIterator(" <<
this <<
"):" << pFit)
1596 const_cast< THIS*
>(
this)->mIterators.erase(pFit);
1600 TEMP void THIS::DValid(
const std::string& rMessage)
const {
1601 typename std::set< Iterator* >::const_iterator iit;
1602 typename std::list< THIS* >::const_iterator rit;
1603 #ifdef FAUDES_DEBUG_CONTAINER
1604 std::cerr <<
"TBaseSet(" <<
this <<
")::DValid(): " << rMessage <<
" source "
1605 << pHostSet <<
" " << (pHostSet->pSet==&msEmptySet ?
"+e+" :
"+f+") <<
1606 (mLocked ?
" +l+" :
" ") << (mDetached ?
" +d+" :
" ") <<
" -- refs ";
1607 if(pHostSet->mpClients)
1608 for(rit=pHostSet->mpClients->begin(); rit!=pHostSet->mpClients->end(); ++rit)
1609 std::cerr << *rit <<
" ";
1610 std::cerr <<
"-- its ";
1611 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit)
1612 std::cerr << *iit <<
" ";
1613 std::cerr <<
"-- attr #" << pAttributes->size();
1614 if(mpAttributes) std::cerr <<
"(" << mpAttributes->size() <<
") ";
1615 else std::cerr <<
" ";
1616 std::cerr << (pAttributes==&msEmptyAttributes ?
"+e+ " :
"+f+ ") << std::endl;
1619 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1620 if((*iit)->pBaseSet!=
this) {
1621 FD_WARN(
"BaseSet("<<
this <<
"," << rMessage <<
"): invalid iterator (baseset): "<< *iit);
1626 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1627 if(!(*iit)->mAttached) {
1628 FD_WARN(
"BaseSet("<<
this <<
"," << rMessage <<
"): invalid iterator (attached): "<< *iit);
1633 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1634 typename std::set<T,Cmp>::const_iterator vit;
1635 for(vit=pSet->begin(); vit!= pSet->end(); ++vit) {
1636 if(vit==(**iit).StlIterator())
break;
1638 if(vit!=(**iit).StlIterator()) {
1639 FD_WARN(
"BaseSet("<<
this <<
"," << rMessage <<
"): invalid iterator (stl) "<< *iit);
1640 (**iit).StlIterator(pSet->end());
1645 if(pHostSet==NULL) {
1646 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): no host found");
1650 if(pHostSet->pHostSet != pHostSet) {
1651 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): inconsistent host");
1655 if((mpSet!=NULL) && (pHostSet !=
this)) {
1656 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): double data");
1660 if(pHostSet!=
this && mpClients!=NULL) {
1661 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): cannot be client and have clients oneself");
1665 if(pHostSet->mpClients==NULL) {
1666 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): refers to invalid host (a)");
1670 if(pHostSet!=
this && pHostSet->mpClients->empty()) {
1671 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): refers to invalid host (b)");
1675 if((pHostSet ==
this) && (mpSet==NULL) && (pSet!=&msEmptySet)) {
1676 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): no data");
1680 if((pHostSet==
this) && (pSet!=&msEmptySet) && (mpClients==NULL)) {
1681 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): host with no client list");
1685 if((pHostSet ==
this) && (pSet != mpSet) && (pSet!=&msEmptySet)) {
1686 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): data pointer mismatch A");
1690 if(pSet != pHostSet->pSet) {
1691 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): data pointer mismatch B");
1696 for(rit=pHostSet->mpClients->begin(); rit!=pHostSet->mpClients->end(); ++rit) {
1697 if((*rit)==
this) hf=
true;
1698 if((*rit)->pHostSet== pHostSet)
continue;
1699 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): invalid client " << (*rit));
1702 if(!hf && (pHostSet!=
this)) {
1703 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): client not registered with host");
1707 if(pHostSet!=
this && *mClientRecord!=
this) {
1708 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): refers to invalid host (c)");
1712 if(mDetached && mpClients==NULL) {
1713 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): invalid detached flag A");
1717 if(mDetached && !mpClients->empty()) {
1718 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): invalid detached flag B");
1722 if(mDetached && (pSet==&msEmptySet)) {
1723 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): detached empty set");
1727 if(mLocked && (mpClients==NULL)) {
1728 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): locked reference (a)");
1732 if(!msEmptySet.empty()) {
1733 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): invalid empty set");
1737 if(!msEmptyAttributes.empty()) {
1738 FD_WARN(
"BaseSet(" <<
this <<
"," << rMessage <<
"): invalid empty attributes");
1741 #ifdef FAUDES_DEBUG_CONTAINER
1742 std::cerr <<
"TBaseSet(" <<
this <<
")::DValid(): passed" << std::endl;
1749 TEMP const std::string& THIS::Name(
void)
const {
1754 TEMP void THIS::Name(
const std::string& rName) {
1762 if(!pTypeDefinition) {
1764 THIS* fake_const =
const_cast< THIS*
>(
this);
1767 return pTypeDefinition;
1771 TEMP const std::string& THIS::XElementTag(
void)
const {
1772 if(mXElementTag.empty()) {
1774 THIS* fake_const =
const_cast< THIS*
>(
this);
1775 fake_const->mXElementTag=
"Element";
1777 if(fdp) fake_const->mXElementTag=fdp->
XElementTag();
1779 return mXElementTag;
1783 TEMP void THIS::XElementTag(
const std::string& rTag) {
1789 TEMP const std::string& THIS::TypeName(
void)
const {
1790 if(mFaudesTypeName.empty()) {
1792 THIS* fake_const =
const_cast< THIS*
>(
this);
1794 if(fdp) fake_const->mFaudesTypeName=fdp->
Name();
1796 return mFaudesTypeName;
1800 TEMP void THIS::TypeName(
const std::string& rType) {
1801 mFaudesTypeName=rType;
1806 TEMP std::string THIS::Str(
const T& rElem)
const {
1814 return (
Idx) pSet->size();
1818 TEMP bool THIS::Empty(
void)
const {
1819 return pSet->empty();
1826 std::string label=rLabel;
1827 if(label==
"") label=Name();
1828 if(label==
"") label=
"BaseSet";
1829 FD_DC(
"TBaseSet(" <<
this <<
")::DoWrite(..): section " << label <<
" #" << Size());
1839 BASE::DoSWrite(rTw);
1841 if(pHostSet->mpClients) shares=pHostSet->mpClients->size();
1848 #ifdef FAUDES_DEBUG_CODE
1855 BASE::DoSWrite(rTw);
1857 if(pHostSet->mpClients) shares=pHostSet->mpClients->size();
1860 if(pAttributes->size()!=0)
1862 if(pAttributes->size()!=0) {
1871 std::string label=rLabel;
1872 if(label==
"") label=Name();
1873 if(label==
"") label=
"BaseSet";
1880 TEMP typename THIS::Iterator THIS::ThisIterator(
const typename std::set<T,Cmp>::const_iterator& sit)
const {
1885 TEMP inline typename THIS::Iterator THIS::Begin(
void)
const {
1886 return ThisIterator(pSet->begin());
1890 TEMP inline typename THIS::Iterator THIS::End(
void)
const {
1891 return ThisIterator(pSet->end());
1897 FD_DC(
"TBaseSet(" <<
this <<
")::Clear()");
1898 #ifdef FAUDES_DEBUG_CODE
1902 if(pSet==&msEmptySet)
return;
1904 FD_DC(
"TBaseSet(" <<
this <<
")::Clear(): doit");
1905 FD_DC(
"TBaseSet(" <<
this <<
")::Clear(): type " <<
typeid(*this).name());
1907 if(mLocked) Detach(SetOnly);
1910 pHostSet->DetachClient(
this);
1913 if(!mpClients) mpClients=
new std::list< TBaseSet<T,Cmp>* >;
1922 for(
aiterator ait=mpAttributes->begin(); ait!=mpAttributes->end(); ++ait) {
1923 FD_DC(
"TBaseSet(" <<
this <<
")::Clear(): del attr " << ait->second);
1926 delete mpAttributes;
1931 pAttributes=&msEmptyAttributes;
1933 typename std::set< Iterator* >::iterator iit;
1934 for(iit=mIterators.begin(); iit!=mIterators.end(); ++iit) {
1935 (**iit).Invalidate();
1940 #ifdef FAUDES_DEBUG_CODE
1941 DValid(
"PostClear");
1943 FD_DC(
"TBaseSet(" <<
this <<
")::Clear(): done");
1948 TEMP inline bool THIS::Valid(
const T& rElem)
const {
1954 TEMP bool THIS::Insert(
const T& rElem) {
1955 #ifdef FAUDES_CHECKED
1957 std::stringstream errstr;
1958 errstr <<
"refuse to insert invalid element" << std::endl;
1959 throw Exception(
"BaseSet::Insert", errstr.str(), 61);
1962 if(!mDetached) Detach();
1963 return pSet->insert(rElem).second;
1967 TEMP typename THIS::Iterator THIS::Inject(
const Iterator& pos,
const T& rElem) {
1968 if(!mDetached) Detach();
1970 return ThisIterator(pSet->insert(dst,rElem));
1975 TEMP void THIS::Inject(
const T& rElem) {
1976 if(!mDetached) Detach();
1977 pSet->insert(pSet->end(),rElem);
1982 FD_DC(
"TBaseSet(" <<
this <<
")::InsertSet(" << &rOtherSet <<
")");
1983 if(!mDetached) Detach();
1992 while ((it1 != pSet->end()) && (it2 != rOtherSet.
pSet->end())) {
1996 else if (*it1 == *it2) {
2005 while (it2 != rOtherSet.
pSet->end()) {
2013 TEMP bool THIS::Erase(
const T& rElem) {
2014 if(!mDetached) Detach();
2015 return (pSet->erase(rElem)!=0);
2021 #ifdef FAUDES_CHECKED
2023 std::stringstream errstr;
2024 errstr <<
"iterator out of range " << std::endl;
2025 throw Exception(
"BaseSet::Erase", errstr.str(), 62);
2031 return ThisIterator(del);
2037 FD_DC(
"TBaseSet(" <<
this <<
")::EraseSet(" << &rOtherSet <<
")");
2038 if(!mDetached) Detach();
2042 while ((it != pSet->end()) && (oit != rOtherSet.
pSet->end())) {
2044 it=pSet->lower_bound(*oit);
2046 else if (*it == *oit) {
2051 oit=rOtherSet.
pSet->lower_bound(*it);
2059 FD_DC(
"TBaseSet(" <<
this <<
")::RestrictSet(" << &rOtherSet <<
")");
2060 if(!mDetached) Detach();
2064 while ((it != pSet->end()) && (oit != rOtherSet.
pSet->end())) {
2068 else if (*it == *oit) {
2073 oit=rOtherSet.
pSet->lower_bound(*it);
2076 while(it != pSet->end()) {
2083 TEMP typename THIS::Iterator THIS::Find(
const T& rElem)
const {
2084 return ThisIterator(pSet->find(rElem));
2088 TEMP bool THIS::Exists(
const T& rElem)
const {
2089 return pSet->find(rElem) != pSet->end();
2118 FD_DC(
"TBaseSet::DoEqual()");
2120 if(pSet == rOtherSet.
pSet)
return true;
2122 return ( *pSet == *rOtherSet.
pSet );
2127 FD_DC(
"BaseSet::op<=()");
2128 return ( std::includes(rOtherSet.
pSet->begin(), rOtherSet.
pSet->end(), pSet->begin(), pSet->end()) ) ;
2133 FD_DC(
"BaseSet::op>=()");
2134 return ( std::includes(pSet->begin(), pSet->end(), rOtherSet.
pSet->begin(), rOtherSet.
pSet->end()) );
2139 return *pSet < *rOtherSet.
pSet;
2150 TEMP bool THIS::AttributeTest(
const Type& rAttr)
const {
2151 return AttributeType()->Cast(&rAttr)!=NULL;
2156 return (
Idx) pAttributes->size();
2160 TEMP void THIS::ClearAttributes(
void) {
2162 if(this->pAttributes->size()==0)
return;
2164 this->Detach(SetOnly);
2170 FD_DC(
"TBaseSet::EqualAttributes(TBaseSet)");
2172 FD_DC(
"TBaseSet::EqualAttributes(TBaseSet): 1");
2173 if(
typeid(*rOtherSet.
AttributeType())!=
typeid(*this->AttributeType()))
2176 FD_DC(
"TBaseSet::EqualAttributes(TBaseSet): 2");
2180 FD_DC(
"TBaseSet::EqualAttributes(TBaseSet): 3");
2182 if(this->AttributesSize()==0)
2187 while ((ait1 != pAttributes->end()) && (ait2 != rOtherSet.
pAttributes->end())) {
2188 if (ait1->first < ait2->first) {
2191 else if (ait1->first == ait2->first) {
2192 FD_DC(
"TBaseSet::EqualAttributes(TBaseSet): cmp " << ait1->second->ToString()
2193 <<
" vs " << ait2->second->ToString());
2194 if( ! ait1->second->Equal(*ait2->second))
return false;
2203 FD_DC(
"TBaseSet::EqualAttributes(TBaseSet): pass");
2212 this->DoAssign(rSourceSet);
2214 this->Detach(SetOnly);
2220 FD_DC(
"TBaseSet::Attributes("<<
this<<
")");
2223 std::stringstream errstr;
2224 errstr <<
"cannot cast attribute " << std::endl;
2225 throw Exception(
"TBaseSet::Attributes(otherset)", errstr.str(), 63);
2228 if(
typeid(*this->AttributeType())==
typeid(
const AttributeVoid))
return;
2230 this->Detach(AttrIncl);
2233 while ((it1 != pSet->end()) && (it2 != rOtherSet.
pSet->end())) {
2237 else if (*it1 == *it2) {
2238 DoAttribute(*it1,&rOtherSet.
Attribute(*it2));
2246 FD_DC(
"TBaseSet::Attributes(): copy ok");
2254 std::stringstream errstr;
2255 errstr <<
"cannot get attribute for TBaseSet \"" << mMyName <<
"\" type " <<
typeid(*this).name();
2256 throw Exception(
"TBaseSet::Attributep(rElem)", errstr.str(), 63);
2270 TEMP void THIS::Attribute(
const T& rElem,
const Type& rAttr) {
2273 #ifdef FAUDES_CHECKED
2274 if (!Exists(rElem)) {
2275 std::stringstream errstr;
2276 errstr <<
"element not member of set" << std::endl;
2277 throw Exception(
"TBaseSet::Attribute(elem,attr)", errstr.str(), 60);
2280 if(!AttributeTest(rAttr)) {
2281 std::stringstream errstr;
2282 errstr <<
"cannot cast attribute " << std::endl;
2283 throw Exception(
"TBaseSet::Attribute(elem,attr)", errstr.str(), 63);
2290 TEMP void THIS::ClrAttribute(
const T& rElem) {
2299 ait=this->pAttributes->find(rElem);
2300 if(ait==this->pAttributes->end())
return NULL;
2306 FD_DC(
"TBaseSet::DoAttributeExplicit(elem)");
2307 #ifdef FAUDES_DEBUG_CODE
2308 if(this->pAttributes!=this->::mpAttributes) {
2309 FD_ERR(
"TBaseSet::DoAttributeExplicit(elem): attributes not detached");
2314 ait=this->pAttributes->find(rElem);
2315 if(ait!=this->pAttributes->end())
2319 FD_DC(
"TBaseSet::DoAttributeExplicit(Elem): inserting explicit default " << attr <<
" type " <<
typeid(*attr).name());
2320 (*this->pAttributes)[rElem]=attr;
2325 TEMP void THIS::DoAttribute(
const T& rElem,
const Type* pAttr) {
2326 FD_DC(
"TBaseSet::DoAttribute([v] " << this->Str(rElem) <<
", ...)");
2327 #ifdef FAUDES_DEBUG_CODE
2328 if(this->pAttributes!=this->mpAttributes) {
2329 FD_ERR(
"TBaseSet::DoAttribute([v] set): attributes not detached");
2335 if(!this->AttributeType()->Cast(pAttr)) newattr=NULL;
2339 ait=this->pAttributes->find(rElem);
2340 if(ait!=this->pAttributes->end() )
2341 oldattr=ait->second;
2344 FD_DC(
"TBaseSet::DoAttribute([v] " << this->Str(rElem) <<
", ...): default 1");
2345 if(oldattr==NULL)
return;
2347 this->pAttributes->erase(ait);
2352 FD_DC(
"TBaseSet::DoAttribute([v] " << this->Str(rElem) <<
", ...): default 2");
2353 if(oldattr==NULL)
return;
2355 this->pAttributes->erase(ait);
2358 FD_DC(
"TBaseSet::DoAttribute([v] " << this->Str(rElem) <<
", ...): " << newattr->
ToString());
2363 (*this->pAttributes)[rElem]=attr;
2367 FD_DC(
"TBaseSet::DoAttribute([v] " << this->Str(rElem) <<
", ...): " << newattr->
ToString());
2368 oldattr->
Assign(*newattr);