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

libFAUDES 2.33l --- 2025.09.16 --- c++ api documentaion by doxygen