00001
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef FAUDES_TRANSSET_H
00026
00027 #include "definitions.h"
00028 #include "indexset.h"
00029 #include "nameset.h"
00030 #include "attributes.h"
00031 #include "tokenreader.h"
00032 #include <sstream>
00033 #include <map>
00034 #include <iostream>
00035 #include <typeinfo>
00036
00037
00038 namespace faudes {
00039
00052 class Transition {
00053
00054 public:
00055
00057 Transition(void) : X1(0), Ev(0), X2(0) {};
00058
00068 Transition(Idx x1, Idx ev,Idx x2) :
00069 X1(x1), Ev(ev), X2(x2) {}
00070
00072 inline bool operator < (const Transition& othertrans) const {
00073 if (X1 < othertrans.X1) return(true);
00074 if (X1 > othertrans.X1) return(false);
00075 if (Ev < othertrans.Ev) return(true);
00076 if (Ev > othertrans.Ev) return(false);
00077 if (X2 < othertrans.X2) return(true);
00078 return(false);
00079 }
00080
00082 inline bool operator == (const Transition& othertrans) const {
00083 return ((X1 == othertrans.X1) && (Ev == othertrans.Ev) && (X2 == othertrans.X2));
00084 };
00085
00087 inline bool operator != (const Transition& othertrans) const {
00088 return ((X1 != othertrans.X1) || (Ev != othertrans.Ev) || (X2 != othertrans.X2));
00089 };
00090
00092 inline bool Valid(void) const {
00093 return (X1!=0) && (Ev!=0) && (X2!=0);
00094 };
00095
00097 Idx X1;
00098
00100 Idx Ev;
00101
00103 Idx X2;
00104
00106 std::string Str(void) const {
00107 return ToStringInteger(X1)+"--("+ToStringInteger(Ev) + ")->" + ToStringInteger(X2);}
00108 };
00109
00110
00111
00112
00118 class TransSort {
00119
00120 public:
00121
00123 struct EvX1X2 {
00124 inline bool operator () (const Transition& left, const Transition& right) const {
00125 if (left.Ev < right.Ev) return true;
00126 if (left.Ev > right.Ev) return false;
00127 if (left.X1 < right.X1) return true;
00128 if (left.X1 > right.X1) return false;
00129 if (left.X2 < right.X2) return true;
00130 else return false;
00131 }
00132 };
00133
00135 struct EvX2X1 {
00136 inline bool operator () (const Transition& left, const Transition& right) const {
00137 if (left.Ev < right.Ev) return true;
00138 if (left.Ev > right.Ev) return false;
00139 if (left.X2 < right.X2) return true;
00140 if (left.X2 > right.X2) return false;
00141 if (left.X1 < right.X1) return true;
00142 else return false;
00143 }
00144 };
00145
00147 struct X2EvX1 {
00148 inline bool operator () (const Transition& left, const Transition& right) const {
00149 if (left.X2 < right.X2) return true;
00150 if (left.X2 > right.X2) return false;
00151 if (left.Ev < right.Ev) return true;
00152 if (left.Ev > right.Ev) return false;
00153 if (left.X1 < right.X1) return true;
00154 else return false;
00155 }
00156 };
00157
00159 struct X2X1Ev {
00160 inline bool operator () (const Transition& left, const Transition& right) const {
00161 if (left.X2 < right.X2) return true;
00162 if (left.X2 > right.X2) return false;
00163 if (left.X1 < right.X1) return true;
00164 if (left.X1 > right.X1) return false;
00165 if (left.Ev < right.Ev) return true;
00166 else return false;
00167 }
00168 };
00169
00171 struct X1X2Ev {
00172 inline bool operator () (const Transition& left, const Transition& right) const {
00173 if (left.X1 < right.X1) return true;
00174 if (left.X1 > right.X1) return false;
00175 if (left.X2 < right.X2) return true;
00176 if (left.X2 > right.X2) return false;
00177 if (left.Ev < right.Ev) return true;
00178 else return false;
00179 }
00180 };
00181
00183 struct X1EvX2 {
00184 inline bool operator () (const Transition& left, const Transition& right) const {
00185 if (left.X1 < right.X1) return true;
00186 if (left.X1 > right.X1) return false;
00187 if (left.Ev < right.Ev) return true;
00188 if (left.Ev > right.Ev) return false;
00189 if (left.X2 < right.X2) return true;
00190 else return false;
00191 }
00192 };
00193
00194 };
00195
00196
00197
00231 template <class Cmp=TransSort::X1EvX2>
00232 class TTransSet : public TBaseSet<Transition,Cmp> {
00233 public:
00234
00239 TTransSet(void);
00240
00244 TTransSet(const TTransSet& rOtherSet);
00245
00246
00248 virtual ~TTransSet() {};
00249
00254 typedef typename TBaseSet<Transition, Cmp>::Iterator Iterator;
00255
00256
00269 bool Insert(const Transition& rTransition);
00270
00284 bool Insert(Idx x1, Idx ev, Idx x2);
00285
00292 bool Erase(const Transition& t);
00293
00300 bool Erase(Idx x1, Idx ev, Idx x2);
00301
00308 Iterator Erase(const Iterator& it);
00309
00318 void EraseByX1(Idx x1);
00319
00327 void EraseByX2(Idx x2);
00328
00336 void EraseByEv(Idx ev);
00337
00345 void EraseByX1OrX2(Idx x);
00346
00361 Iterator Find(Idx x1, Idx ev, Idx x2) const;
00362
00373 Iterator Find(const Transition& t) const;
00374
00375
00385 bool Exists(const Transition& t) const;
00386
00400 bool Exists(Idx x1, Idx ev, Idx x2) const;
00401
00412 bool Exists(Idx x) const;
00413
00414
00415
00438 Iterator Begin(void) const;
00439
00446 Iterator End(void) const;
00447
00448
00461 Iterator Begin(Idx x1) const;
00462
00475 Iterator End(Idx x1) const;
00476
00491 Iterator Begin(Idx x1, Idx ev) const;
00492
00507 Iterator End(Idx x1, Idx ev) const;
00508
00522 Iterator BeginByEv(Idx ev) const;
00523
00537 Iterator EndByEv(Idx ev) const;
00538
00554 Iterator BeginByEvX1(Idx ev, Idx x1) const;
00555
00571 Iterator EndByEvX1(Idx ev, Idx x1) const;
00572
00588 Iterator BeginByEvX2(Idx ev, Idx x2) const;
00589
00605 Iterator EndByEvX2(Idx ev, Idx x2) const;
00606
00620 Iterator BeginByX2(Idx x2) const;
00621
00635 Iterator EndByX2(Idx x2) const;
00636
00652 Iterator BeginByX2Ev(Idx x2, Idx ev) const;
00653
00669 Iterator EndByX2Ev(Idx x2, Idx ev) const;
00670
00683 template<class OtherCmp>
00684 void ReSort(TTransSet<OtherCmp>& res) const;
00685
00692 StateSet StateSpace(void) const;
00693
00703 StateSet StateSpaceX2(Idx x1) const;
00704
00716 StateSet StateSpaceX2(Idx x1, Idx ev) const;
00717
00733 EventSet ActiveEvents(Idx x1, SymbolTable* pSymTab=NULL) const;
00734
00737 protected:
00738
00753 virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="", const Type* pContext=0) const;
00754
00755
00756 };
00757
00759 typedef TTransSet<TransSort::X1EvX2> TransSet;
00760
00762 typedef TTransSet<TransSort::X1EvX2> TransSetX1EvX2;
00763
00765 typedef TTransSet<TransSort::EvX1X2> TransSetEvX1X2;
00766
00768 typedef TTransSet<TransSort::EvX2X1> TransSetEvX2X1;
00769
00771 typedef TTransSet<TransSort::X2EvX1> TransSetX2EvX1;
00772
00774 typedef TTransSet<TransSort::X2X1Ev> TransSetX2X1Ev;
00775
00777 typedef TTransSet<TransSort::X1X2Ev> TransSetX1X2Ev;
00778
00779
00795 template <class Attr>
00796 class TaTransSet : public TransSet {
00797 public:
00798
00803 template<class A> friend class TaTransSet;
00804
00809 TaTransSet(void);
00810
00814 TaTransSet(const TaTransSet& rOtherSet);
00815
00819 TaTransSet(const TTransSet<TransSort::X1EvX2>& rOtherSet);
00820
00821
00823 virtual ~TaTransSet() {}
00824
00831 void Clear(void);
00832
00837 void ClearAttributes(void);
00838
00845 Idx AttributesSize(void) const;
00846
00865 bool Insert(Idx x1, Idx ev, Idx x2);
00866
00878 bool Insert(const Transition& rTransition);
00879
00891 bool Insert(const Transition& rTransition, const Attr& rAttr);
00892
00899 bool Erase(const Transition& t);
00900
00907 bool Erase(Idx x1, Idx ev, Idx x2);
00908
00915 Iterator Erase(const Iterator& it);
00916
00923 void EraseByX1(Idx x1);
00924
00931 void EraseByX2(Idx x2);
00932
00939 void EraseByEv(Idx ev);
00940
00947 void EraseByX1OrX2(Idx x);
00948
00961 Attr* Attributep(const Transition& rTrans);
00962
00972 const Attr& Attribute(const Transition& rTrans) const;
00973
00983 void Attribute(const Transition& rTrans, const Attr& attr);
00984
00991 void ClrAttribute(const Transition& rTrans);
00992
00993
01006 template<class OtherAttr>
01007 void CopyWithoutAttributes(TaTransSet<OtherAttr>& res) const;
01008
01011 protected:
01013 std::map<Transition,Attr> mAttributeMap;
01014
01016 static Attr mDefAttribute;
01017
01018 };
01019
01021 template<class Attr> Attr TaTransSet<Attr>::mDefAttribute;
01022
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036 #define THIS TTransSet<Cmp>
01037 #define TEMP template<class Cmp>
01038 #define BASE TBaseSet<Transition,Cmp>
01039
01040
01041
01042
01043 TEMP THIS::TTransSet(void) : BASE() {
01044 FD_DC("TTransSet(" << this << ")::TTransSet()");
01045 }
01046
01047
01048 TEMP THIS::TTransSet(const TTransSet& rOtherSet) : BASE(rOtherSet) {
01049 FD_DC("TTransSet(" << this << ")::TTransSet(rOtherSet "<< &rOtherSet <<")");
01050 }
01051
01052
01053 TEMP typename THIS::Iterator THIS::Begin(void) const {
01054 return BASE::Begin();
01055 }
01056
01057
01058 TEMP typename THIS::Iterator THIS::End(void) const {
01059 return BASE::End();
01060 }
01061
01062
01063
01064 #define SORT_EXCEPTION { std::stringstream errstr; \
01065 errstr << "transition set order mismatch " << std::endl; \
01066 throw Exception("TransSet::Iterator()", errstr.str(), 68); }
01067
01068
01069
01070 TEMP typename THIS::Iterator THIS::Begin(Idx x1) const {
01071 #ifdef FAUDES_CHECKED
01072 if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
01073 if(typeid(Cmp)!=typeid(TransSort::X1X2Ev))
01074 SORT_EXCEPTION;
01075 #endif
01076 Transition tlx(x1,0,0);
01077 return ThisIterator(BASE::pSet->lower_bound(tlx));
01078 }
01079
01080
01081 TEMP typename THIS::Iterator THIS::End(Idx x1) const {
01082 #ifdef FAUDES_CHECKED
01083 if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
01084 if(typeid(Cmp)!=typeid(TransSort::X1X2Ev))
01085 SORT_EXCEPTION;
01086 #endif
01087 Transition tlx(x1+1,0,0);
01088 return ThisIterator(BASE::pSet->lower_bound(tlx));
01089 }
01090
01091
01092 TEMP typename THIS::Iterator THIS::Begin(Idx x1, Idx ev) const {
01093 #ifdef FAUDES_CHECKED
01094 if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
01095 SORT_EXCEPTION;
01096 #endif
01097 Transition tlx(x1,ev,0);
01098 return ThisIterator(BASE::pSet->lower_bound(tlx));
01099 }
01100
01101
01102 TEMP typename THIS::Iterator THIS::End(Idx x1, Idx ev) const {
01103 #ifdef FAUDES_CHECKED
01104 if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
01105 SORT_EXCEPTION;
01106 #endif
01107 Transition tlx(x1,ev+1, 0);
01108 return ThisIterator(BASE::pSet->lower_bound(tlx));
01109 }
01110
01111
01112 TEMP typename THIS::Iterator THIS::BeginByEv(Idx ev) const {
01113 #ifdef FAUDES_CHECKED
01114 if(typeid(Cmp)!=typeid(TransSort::EvX1X2))
01115 if(typeid(Cmp)!=typeid(TransSort::EvX2X1))
01116 SORT_EXCEPTION;
01117 #endif
01118 Transition tlx(0,ev,0);
01119 return ThisIterator(BASE::pSet->lower_bound(tlx));
01120 }
01121
01122
01123 TEMP typename THIS::Iterator THIS::EndByEv(Idx ev) const {
01124 #ifdef FAUDES_CHECKED
01125 if(typeid(Cmp)!=typeid(TransSort::EvX1X2))
01126 if(typeid(Cmp)!=typeid(TransSort::EvX2X1))
01127 SORT_EXCEPTION;
01128 #endif
01129 Transition tlx(0,ev+1,0);
01130 return ThisIterator(BASE::pSet->lower_bound(tlx));
01131 }
01132
01133
01134 TEMP typename THIS::Iterator THIS::BeginByEvX1(Idx ev, Idx x1) const {
01135 #ifdef FAUDES_CHECKED
01136 if(typeid(Cmp)!=typeid(TransSort::EvX1X2))
01137 SORT_EXCEPTION;
01138 #endif
01139 Transition tlx(x1,ev,0);
01140 return ThisIterator(BASE::pSet->lower_bound(tlx));
01141 }
01142
01143
01144 TEMP typename THIS::Iterator THIS::EndByEvX1(Idx ev, Idx x1) const {
01145 #ifdef FAUDES_CHECKED
01146 if(typeid(Cmp)!=typeid(TransSort::EvX1X2))
01147 SORT_EXCEPTION;
01148 #endif
01149 Transition tlx(x1+1,ev,0);
01150 return ThisIterator(BASE::pSet->lower_bound(tlx));
01151 }
01152
01153
01154 TEMP typename THIS::Iterator THIS::BeginByEvX2(Idx ev, Idx x2) const {
01155 #ifdef FAUDES_CHECKED
01156 if(typeid(Cmp)!=typeid(TransSort::EvX2X1))
01157 SORT_EXCEPTION;
01158 #endif
01159 Transition tlx(0,ev,x2);
01160 return ThisIterator(BASE::pSet->lower_bound(tlx));
01161 }
01162
01163
01164 TEMP typename THIS::Iterator THIS::EndByEvX2(Idx ev, Idx x2) const {
01165 #ifdef FAUDES_CHECKED
01166 if(typeid(Cmp)!=typeid(TransSort::EvX2X1))
01167 SORT_EXCEPTION;
01168 #endif
01169 Transition tlx(0,ev,x2+1);
01170 return ThisIterator(BASE::pSet->lower_bound(tlx));
01171 }
01172
01173
01174 TEMP typename THIS::Iterator THIS::BeginByX2(Idx x2) const {
01175 #ifdef FAUDES_CHECKED
01176 if(typeid(Cmp)!=typeid(TransSort::X2EvX1))
01177 if(typeid(Cmp)!=typeid(TransSort::X2X1Ev))
01178 SORT_EXCEPTION;
01179 #endif
01180 Transition tlx(0,0,x2);
01181 return ThisIterator(BASE::pSet->lower_bound(tlx));
01182 }
01183
01184
01185 TEMP typename THIS::Iterator THIS::EndByX2(Idx x2) const {
01186 #ifdef FAUDES_CHECKED
01187 if(typeid(Cmp)!=typeid(TransSort::X2EvX1))
01188 if(typeid(Cmp)!=typeid(TransSort::X2X1Ev))
01189 SORT_EXCEPTION;
01190 #endif
01191 Transition tlx(0,0,x2+1);
01192 return ThisIterator(BASE::pSet->lower_bound(tlx));
01193 }
01194
01195
01196 TEMP typename THIS::Iterator THIS::BeginByX2Ev(Idx x2, Idx ev) const {
01197 #ifdef FAUDES_CHECKED
01198 if(typeid(Cmp)!=typeid(TransSort::X2EvX1))
01199 SORT_EXCEPTION;
01200 #endif
01201 Transition tlx(0,ev,x2);
01202 return ThisIterator(BASE::pSet->lower_bound(tlx));
01203 }
01204
01205
01206 TEMP typename THIS::Iterator THIS::EndByX2Ev(Idx x2, Idx ev) const {
01207 #ifdef FAUDES_CHECKED
01208 if(typeid(Cmp)!=typeid(TransSort::X2EvX1))
01209 SORT_EXCEPTION;
01210 #endif
01211 Transition tlx(0,ev+1,x2);
01212 return ThisIterator(BASE::pSet->lower_bound(tlx));
01213 }
01214
01215
01216
01217
01218 TEMP void THIS::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const
01219 {
01220 (void) pContext;
01221 std::string label=rLabel;
01222 if(label=="") label=BASE::Name();
01223 rTw.WriteBegin(label);
01224 int oldcolumns = rTw.Columns();
01225 rTw.Columns(3);
01226 rTw.WriteBegin(label);
01227
01228 Iterator tit;
01229 for (tit = Begin(); tit != End(); ++tit) {
01230 rTw << tit->X1; rTw << tit->Ev; rTw << tit->X2;
01231 }
01232
01233 rTw.WriteEnd(label);
01234 rTw.Columns(oldcolumns);
01235 }
01236
01237
01238
01239 TEMP bool THIS::Insert(const Transition& t) {
01240 return BASE::Insert(t);
01241 }
01242
01243
01244 TEMP bool THIS::Insert(Idx x1, Idx ev, Idx x2) {
01245 FD_DC("TTransSet(" << this << ")::Insert(" << x1 << "-" << ev << "-" << x2 << ")");
01246 return BASE::Insert(Transition(x1, ev, x2));
01247 }
01248
01249
01250 TEMP bool THIS::Erase(const Transition& t) {
01251 return BASE::Erase(t);
01252 }
01253
01254
01255 TEMP bool THIS::Erase(Idx x1, Idx ev, Idx x2) {
01256 FD_DC("TTransSet(" << this << ")::Erase(" << x1 << "-" << ev << "-" << x2 << ")");
01257 return BASE::Erase(Transition(x1, ev, x2));
01258 }
01259
01260
01261 TEMP typename THIS::Iterator THIS::Erase(const Iterator& it) {
01262 FD_DC("TTransSet(" << this << ")::Erase(" << it->X1 << "-" << it->Ev
01263 << "-" << it->X2 << ")");
01264 return BASE::Erase(it);
01265 }
01266
01267
01268 TEMP void THIS::EraseByX1(Idx x1) {
01269 FD_DC("TTransSet(" << this << ")::EraseByX1(" << x1 << ")");
01270 #ifdef FAUDES_CHECKED
01271 if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
01272 if(typeid(Cmp)!=typeid(TransSort::X1X2Ev))
01273 SORT_EXCEPTION;
01274 #endif
01275 BASE::Detach();
01276 typename BASE::iterator lower, upper, it;
01277 Transition tl(x1,0,0);
01278 Transition tu(x1+1,0,0);
01279 lower = BASE::pSet->lower_bound(tl);
01280 upper = BASE::pSet->upper_bound(tu);
01281 BASE::pSet->erase(lower, upper);
01282 }
01283
01284
01285 TEMP void THIS::EraseByX2(Idx x2) {
01286 FD_DC("TTransSet(" << this << ")::EraseByX2(" << x2 << ")");
01287 BASE::Detach();
01288 typename BASE::iterator it, tmpit;
01289 for(it = BASE::pSet->begin(); it != BASE::pSet->end();) {
01290 if (it->X2 == x2) {
01291 tmpit = it;
01292 it++;
01293 BASE::pSet->erase(tmpit);
01294 continue;
01295 }
01296 it++;
01297 }
01298 }
01299
01300
01301 TEMP void THIS::EraseByEv(Idx ev) {
01302 FD_DC("TTransSet(" << this << ")::EraseByEv(" << ev << ")");
01303 BASE::Detach();
01304 typename BASE::iterator it, tmpit;
01305 for(it = BASE::pSet->begin(); it != BASE::pSet->end();) {
01306 if (it->Ev == ev) {
01307 tmpit = it;
01308 it++;
01309 BASE::pSet->erase(tmpit);
01310 continue;
01311 }
01312 it++;
01313 }
01314 }
01315
01316
01317
01318
01319 TEMP void THIS::EraseByX1OrX2(Idx x) {
01320 FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(" << x << ")");
01321 BASE::Detach();
01322 typename BASE::iterator it, tmpit;
01323 for(it = BASE::pSet->begin(); it != BASE::pSet->end();) {
01324 if ((it->X1 == x) || (it->X2 == x)) {
01325 tmpit = it;
01326 it++;
01327 BASE::pSet->erase(tmpit);
01328 continue;
01329 }
01330 it++;
01331 }
01332 FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(" << x << "): done");
01333 }
01334
01335
01336 TEMP typename THIS::Iterator THIS::Find(Idx x1, Idx ev, Idx x2) const {
01337 return BASE::Find(Transition(x1,ev,x2));
01338 }
01339
01340
01341
01342 TEMP typename THIS::Iterator THIS::Find(const Transition& t) const{
01343 return BASE::Find(t);
01344 }
01345
01346
01347 TEMP bool THIS::Exists(const Transition& t) const {
01348 return BASE::Exists(t);
01349 }
01350
01351
01352 TEMP bool THIS::Exists(Idx x1, Idx ev, Idx x2) const {
01353 return BASE::Exists(Transition(x1,ev,x2));
01354 }
01355
01356
01357 TEMP bool THIS::Exists(Idx x) const {
01358 typename BASE::iterator it;
01359 for(it = BASE::pSet->begin(); it != BASE::pSet->end(); ++it) {
01360 if ((it->X1 == x) || (it->X2 == x)) {
01361 return true;
01362 }
01363 }
01364 return false;
01365 }
01366
01367
01368
01369
01370 TEMP template<class OtherCmp>
01371 void THIS::ReSort(TTransSet<OtherCmp>& res) const {
01372 Iterator it;
01373 res.Clear();
01374 for (it = Begin(); it != End(); ++it) {
01375 res.Insert(*it);
01376 }
01377 }
01378
01379
01380 TEMP StateSet THIS::StateSpace(void) const {
01381 StateSet states;
01382 Iterator it;
01383 for (it=Begin(); it!=End(); ++it) {
01384 states.Insert(it->X1);
01385 states.Insert(it->X2);
01386 }
01387 return states;
01388 }
01389
01390
01391 TEMP StateSet THIS::StateSpaceX2(Idx x1) const {
01392 StateSet states;
01393 Iterator it = Begin(x1);
01394 Iterator it_end = End(x1);
01395 while (it != it_end) {
01396 states.Insert(it->X2);
01397 ++it;
01398 }
01399 return states;
01400 }
01401
01402
01403 TEMP StateSet THIS::StateSpaceX2(Idx x1, Idx ev) const {
01404 StateSet states;
01405 Iterator it = Begin(x1, ev);
01406 Iterator it_end = End(x1, ev);
01407 while (it != it_end) {
01408 states.Insert(it->X2);
01409 ++it;
01410 }
01411 return states;
01412 }
01413
01414
01415 TEMP EventSet THIS::ActiveEvents(Idx x1, SymbolTable* pSymTab) const {
01416 Iterator it = Begin(x1);
01417 Iterator it_end = End(x1);
01418 EventSet result;
01419 if(pSymTab!=NULL) result.SymbolTablep(pSymTab);
01420 for (; it != it_end; ++it) {
01421 result.Insert(it->Ev);
01422 }
01423 return result;
01424 }
01425
01426
01427 #undef THIS
01428 #undef TEMP
01429 #undef BASE
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441 #define THIS TaTransSet<Attr>
01442 #define TEMP template <class Attr>
01443 #define BASE TTransSet<TransSort::X1EvX2>
01444
01445
01446
01447 TEMP THIS::TaTransSet(void) : BASE() {
01448 FD_DC("TaTransSet(" << this << ")::TaTransSet()");
01449 }
01450
01451
01452 TEMP THIS::TaTransSet(const TaTransSet& rOtherSet) : BASE(rOtherSet) {
01453 FD_DC("TaTransSet(" << this << ")::TaTransSet(rOtherSet "<< &rOtherSet <<")");
01454 mAttributeMap = rOtherSet.mAttributeMap;
01455 }
01456
01457
01458
01459 TEMP THIS::TaTransSet(const BASE& rOtherSet) :
01460 TransSet(rOtherSet)
01461 {
01462 FD_DC("TaTransSet(" << this << ")::TaTransSet(rOtherSet "<< &rOtherSet <<")");
01463 }
01464
01465
01466 TEMP template<class OtherAttr>
01467 void THIS::CopyWithoutAttributes(TaTransSet<OtherAttr>& res) const{
01468 res.Clear();
01469 Assign(res);
01470 }
01471
01472
01473 TEMP Idx THIS::AttributesSize(void) const {
01474 return (Idx)mAttributeMap.size();
01475 }
01476
01477
01478 TEMP void THIS::Clear(void) {
01479 FD_DC("TaTransSet(" << this << ")::Clear()");
01480 TransSet::Clear();
01481 mAttributeMap.clear();
01482 }
01483
01484
01485 TEMP bool THIS::Insert(const Transition& t) {
01486 FD_DC("TaTransSet(" << this << ")::Insert(" << t.Str() << ")");
01487
01488 return BASE::Insert(t);
01489 }
01490
01491
01492 TEMP bool THIS::Insert(Idx x1, Idx ev, Idx x2) {
01493 FD_DC("TaTransSet(" << this << ")::Insert(" << x1 << "-" << ev << "-" << x2 << ")");
01494 Transition t(x1, ev, x2);
01495
01496 return BASE::Insert(t);
01497 }
01498
01499
01500 TEMP bool THIS::Insert(const Transition& t, const Attr& attr) {
01501 if(attr.IsDefault())
01502 mAttributeMap.erase(t);
01503 else
01504 mAttributeMap[t]=attr;
01505 return BASE::Insert(t);
01506 }
01507
01508
01509 TEMP bool THIS::Erase(const Transition& t) {
01510 bool ret= BASE::Erase(t);
01511 mAttributeMap.erase(t);
01512 return ret;
01513 }
01514
01515
01516 TEMP bool THIS::Erase(Idx x1, Idx ev, Idx x2) {
01517 FD_DC("TaTransSet(" << this << ")::Erase(" << x1 << "-" << ev << "-" << x2 << ")");
01518 Transition t(x1, ev, x2);
01519 mAttributeMap.erase(t);
01520 return BASE::Erase(t);
01521 }
01522
01523
01524 TEMP typename THIS::Iterator THIS::Erase(const Iterator& it) {
01525 #ifdef FAUDES_CHECKED
01526 if (it == End()) {
01527 std::stringstream errstr;
01528 errstr << "iterator out of range " << std::endl;
01529 throw Exception("TTransSet::Erase", errstr.str(), 69);
01530 }
01531 #endif
01532 BASE::Detach();
01533 FD_DC("TaTransSet(" << this << ")::Erase(" << it->X1 << "-" << it->Ev
01534 << "-" << it->X2 << ")");
01535 mAttributeMap.erase(*it);
01536 return BASE::Erase(it);
01537 }
01538
01539
01540 TEMP void THIS::EraseByX1(Idx x1) {
01541 FD_DC("TaTransSet(" << this << ")::EraseByX1(" << x1 << ")");
01542 BASE::Detach();
01543 BASE::iterator lower, upper, it;
01544 Transition tl(x1,0,0);
01545 Transition tu(x1+1,0,0);
01546 lower = BASE::pSet->lower_bound(tl);
01547 upper = BASE::pSet->upper_bound(tu);
01548 if(mAttributeMap.size()!=0)
01549 for(it=lower; it!=upper; ++it)
01550 mAttributeMap.erase(*it);
01551 BASE::pSet->erase(lower, upper);
01552 }
01553
01554
01555 TEMP void THIS::EraseByX2(Idx x2) {
01556 FD_DC("TaTransSet(" << this << ")::EraseByX2(" << x2 << ")");
01557 BASE::Detach();
01558 BASE::iterator it, tmpit;
01559 for(it = BASE::pSet->begin(); it !=BASE::pSet->end();) {
01560 if (it->X2 == x2) {
01561 tmpit = it;
01562 it++;
01563 mAttributeMap.erase(*tmpit);
01564 BASE::pSet->erase(tmpit);
01565 continue;
01566 }
01567 it++;
01568 }
01569 }
01570
01571
01572 TEMP void THIS::EraseByEv(Idx ev) {
01573 FD_DC("TaTransSet(" << this << ")::EraseByEv(" << ev << ")");
01574 BASE::Detach();
01575 BASE::iterator it, tmpit;
01576 for(it = BASE::pSet->begin(); it !=BASE::pSet->end();) {
01577 if (it->Ev == ev) {
01578 tmpit = it;
01579 it++;
01580 mAttributeMap.erase(*tmpit);
01581 BASE::pSet->erase(tmpit);
01582 continue;
01583 }
01584 it++;
01585 }
01586 }
01587
01588
01589
01590
01591 TEMP void THIS::EraseByX1OrX2(Idx x) {
01592 FD_DC("TaTransSet(" << this << ")::EraseByX1OrX2(" << x << ")");
01593 BASE::Detach();
01594 BASE::iterator it, tmpit;
01595 for(it = BASE::pSet->begin(); it !=BASE::pSet->end();) {
01596 if ((it->X1 == x) || (it->X2 == x)) {
01597 tmpit = it;
01598 it++;
01599 mAttributeMap.erase(*tmpit);
01600 BASE::pSet->erase(tmpit);
01601 continue;
01602 }
01603 it++;
01604 }
01605 }
01606
01607
01608 TEMP Attr* THIS::Attributep(const Transition& rTrans) {
01609 #ifdef FAUDES_CHECKED
01610 if (!Exists(rTrans)) {
01611 std::stringstream errstr;
01612 errstr << "transition " << rTrans.Str() << " not member of set" << std::endl;
01613 throw Exception("TTransSet::Attributep(t)", errstr.str(), 60);
01614 }
01615 #endif
01616 typename std::map<Transition,Attr>::iterator ait;
01617 ait=mAttributeMap.find(rTrans);
01618 if( ait!=mAttributeMap.end() )
01619 return & (ait->second);
01620
01621 typename std::map<Transition,Attr>::value_type entry(rTrans,mDefAttribute);
01622 ait=mAttributeMap.insert(entry).first;
01623 return & (ait->second);
01624 }
01625
01626
01627 TEMP const Attr& THIS::Attribute(const Transition& rTrans) const {
01628 #ifdef FAUDES_CHECKED
01629 if (!Exists(rTrans)) {
01630 std::stringstream errstr;
01631 errstr << "transition " << rTrans.Str() << " not member of set" << std::endl;
01632 throw Exception("TTransSet::Attribute(t)", errstr.str(), 60);
01633 }
01634 #endif
01635 typename std::map<Transition,Attr>::const_iterator ait;
01636 ait=mAttributeMap.find(rTrans);
01637 if( ait!=mAttributeMap.end() ) {
01638 return ait->second;
01639 }
01640 return mDefAttribute;
01641 }
01642
01643
01644 TEMP void THIS::Attribute(const Transition& rTrans, const Attr& rAttr) {
01645 #ifdef FAUDES_CHECKED
01646 if (!Exists(rTrans)) {
01647 std::stringstream errstr;
01648 errstr << "transition " << rTrans.Str() << " not member of set" << std::endl;
01649 throw Exception("TTransSet::Attribute(t,attr)", errstr.str(), 60);
01650 }
01651 #endif
01652 if(rAttr.IsDefault())
01653 mAttributeMap.erase(rTrans);
01654 else
01655 mAttributeMap[rTrans]=rAttr;
01656 }
01657
01658
01659 TEMP void THIS::ClearAttributes(void) {
01660 mAttributeMap.clear();
01661 }
01662
01663 #undef THIS
01664 #undef TEMP
01665 #undef BASE
01666
01667 #undef SORT_EXECPTION
01668
01669 }
01670
01671
01672
01673
01674 #define FAUDES_TRANSSET_H
01675 #endif
01676