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 TRANSSET_H
00026
00027 #include "definitions.h"
00028 #include "indexset.h"
00029 #include "nameset.h"
00030 #include "attributes.h"
00031 #include <sstream>
00032 #include <map>
00033 #include <iostream>
00034 #include "tokenreader.h"
00035
00036
00037 namespace faudes {
00038
00051 class Transition {
00052
00053 public:
00054
00056 Transition(void) : X1(0), Ev(0), X2(0) {};
00057
00067 Transition(Idx x1, Idx ev,Idx x2) :
00068 X1(x1), Ev(ev), X2(x2) {}
00069
00071 inline bool operator < (const Transition& othertrans) const {
00072 if (X1 < othertrans.X1) return(true);
00073 if (X1 > othertrans.X1) return(false);
00074 if (Ev < othertrans.Ev) return(true);
00075 if (Ev > othertrans.Ev) return(false);
00076 if (X2 < othertrans.X2) return(true);
00077 return(false);
00078 }
00079
00081 inline bool operator == (const Transition& othertrans) const {
00082 return ((X1 == othertrans.X1) && (Ev == othertrans.Ev) && (X2 == othertrans.X2));
00083 };
00084
00086 inline bool operator != (const Transition& othertrans) const {
00087 return ((X1 != othertrans.X1) || (Ev != othertrans.Ev) || (X2 != othertrans.X2));
00088 };
00089
00091 inline bool Valid(void) const {
00092 return (X1!=0) && (Ev!=0) && (X2!=0);
00093 };
00094
00096 Idx X1;
00097
00099 Idx Ev;
00100
00102 Idx X2;
00103
00105 std::string Str(void) const {
00106 return ToStringInteger(X1)+"--("+ToStringInteger(Ev) + ")->" + ToStringInteger(X2);}
00107 };
00108
00109
00110
00111
00117 class TransSort {
00118
00119 public:
00120
00122 struct EvX1X2 {
00123 inline bool operator () (const Transition& left, const Transition& right) const {
00124 if (left.Ev < right.Ev) return true;
00125 if (left.Ev > right.Ev) return false;
00126 if (left.X1 < right.X1) return true;
00127 if (left.X1 > right.X1) return false;
00128 if (left.X2 < right.X2) return true;
00129 else return false;
00130 }
00131 };
00132
00134 struct EvX2X1 {
00135 inline bool operator () (const Transition& left, const Transition& right) const {
00136 if (left.Ev < right.Ev) return true;
00137 if (left.Ev > right.Ev) return false;
00138 if (left.X2 < right.X2) return true;
00139 if (left.X2 > right.X2) return false;
00140 if (left.X1 < right.X1) return true;
00141 else return false;
00142 }
00143 };
00144
00146 struct X2EvX1 {
00147 inline bool operator () (const Transition& left, const Transition& right) const {
00148 if (left.X2 < right.X2) return true;
00149 if (left.X2 > right.X2) return false;
00150 if (left.Ev < right.Ev) return true;
00151 if (left.Ev > right.Ev) return false;
00152 if (left.X1 < right.X1) return true;
00153 else return false;
00154 }
00155 };
00156
00158 struct X2X1Ev {
00159 inline bool operator () (const Transition& left, const Transition& right) const {
00160 if (left.X2 < right.X2) return true;
00161 if (left.X2 > right.X2) return false;
00162 if (left.X1 < right.X1) return true;
00163 if (left.X1 > right.X1) return false;
00164 if (left.Ev < right.Ev) return true;
00165 else return false;
00166 }
00167 };
00168
00170 struct X1X2Ev {
00171 inline bool operator () (const Transition& left, const Transition& right) const {
00172 if (left.X1 < right.X1) return true;
00173 if (left.X1 > right.X1) return false;
00174 if (left.X2 < right.X2) return true;
00175 if (left.X2 > right.X2) return false;
00176 if (left.Ev < right.Ev) return true;
00177 else return false;
00178 }
00179 };
00180
00182 struct X1EvX2 {
00183 inline bool operator () (const Transition& left, const Transition& right) const {
00184 if (left.X1 < right.X1) return true;
00185 if (left.X1 > right.X1) return false;
00186 if (left.Ev < right.Ev) return true;
00187 if (left.Ev > right.Ev) return false;
00188 if (left.X2 < right.X2) return true;
00189 else return false;
00190 }
00191 };
00192
00193 };
00194
00195
00229 template <class Cmp=TransSort::X1EvX2>
00230 class TTransSet : public TBaseSet<Transition,Cmp> {
00231 public:
00232
00237 TTransSet(void);
00238
00242 TTransSet(const TTransSet& rOtherSet);
00243
00244
00246 virtual ~TTransSet() {};
00247
00252 typedef typename TBaseSet<Transition, Cmp>::Iterator Iterator;
00253
00254
00267 bool Insert(const Transition& rTransition);
00268
00282 bool Insert(Idx x1, Idx ev, Idx x2);
00283
00290 bool Erase(const Transition& t);
00291
00298 bool Erase(Idx x1, Idx ev, Idx x2);
00299
00306 Iterator Erase(const Iterator& it);
00307
00316 void EraseByX1(Idx x1);
00317
00325 void EraseByX2(Idx x2);
00326
00334 void EraseByEv(Idx ev);
00335
00343 void EraseByX1OrX2(Idx x);
00344
00359 Iterator Find(Idx x1, Idx ev, Idx x2) const;
00360
00371 Iterator Find(const Transition& t) const;
00372
00373
00383 bool Exists(const Transition& t) const;
00384
00398 bool Exists(Idx x1, Idx ev, Idx x2) const;
00399
00410 bool Exists(Idx x) const;
00411
00412
00413
00436 Iterator Begin(void) const;
00437
00444 Iterator End(void) const;
00445
00446
00459 Iterator Begin(Idx x1) const;
00460
00473 Iterator End(Idx x1) const;
00474
00489 Iterator Begin(Idx x1, Idx ev) const;
00490
00505 Iterator End(Idx x1, Idx ev) const;
00506
00520 Iterator BeginByEv(Idx ev) const;
00521
00535 Iterator EndByEv(Idx ev) const;
00536
00552 Iterator BeginByEvX1(Idx ev, Idx x1) const;
00553
00569 Iterator EndByEvX1(Idx ev, Idx x1) const;
00570
00586 Iterator BeginByEvX2(Idx ev, Idx x2) const;
00587
00603 Iterator EndByEvX2(Idx ev, Idx x2) const;
00604
00618 Iterator BeginByX2(Idx x2) const;
00619
00633 Iterator EndByX2(Idx x2) const;
00634
00650 Iterator BeginByX2Ev(Idx x2, Idx ev) const;
00651
00667 Iterator EndByX2Ev(Idx x2, Idx ev) const;
00668
00681 template<class OtherCmp>
00682 void ReSort(TTransSet<OtherCmp>& res) const;
00683
00690 StateSet StateSpace(void) const;
00691
00701 StateSet StateSpaceX2(Idx x1) const;
00702
00714 StateSet StateSpaceX2(Idx x1, Idx ev) const;
00715
00731 EventSet ActiveEvents(Idx x1, SymbolTable* pSymTab=NULL) const;
00732
00735 protected:
00736
00749 void DoWrite(TokenWriter& rTw, const std::string& rLabel="") const;
00750
00751
00752 };
00753
00755 typedef TTransSet<TransSort::X1EvX2> TransSet;
00756
00758 typedef TTransSet<TransSort::X1EvX2> TransSetX1EvX2;
00759
00761 typedef TTransSet<TransSort::EvX1X2> TransSetEvX1X2;
00762
00764 typedef TTransSet<TransSort::EvX2X1> TransSetEvX2X1;
00765
00767 typedef TTransSet<TransSort::X2EvX1> TransSetX2EvX1;
00768
00770 typedef TTransSet<TransSort::X2X1Ev> TransSetX2X1Ev;
00771
00773 typedef TTransSet<TransSort::X1X2Ev> TransSetX1X2Ev;
00774
00775
00791 template <class Attr>
00792 class TaTransSet : public TransSet {
00793 public:
00794
00799 template<class A> friend class TaTransSet;
00800
00805 TaTransSet(void);
00806
00810 TaTransSet(const TaTransSet& rOtherSet);
00811
00815 TaTransSet(const TTransSet<TransSort::X1EvX2>& rOtherSet);
00816
00817
00819 virtual ~TaTransSet() {}
00820
00827 void Clear(void);
00828
00833 void ClearAttributes(void);
00834
00841 Idx AttributesSize(void) const;
00842
00861 bool Insert(Idx x1, Idx ev, Idx x2);
00862
00874 bool Insert(const Transition& rTransition);
00875
00887 bool Insert(const Transition& rTransition, const Attr& rAttr);
00888
00895 bool Erase(const Transition& t);
00896
00903 bool Erase(Idx x1, Idx ev, Idx x2);
00904
00911 Iterator Erase(const Iterator& it);
00912
00919 void EraseByX1(Idx x1);
00920
00927 void EraseByX2(Idx x2);
00928
00935 void EraseByEv(Idx ev);
00936
00943 void EraseByX1OrX2(Idx x);
00944
00957 Attr* Attributep(const Transition& rTrans);
00958
00968 const Attr& Attribute(const Transition& rTrans) const;
00969
00979 void Attribute(const Transition& rTrans, const Attr& attr);
00980
00987 void ClrAttribute(const Transition& rTrans);
00988
00989
01002 template<class OtherAttr>
01003 void CopyWithoutAttributes(TaTransSet<OtherAttr>& res) const;
01004
01007 protected:
01009 std::map<Transition,Attr> mAttributeMap;
01010
01012 static Attr mDefAttribute;
01013
01014 };
01015
01017 template<class Attr> Attr TaTransSet<Attr>::mDefAttribute;
01018
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032 #define THIS TTransSet<Cmp>
01033 #define TEMP template<class Cmp>
01034 #define BASE TBaseSet<Transition,Cmp>
01035
01036
01037
01038
01039 TEMP THIS::TTransSet(void) : BASE() {
01040 FD_DC("TTransSet(" << this << ")::TTransSet()");
01041 }
01042
01043
01044 TEMP THIS::TTransSet(const TTransSet& rOtherSet) : BASE(rOtherSet) {
01045 FD_DC("TTransSet(" << this << ")::TTransSet(rOtherSet "<< &rOtherSet <<")");
01046 }
01047
01048
01049 TEMP typename THIS::Iterator THIS::Begin(void) const {
01050 return BASE::Begin();
01051 }
01052
01053
01054 TEMP typename THIS::Iterator THIS::End(void) const {
01055 return BASE::End();
01056 }
01057
01058
01059
01060 #define SORT_EXCEPTION { std::stringstream errstr; \
01061 errstr << "transition set order mismatch " << std::endl; \
01062 throw Exception("TransSet::Iterator()", errstr.str(), 68); }
01063
01064
01065
01066 TEMP typename THIS::Iterator THIS::Begin(Idx x1) const {
01067 #ifdef FAUDES_CHECKED
01068 if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
01069 if(typeid(Cmp)!=typeid(TransSort::X1X2Ev))
01070 SORT_EXCEPTION;
01071 #endif
01072 Transition tlx(x1,0,0);
01073 return ThisIterator(BASE::pSet->lower_bound(tlx));
01074 }
01075
01076
01077 TEMP typename THIS::Iterator THIS::End(Idx x1) const {
01078 #ifdef FAUDES_CHECKED
01079 if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
01080 if(typeid(Cmp)!=typeid(TransSort::X1X2Ev))
01081 SORT_EXCEPTION;
01082 #endif
01083 Transition tlx(x1+1,0,0);
01084 return ThisIterator(BASE::pSet->lower_bound(tlx));
01085 }
01086
01087
01088 TEMP typename THIS::Iterator THIS::Begin(Idx x1, Idx ev) const {
01089 #ifdef FAUDES_CHECKED
01090 if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
01091 SORT_EXCEPTION;
01092 #endif
01093 Transition tlx(x1,ev,0);
01094 return ThisIterator(BASE::pSet->lower_bound(tlx));
01095 }
01096
01097
01098 TEMP typename THIS::Iterator THIS::End(Idx x1, Idx ev) const {
01099 #ifdef FAUDES_CHECKED
01100 if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
01101 SORT_EXCEPTION;
01102 #endif
01103 Transition tlx(x1,ev+1, 0);
01104 return ThisIterator(BASE::pSet->lower_bound(tlx));
01105 }
01106
01107
01108 TEMP typename THIS::Iterator THIS::BeginByEv(Idx ev) const {
01109 #ifdef FAUDES_CHECKED
01110 if(typeid(Cmp)!=typeid(TransSort::EvX1X2))
01111 if(typeid(Cmp)!=typeid(TransSort::EvX2X1))
01112 SORT_EXCEPTION;
01113 #endif
01114 Transition tlx(0,ev,0);
01115 return ThisIterator(BASE::pSet->lower_bound(tlx));
01116 }
01117
01118
01119 TEMP typename THIS::Iterator THIS::EndByEv(Idx ev) const {
01120 #ifdef FAUDES_CHECKED
01121 if(typeid(Cmp)!=typeid(TransSort::EvX1X2))
01122 if(typeid(Cmp)!=typeid(TransSort::EvX2X1))
01123 SORT_EXCEPTION;
01124 #endif
01125 Transition tlx(0,ev+1,0);
01126 return ThisIterator(BASE::pSet->lower_bound(tlx));
01127 }
01128
01129
01130 TEMP typename THIS::Iterator THIS::BeginByEvX1(Idx ev, Idx x1) const {
01131 #ifdef FAUDES_CHECKED
01132 if(typeid(Cmp)!=typeid(TransSort::EvX1X2))
01133 SORT_EXCEPTION;
01134 #endif
01135 Transition tlx(x1,ev,0);
01136 return ThisIterator(BASE::pSet->lower_bound(tlx));
01137 }
01138
01139
01140 TEMP typename THIS::Iterator THIS::EndByEvX1(Idx ev, Idx x1) const {
01141 #ifdef FAUDES_CHECKED
01142 if(typeid(Cmp)!=typeid(TransSort::EvX1X2))
01143 SORT_EXCEPTION;
01144 #endif
01145 Transition tlx(x1+1,ev,0);
01146 return ThisIterator(BASE::pSet->lower_bound(tlx));
01147 }
01148
01149
01150 TEMP typename THIS::Iterator THIS::BeginByEvX2(Idx ev, Idx x2) const {
01151 #ifdef FAUDES_CHECKED
01152 if(typeid(Cmp)!=typeid(TransSort::EvX2X1))
01153 SORT_EXCEPTION;
01154 #endif
01155 Transition tlx(0,ev,x2);
01156 return ThisIterator(BASE::pSet->lower_bound(tlx));
01157 }
01158
01159
01160 TEMP typename THIS::Iterator THIS::EndByEvX2(Idx ev, Idx x2) const {
01161 #ifdef FAUDES_CHECKED
01162 if(typeid(Cmp)!=typeid(TransSort::EvX2X1))
01163 SORT_EXCEPTION;
01164 #endif
01165 Transition tlx(0,ev,x2+1);
01166 return ThisIterator(BASE::pSet->lower_bound(tlx));
01167 }
01168
01169
01170 TEMP typename THIS::Iterator THIS::BeginByX2(Idx x2) const {
01171 #ifdef FAUDES_CHECKED
01172 if(typeid(Cmp)!=typeid(TransSort::X2EvX1))
01173 if(typeid(Cmp)!=typeid(TransSort::X2X1Ev))
01174 SORT_EXCEPTION;
01175 #endif
01176 Transition tlx(0,0,x2);
01177 return ThisIterator(BASE::pSet->lower_bound(tlx));
01178 }
01179
01180
01181 TEMP typename THIS::Iterator THIS::EndByX2(Idx x2) const {
01182 #ifdef FAUDES_CHECKED
01183 if(typeid(Cmp)!=typeid(TransSort::X2EvX1))
01184 if(typeid(Cmp)!=typeid(TransSort::X2X1Ev))
01185 SORT_EXCEPTION;
01186 #endif
01187 Transition tlx(0,0,x2+1);
01188 return ThisIterator(BASE::pSet->lower_bound(tlx));
01189 }
01190
01191
01192 TEMP typename THIS::Iterator THIS::BeginByX2Ev(Idx x2, Idx ev) const {
01193 #ifdef FAUDES_CHECKED
01194 if(typeid(Cmp)!=typeid(TransSort::X2EvX1))
01195 SORT_EXCEPTION;
01196 #endif
01197 Transition tlx(0,ev,x2);
01198 return ThisIterator(BASE::pSet->lower_bound(tlx));
01199 }
01200
01201
01202 TEMP typename THIS::Iterator THIS::EndByX2Ev(Idx x2, Idx ev) const {
01203 #ifdef FAUDES_CHECKED
01204 if(typeid(Cmp)!=typeid(TransSort::X2EvX1))
01205 SORT_EXCEPTION;
01206 #endif
01207 Transition tlx(0,ev+1,x2);
01208 return ThisIterator(BASE::pSet->lower_bound(tlx));
01209 }
01210
01211
01212
01213
01214 TEMP void THIS::DoWrite(TokenWriter& rTw, const std::string& rLabel) const
01215 {
01216 std::string label=rLabel;
01217 if(label=="") label=BASE::Name();
01218 rTw.WriteBegin(label);
01219 int oldcolumns = rTw.Columns();
01220 rTw.Columns(3);
01221 rTw.WriteBegin(label);
01222
01223 Iterator tit;
01224 for (tit = Begin(); tit != End(); ++tit) {
01225 rTw << tit->X1; rTw << tit->Ev; rTw << tit->X2;
01226 }
01227
01228 rTw.WriteEnd(label);
01229 rTw.Columns(oldcolumns);
01230 }
01231
01232
01233
01234 TEMP bool THIS::Insert(const Transition& t) {
01235 return BASE::Insert(t);
01236 }
01237
01238
01239 TEMP bool THIS::Insert(Idx x1, Idx ev, Idx x2) {
01240 FD_DC("TTransSet(" << this << ")::Insert(" << x1 << "-" << ev << "-" << x2 << ")");
01241 return BASE::Insert(Transition(x1, ev, x2));
01242 }
01243
01244
01245 TEMP bool THIS::Erase(const Transition& t) {
01246 return BASE::Erase(t);
01247 }
01248
01249
01250 TEMP bool THIS::Erase(Idx x1, Idx ev, Idx x2) {
01251 FD_DC("TTransSet(" << this << ")::Erase(" << x1 << "-" << ev << "-" << x2 << ")");
01252 return BASE::Erase(Transition(x1, ev, x2));
01253 }
01254
01255
01256 TEMP typename THIS::Iterator THIS::Erase(const Iterator& it) {
01257 FD_DC("TTransSet(" << this << ")::Erase(" << it->X1 << "-" << it->Ev
01258 << "-" << it->X2 << ")");
01259 return BASE::Erase(it);
01260 }
01261
01262
01263 TEMP void THIS::EraseByX1(Idx x1) {
01264 FD_DC("TTransSet(" << this << ")::EraseByX1(" << x1 << ")");
01265 #ifdef FAUDES_CHECKED
01266 if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
01267 if(typeid(Cmp)!=typeid(TransSort::X1X2Ev))
01268 SORT_EXCEPTION;
01269 #endif
01270 BASE::Detach();
01271 typename BASE::iterator lower, upper, it;
01272 Transition tl(x1,0,0);
01273 Transition tu(x1+1,0,0);
01274 lower = BASE::pSet->lower_bound(tl);
01275 upper = BASE::pSet->upper_bound(tu);
01276 BASE::pSet->erase(lower, upper);
01277 }
01278
01279
01280 TEMP void THIS::EraseByX2(Idx x2) {
01281 FD_DC("TTransSet(" << this << ")::EraseByX2(" << x2 << ")");
01282 BASE::Detach();
01283 typename BASE::iterator it, tmpit;
01284 for(it = BASE::pSet->begin(); it != BASE::pSet->end();) {
01285 if (it->X2 == x2) {
01286 tmpit = it;
01287 it++;
01288 BASE::pSet->erase(tmpit);
01289 continue;
01290 }
01291 it++;
01292 }
01293 }
01294
01295
01296 TEMP void THIS::EraseByEv(Idx ev) {
01297 FD_DC("TTransSet(" << this << ")::EraseByEv(" << ev << ")");
01298 BASE::Detach();
01299 typename BASE::iterator it, tmpit;
01300 for(it = BASE::pSet->begin(); it != BASE::pSet->end();) {
01301 if (it->Ev == ev) {
01302 tmpit = it;
01303 it++;
01304 BASE::pSet->erase(tmpit);
01305 continue;
01306 }
01307 it++;
01308 }
01309 }
01310
01311
01312
01313
01314 TEMP void THIS::EraseByX1OrX2(Idx x) {
01315 FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(" << x << ")");
01316 BASE::Detach();
01317 typename BASE::iterator it, tmpit;
01318 for(it = BASE::pSet->begin(); it != BASE::pSet->end();) {
01319 if ((it->X1 == x) || (it->X2 == x)) {
01320 tmpit = it;
01321 it++;
01322 BASE::pSet->erase(tmpit);
01323 continue;
01324 }
01325 it++;
01326 }
01327 FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(" << x << "): done");
01328 }
01329
01330
01331 TEMP typename THIS::Iterator THIS::Find(Idx x1, Idx ev, Idx x2) const {
01332 return BASE::Find(Transition(x1,ev,x2));
01333 }
01334
01335
01336
01337 TEMP typename THIS::Iterator THIS::Find(const Transition& t) const{
01338 return BASE::Find(t);
01339 }
01340
01341
01342 TEMP bool THIS::Exists(const Transition& t) const {
01343 return BASE::Exists(t);
01344 }
01345
01346
01347 TEMP bool THIS::Exists(Idx x1, Idx ev, Idx x2) const {
01348 return BASE::Exists(Transition(x1,ev,x2));
01349 }
01350
01351
01352 TEMP bool THIS::Exists(Idx x) const {
01353 typename BASE::iterator it;
01354 for(it = BASE::pSet->begin(); it != BASE::pSet->end(); ++it) {
01355 if ((it->X1 == x) || (it->X2 == x)) {
01356 return true;
01357 }
01358 }
01359 return false;
01360 }
01361
01362
01363
01364
01365 TEMP template<class OtherCmp>
01366 void THIS::ReSort(TTransSet<OtherCmp>& res) const {
01367 Iterator it;
01368 res.Clear();
01369 for (it = Begin(); it != End(); ++it) {
01370 res.Insert(*it);
01371 }
01372 }
01373
01374
01375 TEMP StateSet THIS::StateSpace(void) const {
01376 StateSet states;
01377 Iterator it;
01378 for (it=Begin(); it!=End(); ++it) {
01379 states.Insert(it->X1);
01380 states.Insert(it->X2);
01381 }
01382 return states;
01383 }
01384
01385
01386 TEMP StateSet THIS::StateSpaceX2(Idx x1) const {
01387 StateSet states;
01388 Iterator it = Begin(x1);
01389 Iterator it_end = End(x1);
01390 while (it != it_end) {
01391 states.Insert(it->X2);
01392 ++it;
01393 }
01394 return states;
01395 }
01396
01397
01398 TEMP StateSet THIS::StateSpaceX2(Idx x1, Idx ev) const {
01399 StateSet states;
01400 Iterator it = Begin(x1, ev);
01401 Iterator it_end = End(x1, ev);
01402 while (it != it_end) {
01403 states.Insert(it->X2);
01404 ++it;
01405 }
01406 return states;
01407 }
01408
01409
01410 TEMP EventSet THIS::ActiveEvents(Idx x1, SymbolTable* pSymTab) const {
01411 Iterator it = Begin(x1);
01412 Iterator it_end = End(x1);
01413 EventSet result;
01414 if(pSymTab!=NULL) result.SymbolTablep(pSymTab);
01415 for (; it != it_end; ++it) {
01416 result.Insert(it->Ev);
01417 }
01418 return result;
01419 }
01420
01421
01422 #undef THIS
01423 #undef TEMP
01424 #undef BASE
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436 #define THIS TaTransSet<Attr>
01437 #define TEMP template <class Attr>
01438 #define BASE TTransSet<TransSort::X1EvX2>
01439
01440
01441
01442 TEMP THIS::TaTransSet(void) : BASE() {
01443 FD_DC("TaTransSet(" << this << ")::TaTransSet()");
01444 }
01445
01446
01447 TEMP THIS::TaTransSet(const TaTransSet& rOtherSet) : BASE(rOtherSet) {
01448 FD_DC("TaTransSet(" << this << ")::TaTransSet(rOtherSet "<< &rOtherSet <<")");
01449 mAttributeMap = rOtherSet.mAttributeMap;
01450 }
01451
01452
01453
01454 TEMP THIS::TaTransSet(const BASE& rOtherSet) :
01455 TransSet(rOtherSet)
01456 {
01457 FD_DC("TaTransSet(" << this << ")::TaTransSet(rOtherSet "<< &rOtherSet <<")");
01458 }
01459
01460
01461 TEMP template<class OtherAttr>
01462 void THIS::CopyWithoutAttributes(TaTransSet<OtherAttr>& res) const{
01463 res.Clear();
01464 Assign(res);
01465 }
01466
01467
01468 TEMP Idx THIS::AttributesSize(void) const {
01469 return (Idx)mAttributeMap.size();
01470 }
01471
01472
01473 TEMP void THIS::Clear(void) {
01474 FD_DC("TaTransSet(" << this << ")::Clear()");
01475 TransSet::Clear();
01476 mAttributeMap.clear();
01477 }
01478
01479
01480 TEMP bool THIS::Insert(const Transition& t) {
01481 FD_DC("TaTransSet(" << this << ")::Insert(" << t.Str() << ")");
01482
01483 return BASE::Insert(t);
01484 }
01485
01486
01487 TEMP bool THIS::Insert(Idx x1, Idx ev, Idx x2) {
01488 FD_DC("TaTransSet(" << this << ")::Insert(" << x1 << "-" << ev << "-" << x2 << ")");
01489 Transition t(x1, ev, x2);
01490
01491 return BASE::Insert(t);
01492 }
01493
01494
01495 TEMP bool THIS::Insert(const Transition& t, const Attr& attr) {
01496 if(attr.IsDefault())
01497 mAttributeMap.erase(t);
01498 else
01499 mAttributeMap[t]=attr;
01500 return BASE::Insert(t);
01501 }
01502
01503
01504 TEMP bool THIS::Erase(const Transition& t) {
01505 bool ret= BASE::Erase(t);
01506 mAttributeMap.erase(t);
01507 return ret;
01508 }
01509
01510
01511 TEMP bool THIS::Erase(Idx x1, Idx ev, Idx x2) {
01512 FD_DC("TaTransSet(" << this << ")::Erase(" << x1 << "-" << ev << "-" << x2 << ")");
01513 Transition t(x1, ev, x2);
01514 mAttributeMap.erase(t);
01515 return BASE::Erase(t);
01516 }
01517
01518
01519 TEMP typename THIS::Iterator THIS::Erase(const Iterator& it) {
01520 #ifdef FAUDES_CHECKED
01521 if (it == End()) {
01522 std::stringstream errstr;
01523 errstr << "iterator out of range " << std::endl;
01524 throw Exception("TTransSet::Erase", errstr.str(), 69);
01525 }
01526 #endif
01527 BASE::Detach();
01528 FD_DC("TaTransSet(" << this << ")::Erase(" << it->X1 << "-" << it->Ev
01529 << "-" << it->X2 << ")");
01530 mAttributeMap.erase(*it);
01531 return BASE::Erase(it);
01532 }
01533
01534
01535 TEMP void THIS::EraseByX1(Idx x1) {
01536 FD_DC("TaTransSet(" << this << ")::EraseByX1(" << x1 << ")");
01537 BASE::Detach();
01538 BASE::iterator lower, upper, it;
01539 Transition tl(x1,0,0);
01540 Transition tu(x1+1,0,0);
01541 lower = BASE::pSet->lower_bound(tl);
01542 upper = BASE::pSet->upper_bound(tu);
01543 if(mAttributeMap.size()!=0)
01544 for(it=lower; it!=upper; ++it)
01545 mAttributeMap.erase(*it);
01546 BASE::pSet->erase(lower, upper);
01547 }
01548
01549
01550 TEMP void THIS::EraseByX2(Idx x2) {
01551 FD_DC("TaTransSet(" << this << ")::EraseByX2(" << x2 << ")");
01552 BASE::Detach();
01553 BASE::iterator it, tmpit;
01554 for(it = BASE::pSet->begin(); it !=BASE::pSet->end();) {
01555 if (it->X2 == x2) {
01556 tmpit = it;
01557 it++;
01558 mAttributeMap.erase(*tmpit);
01559 BASE::pSet->erase(tmpit);
01560 continue;
01561 }
01562 it++;
01563 }
01564 }
01565
01566
01567 TEMP void THIS::EraseByEv(Idx ev) {
01568 FD_DC("TaTransSet(" << this << ")::EraseByEv(" << ev << ")");
01569 BASE::Detach();
01570 BASE::iterator it, tmpit;
01571 for(it = BASE::pSet->begin(); it !=BASE::pSet->end();) {
01572 if (it->Ev == ev) {
01573 tmpit = it;
01574 it++;
01575 mAttributeMap.erase(*tmpit);
01576 BASE::pSet->erase(tmpit);
01577 continue;
01578 }
01579 it++;
01580 }
01581 }
01582
01583
01584
01585
01586 TEMP void THIS::EraseByX1OrX2(Idx x) {
01587 FD_DC("TaTransSet(" << this << ")::EraseByX1OrX2(" << x << ")");
01588 BASE::Detach();
01589 BASE::iterator it, tmpit;
01590 for(it = BASE::pSet->begin(); it !=BASE::pSet->end();) {
01591 if ((it->X1 == x) || (it->X2 == x)) {
01592 tmpit = it;
01593 it++;
01594 mAttributeMap.erase(*tmpit);
01595 BASE::pSet->erase(tmpit);
01596 continue;
01597 }
01598 it++;
01599 }
01600 }
01601
01602
01603 TEMP Attr* THIS::Attributep(const Transition& rTrans) {
01604 #ifdef FAUDES_CHECKED
01605 if (!Exists(rTrans)) {
01606 std::stringstream errstr;
01607 errstr << "transition " << rTrans.Str() << " not member of set" << std::endl;
01608 throw Exception("TTransSet::Attributep(t)", errstr.str(), 60);
01609 }
01610 #endif
01611 typename std::map<Transition,Attr>::iterator ait;
01612 ait=mAttributeMap.find(rTrans);
01613 if( ait!=mAttributeMap.end() )
01614 return & (ait->second);
01615
01616 typename std::map<Transition,Attr>::value_type entry(rTrans,mDefAttribute);
01617 ait=mAttributeMap.insert(entry).first;
01618 return & (ait->second);
01619 }
01620
01621
01622 TEMP const Attr& THIS::Attribute(const Transition& rTrans) const {
01623 #ifdef FAUDES_CHECKED
01624 if (!Exists(rTrans)) {
01625 std::stringstream errstr;
01626 errstr << "transition " << rTrans.Str() << " not member of set" << std::endl;
01627 throw Exception("TTransSet::Attribute(t)", errstr.str(), 60);
01628 }
01629 #endif
01630 typename std::map<Transition,Attr>::const_iterator ait;
01631 ait=mAttributeMap.find(rTrans);
01632 if( ait!=mAttributeMap.end() ) {
01633 return ait->second;
01634 }
01635 return mDefAttribute;
01636 }
01637
01638
01639 TEMP void THIS::Attribute(const Transition& rTrans, const Attr& rAttr) {
01640 #ifdef FAUDES_CHECKED
01641 if (!Exists(rTrans)) {
01642 std::stringstream errstr;
01643 errstr << "transition " << rTrans.Str() << " not member of set" << std::endl;
01644 throw Exception("TTransSet::Attribute(t,attr)", errstr.str(), 60);
01645 }
01646 #endif
01647 if(rAttr.IsDefault())
01648 mAttributeMap.erase(rTrans);
01649 else
01650 mAttributeMap[rTrans]=rAttr;
01651 }
01652
01653
01654 TEMP void THIS::ClearAttributes(void) {
01655 mAttributeMap.clear();
01656 }
01657
01658 #undef THIS
01659 #undef TEMP
01660 #undef BASE
01661
01662 #undef SORT_EXECPTION
01663
01664 }
01665
01666
01667
01668
01669 #define TRANSSET_H
01670 #endif
01671