cfl_nameset.cpp
Go to the documentation of this file.
1/** @file cfl_nameset.cpp @brief Classes NameSet */
2
3/* FAU Discrete Event Systems Library (libfaudes)
4
5 Copyright (C) 2006 Bernd Opitz
6 Copyright (C) 2007,2025 Thomas Moor.
7
8 Exclusive copyright is granted to Klaus Schmidt
9
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2.1 of the License, or (at your option) any later version.
14
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24
25#include "cfl_nameset.h"
26
27namespace faudes {
28
29/*
30*********************************************************************************
31*********************************************************************************
32*********************************************************************************
33
34 NameSet
35
36*********************************************************************************
37*********************************************************************************
38*********************************************************************************
39*/
40
41// register
44
45// std faudes type (cannot do New() with macro)
51
52
53// empty constructor
56 mElementTagDef="Event";
57 Name("NameSet");
58 FD_DC("NameSet("<<this<<")::NameSet() with symtab "<< mpSymbolTable);
59}
60
61// constructor from nameset
62NameSet::NameSet(const NameSet& rOtherSet) : TBaseSet<Idx>() {
63 FD_DC("NameSet(" << this << ")::NameSet(rOtherSet " << &rOtherSet << ")");
64 mpSymbolTable = rOtherSet.mpSymbolTable;
65 mElementTagDef="Event";
66 Copy(rOtherSet);
67 FD_DC("NameSet(" << this << ")::NameSet(rOtherSet " << &rOtherSet << "): done");
68}
69
70// read file constructor
71NameSet::NameSet(const std::string& rFilename, const std::string& rLabel) : TBaseSet<Idx>() {
72 FD_DC("NameSet(" << this << ")::NameSet(" << rFilename << ")");
74 mElementTagDef="Event";
75 Read(rFilename, rLabel);
76}
77
78// destructor
80 FD_DC("NameSet("<<this<<")::~NameSet()");
81}
82
83// New()
84NameSet* NameSet::New(void) const {
85 NameSet* res= new NameSet();
87 return res;
88}
89
90
91// copy (attributes to default)
92void NameSet::DoCopy(const NameSet& rSourceSet) {
93 FD_DC("NameSet(" << this << ")::DoCopy(from " << &rSourceSet <<")");
94 // fix my symboltable
96 // call base
97 TBaseSet<Idx>::DoCopy(rSourceSet);
98}
99
100// copy (attributes to default)
101void NameSet::DoMove(NameSet& rSourceSet) {
102 FD_DF("NameSet(" << this << ")::DoMove(from " << &rSourceSet <<")");
103 // fix my symboltable
104 mpSymbolTable=rSourceSet.mpSymbolTable;
105 // call base
106 TBaseSet<Idx>::DoMove(rSourceSet);
107}
108
109// Compare
110bool NameSet::DoEqual(const NameSet& rOtherSet) const {
111 FD_DC("NameSet::DoEqual()");
112#ifdef FAUDES_CHECKED
113 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
114 std::stringstream errstr;
115 errstr << "symboltable mismazch aka not implemented" << std::endl;
116 throw Exception("NameSet::DoEqual()", errstr.str(), 67);
117 }
118#endif
119 return TBaseSet<Idx>::DoEqual(rOtherSet);
120}
121
122// SymbolTablep()
124 return mpSymbolTable;
125}
126
127// SymbolTablep(pSymTab)
129 FD_DC("NameSet(" << this << ")::SymbolTablep(" << pSymTab << ")");
130 if(!Empty()) {
131 Clear();
132 }
133 mpSymbolTable=pSymTab;
134}
135
136// DoWrite(tw, rLabel)
137void NameSet::DoWrite(TokenWriter& tw, const std::string& rLabel, const Type* pContext) const {
138 std::string label=rLabel;
139 if(label=="") label=Name();
140 if(label=="") label=TypeName();
141 FD_DC("NameSet(" << this << ")::DoWrite(..): section " << label << " #" << Size());
142 tw.WriteBegin(label);
143 Token token;
144 Iterator it;
145 for (it = Begin(); it != End(); ++it) {
146#ifdef FAUDES_DEBUG_CODE
147 if (SymbolicName(*it) == "") {
148 FD_ERR("NameSet::Write(): "
149 << "index " << *it << " not in SymbolTable. aborting...");
150 abort();
151 }
152#endif
153 token.SetString(SymbolicName(*it));
154 tw << token;
155 Attribute(*it).Write(tw,"",pContext);
156 }
157 tw.WriteEnd(label);
158}
159
160// DoDWrite()
161void NameSet::DoDWrite(TokenWriter& tw, const std::string& rLabel, const Type* pContext) const {
162 std::string label=rLabel;
163 if(label=="") label=Name();
164 if(label=="") label=TypeName();
165 tw.WriteBegin(label);
166 Token token;
167 Iterator it;
168 for (it = Begin(); it != End(); ++it) {
169 tw << Str(*it);
170 Attribute(*it).Write(tw,"",pContext);
171 }
172 tw.WriteEnd(label);
173}
174
175
176// DoXWrite(tw, rLabel)
177void NameSet::DoXWrite(TokenWriter& tw, const std::string& rLabel, const Type* pContext) const {
178 // Set up outer tag
179 Token btag=XBeginTag(rLabel,"NameSet");
180 tw.Write(btag);
181 FD_DC("NameSet(" << this << ")::DoXWrite(..): section " << btag.StringValue() << " #" << Size());
182 // loop elements
183 std::string etstr=ElementTag();
184 for (Iterator it = Begin(); it != End(); ++it) {
185 Token etoken;
186 const AttributeVoid& attr=Attribute(*it);
187 // case a: no attribute value
188 if(attr.IsDefault()) {
189 etoken.SetEmpty(etstr);
190 etoken.InsAttributeString("name",SymbolicName(*it));
191 tw << etoken;
192 }
193 // case b: incl attribute value
194 if(!attr.IsDefault()) {
195 etoken.SetBegin(etstr);
196 etoken.InsAttributeString("name",SymbolicName(*it));
197 tw << etoken;
198 Attribute(*it).XWrite(tw,"",pContext);
199 etoken.SetEnd(etstr);
200 tw << etoken;
201 }
202 }
203 tw.WriteEnd(btag.StringValue());
204}
205
206// DoRead(rTr, rLabel, pContext)
207void NameSet::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
208 // set up defaults
209 std::string label=rLabel;
210 std::string ftype=TypeName();
211 std::string etstr=ElementTag();
212 // figure section
213 Token token;
214 if(label=="") {
215 rTr.Peek(token);
216 if(token.Type()==Token::Begin) label=token.StringValue();
217 }
218 if(label=="") label=ftype;
219 Name(label);
220 // read begin
221 rTr.ReadBegin(label,token);
222 if(token.ExistsAttributeString("name"))
223 Name(token.AttributeStringValue("name"));
224 FD_DC("NameSet(" << this << ")::DoRead(..): section " << label << " with symtab " << mpSymbolTable);
225 // prepare attribute
226 AttributeVoid* attrp = AttributeType()->New();
227 FD_DC("NameSet(" << this << ")::DoRead(..): attribute type " << typeid(*attrp).name());
228 // loop tokens
229 std::string name;
230 while(!rTr.Eos(label)) {
231 rTr.Peek(token);
232 // read by name (faudes format)
233 if(token.IsString()) {
234 FD_DC("TaNameSet(" << this << ")::DoRead(..): inserting element in faudes format \""
235 << token.StringValue() << "\"");
236 rTr.Get(token);
237 name=token.StringValue();
238 // read faudes attribute
239 attrp->Read(rTr,"",pContext);
240 // skip unknown faudes attributes
242 // insert element with attribute
243 Idx index=Insert(name);
244 Attribute(index,*attrp);
245 continue;
246 }
247 // read element section (XML format)
248 if(token.IsBegin(etstr)) {
249 FD_DC("TaNameSet(" << this << ")::DoRead(..): inserting element in xml format \""
250 << token.StringValue() << "\"");
251 rTr.ReadBegin(etstr,token);
252 name=token.AttributeStringValue("name");
253 // read faudes attribute
254 attrp->Read(rTr,"",pContext);
255 // skip unknown faudes attributes
256 rTr.ReadEnd(etstr);
257 // insert element with attribute
258 Idx index=Insert(name);
259 Attribute(index,*attrp);
260 continue;
261 }
262 // cannot process token
263 delete attrp;
264 std::stringstream errstr;
265 errstr << "Invalid token of type " << token.Type() << " at " << rTr.FileLine();
266 throw Exception("NameSet::DoRead", errstr.str(), 50);
267 }
268 rTr.ReadEnd(label);
269 delete attrp;
270 FD_DC("NameSet(" << this << ")::DoRead(tr," << label << ", " << pContext << "): done");
271}
272
273
274// Insert(index)
275bool NameSet::Insert(const Idx& index) {
276#ifdef FAUDES_CHECKED
277 if(!mpSymbolTable->Exists(index)) {
278 std::stringstream errstr;
279 errstr << "index " << index << " not known to symboltable" << std::endl;
280 throw Exception("NameSet::Insert", errstr.str(), 65);
281 }
282#endif
283 return TBaseSet<Idx>::Insert(index);
284}
285
286// Insert(rName)
287Idx NameSet::Insert(const std::string& rName) {
288 FD_DC("NameSet(" << this << ")::Insert(" << rName <<")");
289 Idx index = mpSymbolTable->InsEntry(rName);
291 return index;
292}
293
294// InsertSet(set)
295void NameSet::InsertSet(const TBaseSet<Idx>& rOtherSet) {
296#ifdef FAUDES_CHECKED
297 const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
298 if(!nset) {
299 std::stringstream errstr;
300 errstr << "cannot cast to nameset" << std::endl;
301 throw Exception("NameSet::InsertSet", errstr.str(), 67);
302 }
303 if(nset->mpSymbolTable!=mpSymbolTable) {
304 std::stringstream errstr;
305 errstr << "symboltable mismatch aka not implemented" << std::endl;
306 throw Exception("NameSet::InsertSet", errstr.str(), 67);
307 }
308#endif
309 TBaseSet<Idx>::InsertSet(rOtherSet);
310}
311
312
313// InsertSet(set)
314void NameSet::InsertSet(const NameSet& rOtherSet) {
315 FD_DC("NameSet(" << this << ")::InsertSet(" << rOtherSet.ToString() << ")");
316#ifdef FAUDES_CHECKED
317 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
318 std::stringstream errstr;
319 errstr << "symboltable mismatch aka not implemented" << std::endl;
320 throw Exception("NameSet::InsertSet", errstr.str(), 67);
321 }
322#endif
323 TBaseSet<Idx>::InsertSet(rOtherSet);
324}
325
326// Erase(index)
327bool NameSet::Erase(const Idx& index) {
328 FD_DC("NameSet(" << this << ")::Erase(" << index <<")");
329 return TBaseSet<Idx>::Erase(index);
330}
331
332// Erase(rName)
333bool NameSet::Erase(const std::string& rName) {
334 FD_DC("NameSet(" << this << ")::Erase(" << rName <<")");
335 Idx index = mpSymbolTable->Index(rName);
336#ifdef FAUDES_CHECKED
337 if (index == 0) {
338 std::stringstream errstr;
339 errstr << "name \"" << rName << "\" not found in NameSet" << std::endl;
340 throw Exception("NameSet::Erase", errstr.str(), 66);
341 }
342#endif
343 return TBaseSet<Idx>::Erase(index);
344}
345
346// Erase(pos)
347NameSet::Iterator NameSet::Erase(const Iterator& pos) {
348 return TBaseSet<Idx>::Erase(pos);
349}
350
351// EraseSet(set)
352void NameSet::EraseSet(const TBaseSet<Idx>& rOtherSet) {
353#ifdef FAUDES_CHECKED
354 const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
355 if(!nset) {
356 std::stringstream errstr;
357 errstr << "cannot cast to nameset" << std::endl;
358 throw Exception("NameSet::EraseSet", errstr.str(), 67);
359 }
360 if(nset->mpSymbolTable!=mpSymbolTable) {
361 std::stringstream errstr;
362 errstr << "symboltable mismatch aka not implemented" << std::endl;
363 throw Exception("NameSet::EraseSet", errstr.str(), 67);
364 }
365#endif
366 TBaseSet<Idx>::EraseSet(rOtherSet);
367}
368
369
370// EraseSet(set)
371void NameSet::EraseSet(const NameSet& rOtherSet) {
372#ifdef FAUDES_CHECKED
373 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
374 std::stringstream errstr;
375 errstr << "symboltable mismatch aka not implemented" << std::endl;
376 throw Exception("NameSet::EraseSet", errstr.str(), 67);
377 }
378#endif
379 TBaseSet<Idx>::EraseSet(rOtherSet);
380}
381
382
383// RestrictSet(set)
384void NameSet::RestrictSet(const TBaseSet<Idx>& rOtherSet) {
385#ifdef FAUDES_CHECKED
386 const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
387 if(!nset) {
388 std::stringstream errstr;
389 errstr << "cannot cast to nameset" << std::endl;
390 throw Exception("NameSet::RestrictSet", errstr.str(), 67);
391 }
392 if(nset->mpSymbolTable!=mpSymbolTable) {
393 std::stringstream errstr;
394 errstr << "symboltable mismatch aka not implemented" << std::endl;
395 throw Exception("NameSet::RestrictSet", errstr.str(), 67);
396 }
397#endif
399}
400
401// RestrictSet(set)
402void NameSet::RestrictSet(const NameSet& rOtherSet) {
403#ifdef FAUDES_CHECKED
404 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
405 std::stringstream errstr;
406 errstr << "symboltable mismatch aka not implemented" << std::endl;
407 throw Exception("NameSet::RestrictSet", errstr.str(), 67);
408 }
409#endif
411}
412
413// SymbolicName(index)
414std::string NameSet::SymbolicName(Idx index) const {
415 return mpSymbolTable->Symbol(index);
416}
417
418// SymbolicName(index, name)
419void NameSet::SymbolicName(Idx index, const std::string& rName) {
420 FD_DC("NameSet(" << this << ")::SymbolicName(" << index << ", " << rName <<")");
421#ifdef FAUDES_CHECKED
422 if (! Exists(index)) {
423 std::stringstream errstr;
424 errstr << "index " << index << " not in this set" << std::endl;
425 throw Exception("NameSet::SymbolicName", errstr.str(), 60);
426 }
427#endif
428 mpSymbolTable->SetEntry(index, rName);
429}
430
431// SymbolicName(name, name)
432void NameSet::SymbolicName(const std::string& rName,
433 const std::string& rNewName) {
434 FD_DC("NameSet(" << this << ")::SymbolicName(" << rName << ", "
435 << rNewName <<")");
436#ifdef FAUDES_CHECKED
437 if (! Exists(rName)) {
438 std::stringstream errstr;
439 errstr << "name \"" << rName << "\" not found in NameSet" << std::endl;
440 throw Exception("NameSet::Symbolic", errstr.str(), 66);
441 }
442#endif
443 mpSymbolTable->SetEntry(Index(rName), rNewName);
444}
445
446// Index(rName)
447Idx NameSet::Index(const std::string& rName) const {
448 return mpSymbolTable->Index(rName);
449}
450
451// Exists(index)
452bool NameSet::Exists(const Idx& index) const {
453 return TBaseSet<Idx>::Exists(index);
454}
455
456// Exists(rName)
457bool NameSet::Exists(const std::string& rName) const {
459}
460
461// Find(index) const
462NameSet::Iterator NameSet::Find(const Idx& index) const {
463 return TBaseSet<Idx>::Find(index);
464}
465
466// Find(rName) const
467NameSet::Iterator NameSet::Find(const std::string& rName) const {
469}
470
471
472// operator +
473NameSet NameSet::operator+ (const NameSet& rOtherSet) const {
474 FD_DC("NameSet(" << this << ")::operator + (" << &rOtherSet << ")");
475#ifdef FAUDES_CHECKED
476 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
477 std::stringstream errstr;
478 errstr << "symboltable mismazch aka not implemented" << std::endl;
479 throw Exception("NameSet::Operator+", errstr.str(), 67);
480 }
481#endif
482 NameSet res;
484 res.InsertSet(*this);
485 res.InsertSet(rOtherSet);
486 return res;
487}
488
489// operator -
490NameSet NameSet::operator - (const NameSet& rOtherSet) const {
491 FD_DC("NameSet(" << this << ")::operator - (" << &rOtherSet << ")");
492#ifdef FAUDES_CHECKED
493 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
494 std::stringstream errstr;
495 errstr << "symboltable mismazch aka not implemented" << std::endl;
496 throw Exception("NameSet::Operator-", errstr.str(), 67);
497 }
498#endif
499 NameSet res;
501 res.InsertSet(*this);
502 res.EraseSet(rOtherSet);
503 return res;
504}
505
506
507// operator*
508NameSet NameSet::operator * (const NameSet& rOtherSet) const {
509 FD_DC("NameSet(" << this << ")::operator * (" << &rOtherSet << ")");
510#ifdef FAUDES_CHECKED
511 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
512 std::stringstream errstr;
513 errstr << "symboltable mismazch aka not implemented" << std::endl;
514 throw Exception("NameSet::Operator*", errstr.str(), 67);
515 }
516#endif
517 NameSet res;
519 res.InsertSet(*this);
520 res.RestrictSet(rOtherSet);
521 return res;
522}
523
524// operator <=
525bool NameSet::operator <= (const NameSet& rOtherSet) const {
526#ifdef FAUDES_CHECKED
527 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
528 std::stringstream errstr;
529 errstr << "symboltable mismazch aka not implemented" << std::endl;
530 throw Exception("NameSet::Operator<=", errstr.str(), 67);
531 }
532#endif
533 return TBaseSet<Idx>::operator <= (rOtherSet);
534}
535
536// operator >=
537bool NameSet::operator >= (const NameSet& rOtherSet) const {
538#ifdef FAUDES_CHECKED
539 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
540 std::stringstream errstr;
541 errstr << "symboltable mismazch aka not implemented" << std::endl;
542 throw Exception("NameSet::Operator>=", errstr.str(), 67);
543 }
544#endif
545 return TBaseSet<Idx>::operator >= (rOtherSet);
546}
547
548// Str(index)
549std::string NameSet::Str(const Idx& index) const {
550 return mpSymbolTable->Symbol(index)+"#"+faudes::ToStringInteger(index);
551}
552
553// Str()
554std::string NameSet::Str(void) const {
555 return TBaseSet<Idx>::Str();
556}
557
558
559/*
560*********************************************************************************
561*********************************************************************************
562*********************************************************************************
563
564 Misc
565
566*********************************************************************************
567*********************************************************************************
568*********************************************************************************
569*/
570
571
572// RTI convenience function
573void SetIntersection(const EventSetVector& rSetVec, EventSet& rRes) {
574 // prepare result
575 rRes.Clear();
576 // ignore empty
577 if(rSetVec.Size()==0) return;
578 // copy first
579 rRes.Copy(rSetVec.At(0));
580 // perform intersecttion
581 for(EventSetVector::Position i=1; i<rSetVec.Size(); i++)
582 SetIntersection(rSetVec.At(i),rRes,rRes);
583}
584
585
586// RTI convenience function
587void SetUnion(const EventSetVector& rSetVec, EventSet& rRes) {
588 // prepare result
589 rRes.Clear();
590 // ignore empty
591 if(rSetVec.Size()==0) return;
592 // copy first
593 rRes.Copy(rSetVec.At(0));
594 // perform union
595 for(EventSetVector::Position i=1; i<rSetVec.Size(); i++)
596 SetUnion(rSetVec.At(i),rRes,rRes);
597}
598
599
600/*
601*********************************************************************************
602*********************************************************************************
603*********************************************************************************
604
605 RelabelMap
606
607*********************************************************************************
608*********************************************************************************
609*********************************************************************************
610*/
611
612// register with RTI
616
617
618// std faudes type
625
626
627// empty constructor
629 FD_DC("RelabelMap("<<this<<")::RelabelMap() with symtab "<< mpSymbolTable);
630 mObjectName="RelabelMap";
631 Lock();
632}
633
634// constructor from RelabelMap
636 FD_DC("RelabelMap(" << this << ")::RelabelMap(rOtherMap " << &rOtherMap << ")");
637 Copy(rOtherMap);
638 FD_DC("RelabelMap(" << this << ")::RelabelMap(rOtherSet " << &rOtherSet << "): done");
639 Lock();
640}
641
642// read file constructor
643RelabelMap::RelabelMap(const std::string& rFilename, const std::string& rLabel) : TaNameSet<NameSet>() {
644 FD_DC("RelabelMap(" << this << ")::RelabelMap(" << rFilename << ")");
645 Read(rFilename, rLabel);
646 Lock();
647}
648
649// destructor
651 FD_DC("RelabelMap("<<this<<")::~RelabelMap()");
652}
653
654// extra accessors
655bool RelabelMap::Insert(const Idx& rSrc, const Idx& rDst) {
656 Insert(rSrc);
657 return Attributep(rSrc)->Insert(rDst);
658}
659
660// extra accessors
661bool RelabelMap::Insert(const std::string& rSrc, const std::string& rDst) {
662 Insert(rSrc);
663 return Attributep(rSrc)->Insert(rDst);
664}
665
666// extra accessors
667const NameSet& RelabelMap::Target(const Idx& rSrc) const {
668 return Attribute(rSrc);
669}
670
671// extra accessors
673 return *Attributep(rSrc);
674}
675
676// extra accessors
677const NameSet& RelabelMap::Target(const std::string& rSrc) const {
678 return Attribute(rSrc);
679}
680
681
682// extra accessors
683NameSet& RelabelMap::Target(const std::string& rSrc) {
684 return *Attributep(rSrc);
685}
686
687// extra accessors
688void RelabelMap::Target(const std::string& rSrc, const NameSet& rTarget) {
689 return Attribute(rSrc,rTarget);
690}
691
692
693// extra accessors
694void RelabelMap::Target(const Idx& rSrc, const NameSet& rTarget) {
695 return Attribute(rSrc,rTarget);
696}
697
698// read STL
699void RelabelMap::FromStlMap(const std::map<Idx, std::set<Idx> >& rMap) {
700 Clear();
701 NameSet target;
702 std::map<Idx, std::set<Idx> >::const_iterator mit;
703 mit=rMap.begin();
704 while(mit!=rMap.end()) {
705 target.FromStl(mit->second);
706 TAttrMap<Idx,NameSet>::Insert(mit->first,target);
707 ++mit;
708 }
709}
710
711// write STL
712void RelabelMap::ToStlMap(std::map<Idx, std::set<Idx> >& rMap) const {
713 rMap.clear();
714 std::set<Idx> target;
715 Iterator it=Begin();
716 while(it!=End()) {
717 Attribute(*it).ToStl(target);
718 rMap[*it]=target;
719 ++it;
720 }
721}
722
723// pretty print
724std::string RelabelMap::Str(void) const {
725 std::stringstream str;
726 NameSet::Iterator tit, tit_end;
727 NameSet::Iterator dit=Begin();
728 NameSet::Iterator dit_end=End();
729 while(true) {
730 str << Str(*dit) << " -> { ";
731 const NameSet& target=Target(*dit);
732 tit=target.Begin();
733 tit_end=target.End();
734 for(;tit!=tit_end;++tit)
735 str << NameSet::Str(*tit) << " ";
736 str << "}";
737 ++dit;
738 if(dit==dit_end) break;
739 str << std::endl;
740 }
741 return str.str();
742}
743
744
745
746// apply the map to a NameSet
747void ApplyRelabelMap(const RelabelMap& rMap, const NameSet& rSet, NameSet& rRes) {
748#ifdef FAUDES_CHECKED
749 // test for matching symboltables
750 if(rMap.SymbolTablep()!=rSet.SymbolTablep()) {
751 std::stringstream errstr;
752 errstr << "symboltable mismatch aka not implemented" << std::endl;
753 throw Exception("ApplyRelableMap", errstr.str(), 67);
754 }
755#endif
756 // set up effective domain and range
757 /*
758 NameSet domain, range;
759 NameSet::Iterator dit=rSet.Begin()
760 NameSet::Iterator dit_end=rSet.End()
761 for(;dit=dit_end;++dit) {
762 if(!rMat.Exists(*dit)) continue;
763 domain.Insert(*dit);
764 range.InsertSet(rMap.Target(*dit));
765 }
766 */
767 // have intermediate targets
768 /*
769 SymbolTable& symtab = *rSet.SymbolTablep();
770 std::map<Idx,Idx> target2alt;
771 std::map<Idx,Idx> alt2target;
772 NameSet::Iterator rit=range.Begin()
773 NameSet::Iterator rit_end=range.End()
774 for(;rit=rit_end;++rit) {
775 std::string altstr=symtab.UniqueSymbol("TMP_1");
776 Idx altidx = symtab.InsEntry(altstr);
777 target2alt[*rit]=altidx;
778 alt2target[altidx]=*rit;
779 }
780 */
781 NameSet& inselem = *rSet.New();
782 NameSet delelem;
783 NameSet::Iterator tit, tit_end;
784 NameSet::Iterator dit=rSet.Begin();
785 NameSet::Iterator dit_end=rSet.End();
786 for(;dit!=dit_end;++dit) {
787 if(!rMap.Exists(*dit)) continue;
788 delelem.Insert(*dit);
789 const NameSet& target=rMap.Target(*dit);
790 AttributeVoid* attrp = rSet.Attribute(*dit).NewCpy();
791 tit=target.Begin();
792 tit_end=target.End();
793 for(;tit!=tit_end;++tit) {
794 inselem.Insert(*tit);
795 inselem.Attribute(*tit,*attrp);
796 }
797 delete attrp;
798 }
799 rRes.Copy(rSet);
800 rRes.EraseSet(delelem);
801 rRes.InsertSet(inselem);
802 delete &inselem;
803}
804
805
806
807} // namespace faudes
808
809
810
#define FD_DC(message)
#define FD_DF(message)
#define FD_ERR(message)
Classes NameSet, TaNameSet.
#define FAUDES_TYPE_IMPLEMENTATION_MOVE(ftype, ctype, cbase)
Definition cfl_types.h:959
#define FAUDES_TYPE_IMPLEMENTATION_EQUAL(ftype, ctype, cbase)
Definition cfl_types.h:967
#define FAUDES_TYPE_IMPLEMENTATION_CAST(ftype, ctype, cbase)
Definition cfl_types.h:948
#define FAUDES_TYPE_IMPLEMENTATION_ASSIGN(ftype, ctype, cbase)
Definition cfl_types.h:951
#define FAUDES_TYPE_IMPLEMENTATION_NEW(ftype, ctype, cbase)
Definition cfl_types.h:944
#define FAUDES_TYPE_IMPLEMENTATION_NEWCOPY(ftype, ctype, cbase)
Definition cfl_types.h:946
static void Skip(TokenReader &rTr)
virtual bool IsDefault(void) const
Definition cfl_types.h:1148
std::string mElementTagDef
Definition cfl_types.h:1301
virtual const std::string & ElementTag(void) const
const std::string & Name(void) const
virtual const std::string & TypeName(void) const
bool Exists(const Idx &rIndex) const
NameSet::Iterator Find(const Idx &rIndex) const
void SymbolicName(Idx index, const std::string &rName)
void DoCopy(const NameSet &rSourceSet)
virtual void DoRead(TokenReader &tr, const std::string &rLabel="", const Type *pContext=0)
virtual void InsertSet(const NameSet &rOtherSet)
NameSet operator-(const NameSet &rOtherSet) const
bool DoEqual(const NameSet &rOtherSet) const
bool operator<=(const NameSet &rOtherSet) const
NameSet operator*(const NameSet &rOtherSet) const
SymbolTable * SymbolTablep(void) const
bool Insert(const Idx &rIndex)
NameSet operator+(const NameSet &rOtherSet) const
void DoMove(NameSet &rSourceSet)
bool operator>=(const NameSet &rOtherSet) const
virtual void DoDWrite(TokenWriter &tw, const std::string &rLabel="", const Type *pContext=0) const
virtual std::string Str(void) const
virtual void DoXWrite(TokenWriter &tw, const std::string &rLabel="", const Type *pContext=0) const
void EraseSet(const NameSet &rOtherSet)
Idx Index(const std::string &rName) const
void RestrictSet(const NameSet &rOtherSet)
virtual ~NameSet(void)
virtual void DoWrite(TokenWriter &tw, const std::string &rLabel="", const Type *pContext=0) const
SymbolTable * mpSymbolTable
virtual bool Erase(const Idx &rIndex)
const NameSet & Target(const Idx &rSrc) const
void ToStlMap(std::map< Idx, std::set< Idx > > &rMap) const
virtual bool Insert(const Idx &rSrc, const Idx &rDst)
virtual ~RelabelMap(void)
void FromStlMap(const std::map< Idx, std::set< Idx > > &rMap)
virtual std::string Str(void) const
static SymbolTable * GlobalEventSymbolTablep(void)
std::string Symbol(Idx index) const
bool Exists(Idx index) const
void SetEntry(Idx index, const std::string &rName)
Idx InsEntry(Idx index, const std::string &rName)
Idx Index(const std::string &rName) const
TBaseSet< T, Cmp >::const_iterator const_iterator
bool Insert(const T &rElem)
std::vector< int >::size_type Position
virtual const T & At(const Position &pos) const
NameSet * Attributep(const Idx &rElem)
virtual TaNameSet & Copy(const TBaseSet< Idx > &rSrc)
const NameSet & Attribute(const Idx &rElem) const
std::string FileLine(void) const
bool Eos(const std::string &rLabel)
void ReadEnd(const std::string &rLabel)
void ReadBegin(const std::string &rLabel)
bool Get(Token &token)
bool Peek(Token &token)
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)
Definition cfl_token.h:84
bool IsString(void) const
void SetString(const std::string &rName)
Definition cfl_token.cpp:85
bool ExistsAttributeString(const std::string &name)
bool IsBegin(void) const
void SetEmpty(const std::string &rName)
void SetBegin(const std::string &rName)
Definition cfl_token.cpp:92
void InsAttributeString(const std::string &name, const std::string &value)
const std::string & AttributeStringValue(const std::string &name)
TokenType Type(void) const
virtual Type * NewCpy(void) const
Definition cfl_types.cpp:60
virtual Token XBeginTag(const std::string &rLabel="", const std::string &rFallbackLabel="") const
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
virtual Type & Copy(const Type &rSrc)
Definition cfl_types.cpp:82
virtual void XWrite(const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0) const
virtual Type * New(void) const
Definition cfl_types.cpp:54
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
virtual std::string Str(void) const
void Lock(void) const
bool Empty(void) const
bool Exists(const T &rElem) const
virtual void FromStl(const std::set< T, Cmp > &rStlSet)
virtual void Clear(void)
Iterator Find(const T &rElem) const
void DoMove(TBaseSet &rSourceSet)
Iterator End(void) const
virtual void RestrictSet(const TBaseSet &rOtherSet)
virtual void InsertSet(const TBaseSet &rOtherSet)
Iterator Begin(void) const
virtual const AttributeVoid & Attribute(const Idx &rElem) const
virtual bool Erase(const T &rElem)
bool operator<=(const TBaseSet &rOtherSet) const
bool operator>=(const TBaseSet &rOtherSet) 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)
void DoCopy(const TBaseSet &rSourceSet)
virtual void ToStl(std::set< T, Cmp > &rStlSet) const
uint32_t Idx
AutoRegisterElementType< RelabelMap > gRtiRelabelMapEType("RelabelMap","EventSet")
void ApplyRelabelMap(const RelabelMap &rMap, const vGenerator &rGen, vGenerator &rRes)
AutoRegisterElementTag< RelabelMap > gRtiRelabelMapETag("RelabelMap","Label")
AutoRegisterType< EventSet > gRtiEventSet("EventSet")
std::string ToStringInteger(Int number)
Definition cfl_utils.cpp:43
AutoRegisterType< EventSetVector > gRtiEventSetVector("EventSetVector")
AutoRegisterType< RelabelMap > gRtiRelabelMap("RelabelMap")

libFAUDES 2.34e --- 2026.03.16 --- c++ api documentaion by doxygen