|
libFAUDES
Sections
Index
|
cfl_agenerator.hGo to the documentation of this file.00001 /** @file cfl_agenerator.h Attributed generator class TaGenerator */ 00002 00003 /* FAU Discrete Event Systems Library (libfaudes) 00004 00005 Copyright (C) 2006 Bernd Opitz 00006 Copyright (C) 2007 Thomas Moor 00007 Exclusive copyright is granted to Klaus Schmidt 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00022 00023 00024 #ifndef FAUDES_AGENERATOR_H 00025 #define FAUDES_AGENERATOR_H 00026 00027 #include "cfl_definitions.h" 00028 #include "cfl_exception.h" 00029 #include "cfl_symboltable.h" 00030 #include "cfl_indexset.h" 00031 #include "cfl_nameset.h" 00032 #include "cfl_transset.h" 00033 #include "cfl_token.h" 00034 #include "cfl_tokenreader.h" 00035 #include "cfl_tokenwriter.h" 00036 #include "cfl_generator.h" 00037 #include <map> 00038 #include <set> 00039 #include <sstream> 00040 #include <cstdlib> 00041 #include <assert.h> 00042 00043 namespace faudes { 00044 00045 /** 00046 * Generator with specified attribute types. 00047 * 00048 * @section Overview 00049 * 00050 * The TaGenerator takes four template parameters to specify attribute classes for 00051 * the global attribute and state-, event- and transition-attributes. 00052 * 00053 * In the context of a TaGenerator, attributes still have only minimal sematics: they can be 00054 * accessed in a per event, state and transition manner and they can have default or non-default value. 00055 * The minimum interface that an attribute template parameter must provide, is given in 00056 * faudes::AttributeVoid. Derived attribute classes are meant to provide addtional semantics, eg 00057 * faudes::AttributeFlags for boolean flags and faudes::AttributeCFlags for controllability properties. 00058 * The TaGenerator transparently supports extended attribute semantics, buit does not provide 00059 * taylored access functions. This is done in TaGenerator 00060 * derivates eg TcGenerator. 00061 * 00062 * Technical detail: Attributes data types must be derived from AttributeVoid, which in turn is derived from 00063 * the general purpose base faudes::Type. For your derived attribute class to be fully functional, 00064 * you must reimplement the faudes::Type::New(). 00065 * 00066 * @ingroup GeneratorClasses 00067 */ 00068 00069 template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr> 00070 class TaGenerator : public vGenerator { 00071 public: 00072 00073 /** Convenience typdef for member transiton set */ 00074 typedef TaTransSet<TransAttr> ATransSet; 00075 00076 /***************************************** 00077 ***************************************** 00078 ***************************************** 00079 *****************************************/ 00080 00081 /** @name Constructors & Destructor */ 00082 /** @{ doxygen group */ 00083 00084 /** 00085 * Construct an emtpy Generator 00086 */ 00087 TaGenerator(void); 00088 00089 /** 00090 * Copy-constructor (from TaGenerator, incl attributes) 00091 * 00092 * @param rOtherGen 00093 */ 00094 TaGenerator(const TaGenerator& rOtherGen); 00095 00096 /** 00097 * Copy-constructor (from vGenerator, set attributes to default) 00098 * 00099 * @param rOtherGen 00100 */ 00101 TaGenerator(const vGenerator& rOtherGen); 00102 00103 /** 00104 * Construct from file. This constructor 00105 * effectively uses the Read(TokenReader&) function to read. 00106 * 00107 * @param rFileName 00108 * Name of file 00109 * 00110 * @exception Exception 00111 * - IO errors (id 1) 00112 * - Token mismatch (id 50, 51, 52, 80, 85) 00113 */ 00114 TaGenerator(const std::string& rFileName); 00115 00116 /** 00117 * Construct on heap. 00118 * Technically not a constructor, this function creates a TaGenerator with the 00119 * same event symboltable and the same attribute types. It is the callers reponsebilty to 00120 * delete the object when no longer needed. 00121 * 00122 * @return 00123 * new Generator 00124 */ 00125 virtual TaGenerator* New(void) const; 00126 00127 /** 00128 * Construct copy on heap. 00129 * Technically not a constructor, this function creates a TaGenerator with the 00130 * same event symboltable and the same attribute types. It is the callers reponsebilty to 00131 * delete the object when no longer needed. 00132 * 00133 * @return 00134 * new Generator 00135 */ 00136 virtual TaGenerator* Copy(void) const; 00137 00138 /** 00139 * Construct on stack. 00140 * Technically not a constructor, this function creates a TaGenerator with the 00141 * same event symboltable and the same attribute type. 00142 * 00143 * @return 00144 * new Generator 00145 */ 00146 virtual TaGenerator NewAGen(void) const; 00147 00148 /** 00149 * Destructor 00150 */ 00151 virtual ~TaGenerator(void); 00152 00153 /** @} doxygen group */ 00154 00155 /***************************************** 00156 ***************************************** 00157 ***************************************** 00158 *****************************************/ 00159 00160 /** @name Copy and Assignment */ 00161 /** @{ doxygen group */ 00162 00163 00164 /** 00165 * Copy from other TaGenerator (incl attributes) 00166 * 00167 * @param rGen 00168 * Source for copy operation. 00169 */ 00170 virtual TaGenerator& Assign(const TaGenerator& rGen); 00171 00172 /** 00173 * Copy from other vGenerator (try to maintain attributes) 00174 * 00175 * @param rGen 00176 * Source for copy operation. 00177 */ 00178 virtual TaGenerator& Assign(const vGenerator& rGen); 00179 00180 /** 00181 * Destructive copy to other TaGenerator 00182 * Copy method with increased performance at the cost of invalidating 00183 * the source data. This version will copy attributes 1:1. 00184 * 00185 * 00186 * @param rGen 00187 * Destination for copy operation. 00188 */ 00189 virtual void Move(TaGenerator& rGen); 00190 00191 /** 00192 * Destructive copy to other vGenerator. 00193 * Copy method with increased performance at the cost of invalidating 00194 * the source data. Convert attributes if possible. 00195 * 00196 * 00197 * @param rGen 00198 * Destination for copy operation. 00199 */ 00200 virtual void Move(vGenerator& rGen); 00201 00202 /** 00203 * Assignment operator (uses Copy(TaGenerator&) ) 00204 * 00205 * @param rOtherGen 00206 * Other generator 00207 */ 00208 virtual TaGenerator& operator= (const TaGenerator& rOtherGen); 00209 00210 /** 00211 * Assignment operator (uses Copy(vGenerator&) ) 00212 * 00213 * @param rOtherGen 00214 * Other generator 00215 */ 00216 virtual TaGenerator& operator= (const vGenerator& rOtherGen); 00217 00218 00219 /** @} doxygen group */ 00220 00221 /***************************************** 00222 ***************************************** 00223 ***************************************** 00224 *****************************************/ 00225 00226 /** @name Basic Maintenance */ 00227 /** @{ doxygen group */ 00228 00229 /** 00230 * Check if generator is valid 00231 * 00232 * @return 00233 * Success 00234 */ 00235 bool Valid(void); 00236 00237 00238 /** 00239 * Clear generator data. 00240 * Clears state set, alphabet and transitionrealtion. Behavioural flags 00241 * eg StateNamesEnabled are maintained. 00242 */ 00243 virtual void Clear(void); 00244 00245 00246 00247 /** @} doxygen group */ 00248 00249 00250 00251 /***************************************** 00252 ***************************************** 00253 ***************************************** 00254 *****************************************/ 00255 00256 /** @name Read Access to Core Members */ 00257 /** @{ doxygen group */ 00258 00259 /** 00260 * Return const reference to alphabet 00261 * 00262 * @return EventSet 00263 * Reference to mpAlphabet 00264 */ 00265 const TaEventSet<EventAttr>& Alphabet(void) const; 00266 00267 /** 00268 * Return reference to state set 00269 * 00270 * @return 00271 * StateSet reference incl actual attribute type 00272 */ 00273 const TaStateSet<StateAttr>& States(void) const; 00274 00275 /** 00276 * Return reference to transition relation 00277 * 00278 * @return TransRel 00279 */ 00280 const ATransSet& TransRel(void) const; 00281 00282 /** 00283 * Get copy of trantision relation sorted by other compare 00284 * operator, e.g. "x2,ev,x1" 00285 * 00286 * @param res 00287 * resulting transition relation 00288 */ 00289 void TransRel(TransSetX1EvX2& res) const; 00290 void TransRel(TransSetEvX1X2& res) const; 00291 void TransRel(TransSetEvX2X1& res) const; 00292 void TransRel(TransSetX2EvX1& res) const; 00293 void TransRel(TransSetX2X1Ev& res) const; 00294 void TransRel(TransSetX1X2Ev& res) const; 00295 00296 /** @} doxygen group */ 00297 00298 00299 00300 /***************************************** 00301 ***************************************** 00302 ***************************************** 00303 *****************************************/ 00304 00305 /** @name Write Access to Core Members */ 00306 /** @{ doxygen group */ 00307 00308 00309 /** 00310 * Add an existing event to alphabet by index. It is an error to insert 00311 * an event index that is not known to the mpEventSymbolTable. 00312 * 00313 * @param index 00314 * Event index 00315 * @return 00316 * True, if event was new to alphabet 00317 */ 00318 bool InsEvent(Idx index); 00319 00320 /** 00321 * Add named event to generator. An entry in the mpEventSymbolTable will 00322 * be made if event name is not known so far. 00323 * 00324 * @param rName 00325 * Name of the event to add 00326 * 00327 * @return 00328 * New unique index 00329 */ 00330 Idx InsEvent(const std::string& rName); 00331 00332 /** 00333 * Add an existing event to alphabet by index, incl. attribute 00334 * If the index allready exists, the attribute is overwritten by rAttr. 00335 * 00336 * @param rAttr 00337 * Attribute of event 00338 * @param index 00339 * Event index 00340 * @return 00341 * True, if event was new to alphabet 00342 */ 00343 bool InsEvent(Idx index, const EventAttr& rAttr); 00344 00345 /** 00346 * Add named event with attribute to generator. An entry in the 00347 * mpEventSymbolTable will be made if event is not kown so far. 00348 * If the event allready exits in the generator, the attribute will be 00349 * overwritten by rAttr. 00350 * 00351 * @param rName 00352 * Name of the event to add 00353 * @param rAttr 00354 * Attribute of event 00355 * 00356 * @return 00357 * New unique index 00358 */ 00359 Idx InsEvent(const std::string& rName, const EventAttr& rAttr); 00360 00361 /** 00362 * Set mpAlphabet without consistency check. 00363 * Attributes will be casted if possible or silently ignored. 00364 * 00365 * @param rNewalphabet 00366 * EventSet with new alphabet 00367 */ 00368 void InjectAlphabet(const EventSet& rNewalphabet); 00369 00370 /** 00371 * Set mpAlphabet without consistency check. 00372 * 00373 * @param rNewalphabet 00374 * EventSet with new alphabet 00375 */ 00376 void InjectAlphabet(const TaEventSet<EventAttr>& rNewalphabet); 00377 00378 /** 00379 * Add new anonymous state to generator 00380 * 00381 * @return 00382 * Index of new unique state 00383 */ 00384 Idx InsState(void); 00385 00386 /** 00387 * Add new anonymous state with attribute to generator 00388 * 00389 * @param attr 00390 * attribute of new state 00391 * 00392 * @return 00393 * Index of new unique state 00394 */ 00395 Idx InsState(const StateAttr& attr); 00396 00397 /** 00398 * Add (perhaps new) state to generator 00399 * 00400 * @return 00401 * true to indicate that state was new to generator 00402 */ 00403 bool InsState(Idx index); 00404 00405 /** 00406 * Add new named state to generator. 00407 * 00408 * @param rName 00409 * Name of the state to add 00410 * 00411 * @return 00412 * Index of new unique state 00413 * 00414 * @exception Exception 00415 * Name already exists (id 44) 00416 */ 00417 Idx InsState(const std::string& rName); 00418 00419 /** 00420 * Add new named state with attribute to generator. 00421 * 00422 * @param rName 00423 * Name of the state to add 00424 * @param attr 00425 * attribute of new state 00426 * 00427 * @return 00428 * Index of new unique state 00429 * @exception Exception 00430 * Name already exists (id 44) 00431 */ 00432 Idx InsState(const std::string& rName, const StateAttr& attr); 00433 00434 /** 00435 * Add (perhaps new) state with attribute to generator. 00436 * 00437 * @param index 00438 * Index of state to add 00439 * @param attr 00440 * Attribute of new state 00441 * 00442 * @return 00443 * True, if event was new to alphabet 00444 * 00445 */ 00446 bool InsState(Idx index, const StateAttr& attr); 00447 00448 /** 00449 * Inject a complete state set without consistency checks. 00450 * Attributes will be casted if possible or silently ignored. 00451 * 00452 * @param rNewStates 00453 * StateSet 00454 */ 00455 void InjectStates(const StateSet& rNewStates); 00456 00457 00458 /** 00459 * Inject a complete state set without consistency checks. 00460 * 00461 * @param rNewStates 00462 * StateSet 00463 */ 00464 void InjectStates(const TaStateSet<StateAttr>& rNewStates); 00465 00466 00467 /** 00468 * Add a transition to generator by indices. States and event 00469 * must already exist! 00470 * 00471 * Define FAUDES_CHECKED for consistency checks. 00472 * 00473 * @param x1 00474 * Predecessor state index 00475 * @param ev 00476 * Event index 00477 * @param x2 00478 * Successor state index 00479 * 00480 * @return 00481 * True, if the transition was new the generator 00482 * 00483 * @exception Exception 00484 * - state or event not in generator (id 95) 00485 */ 00486 bool SetTransition(Idx x1, Idx ev, Idx x2); 00487 00488 /** 00489 * Add a transition to generator by names. Statename and eventname 00490 * must already exist! 00491 * 00492 * @param rX1 00493 * Predecessor state name 00494 * @param rEv 00495 * Event name 00496 * @param rX2 00497 * Successor state name 00498 * 00499 * @return 00500 * True, if the transition was new the generator 00501 * 00502 * @exception Exception 00503 * - state or event not in generator (id 95) 00504 * - state name not known (id 90) 00505 * - event name not known (id 66) 00506 */ 00507 bool SetTransition(const std::string& rX1, const std::string& rEv, 00508 const std::string& rX2); 00509 00510 /** 00511 * Add a transition to generator. States and event 00512 * must already exist! 00513 * 00514 * 00515 * @param rTransition 00516 * Transition 00517 * 00518 * @return 00519 * True, if the transition was new the generator 00520 * @exception Exception 00521 * - state or event not in generator (id 95) 00522 */ 00523 bool SetTransition(const Transition& rTransition); 00524 00525 /** 00526 * Add a transition with attribute to generator. States and event 00527 * must already exist! 00528 * 00529 * 00530 * @param rTransition 00531 * transition 00532 * @param rAttr 00533 * attribute 00534 * @return 00535 * True, if the transition was new the generator 00536 * @exception Exception 00537 * - state or event not in generator (id 95) 00538 * 00539 */ 00540 bool SetTransition(const Transition& rTransition, const TransAttr& rAttr); 00541 00542 /** 00543 * Set transition relation without consistency check. 00544 * Attributes will be casted if possible or silently ignored. 00545 * 00546 * @param rNewtransrel 00547 * TransRel to insert 00548 */ 00549 void InjectTransRel(const TransSet& rNewtransrel); 00550 00551 /** 00552 * Set transition relation without consistency check. 00553 * 00554 * @param rNewtransrel 00555 * TransRel to insert 00556 */ 00557 void InjectTransRel(const ATransSet& rNewtransrel); 00558 00559 /** @} doxygen group */ 00560 00561 00562 00563 /***************************************** 00564 ***************************************** 00565 ***************************************** 00566 *****************************************/ 00567 00568 /** @name Attributes */ 00569 /** @{ doxygen group */ 00570 00571 00572 /** 00573 * Set attribute for existing event 00574 * 00575 * @param index 00576 * Event index 00577 * @param rAttr 00578 * New attribute 00579 * 00580 * @exception Exception 00581 * Index not found in alphabet (id 60) 00582 */ 00583 void EventAttribute(Idx index, const EventAttr& rAttr); 00584 00585 /** 00586 * Set attribute for existing event. 00587 * This version uses a dynamic cast 00588 * to test the actual type of the provided attribute. An exception is 00589 * thrown for an invalid attribute type. 00590 * 00591 * @param index 00592 * Event index 00593 * @param rAttr 00594 * New attribute 00595 * 00596 * @exception Exception 00597 * - Index not found in alphabet (id 60) 00598 * - Cannot cast attribute (id 63) 00599 */ 00600 void EventAttribute(Idx index, const Type& rAttr); 00601 00602 /** 00603 * Event attribute lookup 00604 * 00605 * @param index 00606 * 00607 * @return 00608 * reference to attribute 00609 */ 00610 const EventAttr& EventAttribute(Idx index) const; 00611 00612 /** 00613 * Event attribute lookup 00614 * 00615 * @param rName 00616 * 00617 * @return 00618 * reference to attribute 00619 */ 00620 const EventAttr& EventAttribute(const std::string& rName) const; 00621 00622 /** 00623 * Event attribute pointer (to access Attribute methods) 00624 * note: may insert explicit default attribute 00625 * 00626 * @param index 00627 * 00628 * @return 00629 * pointer to attribute 00630 */ 00631 EventAttr* EventAttributep(Idx index); 00632 00633 /** 00634 * Event attribute pointer (to access Attribute methods) 00635 * note: may insert explicit default attribute 00636 * 00637 * @param rName 00638 * 00639 * @return 00640 * pointer to attribute 00641 */ 00642 EventAttr* EventAttributep(const std::string& rName); 00643 00644 00645 /** 00646 * Set attribute for existing state 00647 * 00648 * @param index 00649 * Index 00650 * @param rAttr 00651 * attriute 00652 * 00653 * @exception Exception 00654 * Name already associated with another index (id 44) 00655 */ 00656 void StateAttribute(Idx index, const StateAttr& rAttr); 00657 00658 /** 00659 * Set attribute for existing state. 00660 * This version uses a dynamic cast 00661 * to test the actual type of the provided attribute. An exception is 00662 * thrown for an invalid attribute type. 00663 * 00664 * @param index 00665 * State index 00666 * @param rAttr 00667 * New attribute 00668 * 00669 * @exception Exception 00670 * - Index not found in Stateset (id 60) 00671 * - Cannot cast attribute (id 63) 00672 */ 00673 void StateAttribute(Idx index, const Type& rAttr); 00674 00675 /** 00676 * State attribute lookup 00677 * 00678 * @param index 00679 * 00680 * @return ref to attribute of state 00681 */ 00682 const StateAttr& StateAttribute(Idx index) const; 00683 00684 /** 00685 * State attribute pointer (to access Attribute methods) 00686 * note: may insert explicit default attribute 00687 * 00688 * @param index 00689 * 00690 * @return pointer to attribute of state 00691 */ 00692 StateAttr* StateAttributep(Idx index); 00693 00694 /** 00695 * Set attribute for existing transition 00696 * 00697 * @param rTrans 00698 * transition 00699 * @param rAttr 00700 * New attribute 00701 * 00702 */ 00703 void TransAttribute(const Transition& rTrans, const TransAttr& rAttr); 00704 00705 /** 00706 * Set attribute for existing transition. 00707 * This version uses a dynamic cast 00708 * to test the actual type of the provided attribute. An exception is 00709 * thrown for an invalid attribute type. 00710 * 00711 * @param rTrans 00712 * transition 00713 * @param rAttr 00714 * New attribute 00715 * 00716 * @exception Exception 00717 * - Transition not found in transition relation(id 60) 00718 * - Cannot cast attribute (id 63) 00719 */ 00720 void TransAttribute(const Transition& rTrans, const Type& rAttr); 00721 00722 00723 /** 00724 * Get attribute for existing transition 00725 * 00726 * @return 00727 * attribute 00728 * 00729 */ 00730 const TransAttr& TransAttribute(const Transition& rTrans) const; 00731 00732 /** 00733 * Get attribute pointer for existing transition 00734 * note: may insert explicit default attribute 00735 * 00736 * @return 00737 * attribute pointer 00738 * 00739 */ 00740 TransAttr* TransAttributep(const Transition& rTrans); 00741 00742 /** 00743 * Set global attribute 00744 * 00745 * @param rAttr 00746 * attribute 00747 */ 00748 void GlobalAttribute(const GlobalAttr& rAttr) {*pGlobalAttribute=rAttr;}; 00749 00750 /** 00751 * Get global attribute ref 00752 */ 00753 const GlobalAttr& GlobalAttribute(void) const {return *pGlobalAttribute;}; 00754 00755 00756 /** 00757 * Get global attribute pointer 00758 */ 00759 GlobalAttr* GlobalAttributep(void) {return pGlobalAttribute;}; 00760 00761 00762 /** @} doxygen group */ 00763 00764 00765 00766 00767 protected: 00768 00769 /** Alphabet, pointer with actual attribute type */ 00770 TaNameSet<EventAttr>* pAlphabet; 00771 00772 /** State set, pointer with actual attribute type */ 00773 TaIndexSet<StateAttr>* pStates; 00774 00775 /** Transition relation, pointer with actual attribute type */ 00776 ATransSet* pTransRel; 00777 00778 /** Global attribute, pointer with actual attribute type */ 00779 GlobalAttr* pGlobalAttribute; 00780 00781 /** Static default alphabet prototype (incl. attribute type) */ 00782 static const TaNameSet<EventAttr>& AlphabetTaGen(void); 00783 00784 /** Static default state set prototype (incl. attribute type) */ 00785 static const TaIndexSet<StateAttr>& StatesTaGen(void); 00786 00787 /** Static default transition relation prototype (incl. attribute type) */ 00788 static const ATransSet& TransRelTaGen(void); 00789 00790 /** Static default global attribute prototype (configures global attribute type) */ 00791 static const GlobalAttr& GlobalTaGen(void); 00792 00793 /** Allocate my heap members (attribute dependent types) */ 00794 virtual void NewCore(void); 00795 00796 /** Update my secondary pointers for new core */ 00797 virtual void UpdateCore(void); 00798 00799 00800 }; 00801 00802 00803 00804 /* convenience access to relevant scopes */ 00805 #define THIS TaGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr> 00806 #define TEMP template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr> 00807 #define BASE vGenerator 00808 00809 // static default prototypes (construct on first use design pattern) 00810 TEMP const TaNameSet<EventAttr>& THIS::AlphabetTaGen(void) { 00811 static TaNameSet<EventAttr>* pstatic = new TaNameSet<EventAttr>(); 00812 return *pstatic; 00813 } 00814 TEMP const TaIndexSet<StateAttr>& THIS::StatesTaGen(void) { 00815 static TaIndexSet<StateAttr>* pstatic = new TaIndexSet<StateAttr>(); 00816 return *pstatic; 00817 } 00818 TEMP const TaTransSet<TransAttr>& THIS::TransRelTaGen(void) { 00819 static TaTransSet<TransAttr>* pstatic = new TaTransSet<TransAttr>(); 00820 return *pstatic; 00821 } 00822 TEMP const GlobalAttr& THIS::GlobalTaGen(void) { 00823 static GlobalAttr* pstatic = new GlobalAttr(); 00824 return *pstatic; 00825 } 00826 00827 00828 // Generator::Generator(void) 00829 TEMP THIS::TaGenerator(void) : 00830 // init base 00831 vGenerator() 00832 { 00833 FD_DG("TaGenerator(" << this << ")::TaGenerator()"); 00834 // re-allocate core members with nontrivial attribute types 00835 ConfigureAttributeTypes(&GlobalTaGen(),&StatesTaGen(),&AlphabetTaGen(),&TransRelTaGen()); 00836 NewCore(); 00837 FD_DG("TaGenerator(" << this << ")::TaGenerator(): done"); 00838 } 00839 00840 // Generator::Generator(rOtherGen) 00841 TEMP THIS::TaGenerator(const TaGenerator& rOtherGen) : 00842 // init base 00843 vGenerator() 00844 { 00845 FD_DG("TaGenerator(" << this << ")::TaGenerator(" << &rOtherGen << ")"); 00846 // re-allocate core members with nontrivial attribute types 00847 ConfigureAttributeTypes(&GlobalTaGen(),&StatesTaGen(),&AlphabetTaGen(),&TransRelTaGen()); 00848 NewCore(); 00849 // have a 1:1 copy (incl sym tables) 00850 Assign(rOtherGen); 00851 } 00852 00853 00854 // Generator::Generator(rOtherGen) 00855 TEMP THIS::TaGenerator(const vGenerator& rOtherGen) : 00856 // init base 00857 vGenerator() 00858 { 00859 FD_DG("TaGenerator(" << this << ")::TaGenerator([v]" << &rOtherGen << ")"); 00860 // re-allocate core members with nontrivial attribute types 00861 ConfigureAttributeTypes(&GlobalTaGen(),&StatesTaGen(),&AlphabetTaGen(),&TransRelTaGen()); 00862 NewCore(); 00863 // have a 1:1 copy (incl sym tables) 00864 Assign(rOtherGen); 00865 } 00866 00867 // Generator::Generator(rFileName) 00868 TEMP THIS::TaGenerator(const std::string& rFileName) : 00869 // init base 00870 vGenerator() 00871 { 00872 FD_DG("TaGenerator(" << this << ")::TaGenerator(" << rFileName << ")"); 00873 // re-allocate core members with nontrivial attribute types 00874 ConfigureAttributeTypes(&GlobalTaGen(),&StatesTaGen(),&AlphabetTaGen(),&TransRelTaGen()); 00875 NewCore(); 00876 // set some defaults 00877 mStateNamesEnabled=true; 00878 // do read 00879 Read(rFileName); 00880 // get original statenames default 00881 mStateNamesEnabled=msStateNamesEnabledDefault; 00882 } 00883 00884 // allocate core on heap 00885 TEMP void THIS::NewCore(void) { 00886 FD_DG("TaGenerator(" << this << ")::NewCore()"); 00887 // call base, incl virtual call back of UpdateCore 00888 BASE::NewCore(); 00889 } 00890 00891 // indicate new core 00892 TEMP void THIS::UpdateCore(void) { 00893 // let base do an update (fixes names) 00894 BASE::UpdateCore(); 00895 // have pointer with my attribute 00896 pGlobalAttribute = dynamic_cast< GlobalAttr* >(mpGlobalAttribute); 00897 pAlphabet = dynamic_cast< TaNameSet<EventAttr>* >(mpAlphabet); 00898 pStates = dynamic_cast< TaIndexSet<StateAttr>* >(mpStates); 00899 pTransRel = dynamic_cast< ATransSet* >(mpTransRel); 00900 // check for type mismatche 00901 bool tmm=false; 00902 if(pGlobalAttribute==0 && mpGlobalAttribute!=0) tmm=true; 00903 if(pAlphabet==0 && mpAlphabet!=0) tmm=true; 00904 if(pStates==0 && mpStates!=0) tmm=true; 00905 if(pTransRel==0 && mpTransRel!=0) tmm=true; 00906 if(tmm) { 00907 std::stringstream errstr; 00908 errstr << "cannot cast attributes for generator " << Name(); 00909 throw Exception("vGenerator::UpdateCore", errstr.str(), 63); 00910 } 00911 } 00912 00913 00914 // Copy(gen) from identical type 00915 TEMP THIS& THIS::Assign(const TaGenerator& rGen) { 00916 FD_DG("TaGenerator(" << this << ")::Assign(" << &rGen << ")"); 00917 // prepare result (call clear for virtual stuff) 00918 Clear(); 00919 // have same event symboltable 00920 EventSymbolTablep(rGen.mpEventSymbolTable); 00921 // copy state symboltable 00922 StateSymbolTable(rGen.mStateSymbolTable); 00923 // set other members 00924 Name(rGen.Name()); 00925 *pGlobalAttribute=*rGen.pGlobalAttribute; 00926 *pStates= *rGen.pStates; 00927 *pAlphabet = *rGen.pAlphabet; 00928 *pTransRel= *rGen.pTransRel; 00929 mInitStates = rGen.mInitStates; 00930 mMarkedStates = rGen.mMarkedStates; 00931 mStateNamesEnabled=rGen.mStateNamesEnabled; 00932 // copy add on stuff 00933 mMinStateIndexMap=rGen.mMinStateIndexMap; 00934 #ifdef FAUDES_DEBUG_CODE 00935 if(!Valid()) { 00936 FD_DG("TaGenerator()::Assign(): invalid generator"); 00937 DWrite(); 00938 abort(); 00939 } 00940 #endif 00941 return *this; 00942 } 00943 00944 // Copy(gen) to other generator type 00945 TEMP THIS& THIS::Assign(const vGenerator& rGen) { 00946 FD_DG("TaGenerator(" << this << ")::Assign([v]" << &rGen << ")"); 00947 FD_DG("TaGenerator(" << this << ")::Assign(): src type " << typeid(rGen).name()); 00948 FD_DG("TaGenerator(" << this << ")::Assign(): dst type " << typeid(*this).name()); 00949 // call base 00950 BASE::Assign(rGen); 00951 // report 00952 #ifdef FAUDES_DEBUG_GENERATOR 00953 // FD_DG("TaGenerator(" << this << ")::Copy([type " << typeid(rGen).name() <<"]" << &rGen << "): report"); 00954 // Write(); 00955 // rGen.Write(); 00956 #endif 00957 return *this; 00958 } 00959 00960 00961 // Move(gen) destructive copy 00962 TEMP void THIS::Move(TaGenerator& rGen) { 00963 FD_DG("TaGenerator(" << this << ")::Move(" << &rGen << ")"); 00964 // call base 00965 BASE::Move(rGen); 00966 } 00967 00968 00969 // Move(gen) destructive copy 00970 TEMP void THIS::Move(vGenerator& rGen) { 00971 FD_DG("TaGenerator(" << this << ")::Move([v]" << &rGen << ")"); 00972 // call base 00973 BASE::Move(rGen); 00974 } 00975 00976 // Generator::~Generator 00977 TEMP THIS::~TaGenerator(void) { 00978 FD_DG("TaGenerator(" << this << ")::~TaGenerator()"); 00979 } 00980 00981 // New 00982 TEMP THIS* THIS::New(void) const { 00983 // allocate 00984 THIS* res = new THIS; 00985 // fix base data 00986 res->EventSymbolTablep(BASE::mpEventSymbolTable); 00987 res->mStateNamesEnabled=BASE::mStateNamesEnabled; 00988 return res; 00989 } 00990 00991 // Copy 00992 TEMP THIS* THIS::Copy(void) const { 00993 // allocate 00994 THIS* res = new THIS(*this); 00995 // done 00996 return res; 00997 } 00998 00999 // NewAGen() 01000 TEMP THIS THIS::NewAGen(void) const { 01001 THIS res; 01002 // fix base data 01003 res.EventSymbolTablep(BASE::mpEventSymbolTable); 01004 res.mStateNamesEnabled=BASE::mStateNamesEnabled; 01005 return res; 01006 } 01007 01008 01009 // operator= 01010 TEMP TaGenerator<GlobalAttr,StateAttr,EventAttr,TransAttr>& THIS::operator= (const TaGenerator& rOtherGen) { 01011 FD_DG("TaGenerator(" << this << ")::operator = " << &rOtherGen); 01012 return Assign(rOtherGen); 01013 } 01014 01015 // operator= 01016 TEMP TaGenerator<GlobalAttr,StateAttr,EventAttr,TransAttr>& THIS::operator= (const vGenerator& rOtherGen) { 01017 FD_DG("TaGenerator(" << this << ")::operator = [v]" << &rOtherGen); 01018 return Assign(rOtherGen); 01019 } 01020 01021 // Valid() 01022 TEMP bool THIS::Valid(void) { 01023 FD_DG("TaGenerator(" << this << ")::Valid()"); 01024 if(!BASE::Valid()) return false; 01025 // test types 01026 bool tmm=false; 01027 if(typeid(Alphabet().Attribute())!=typeid(const EventAttr&)) tmm=true; 01028 if(typeid(States().Attribute())!=typeid(const StateAttr&)) tmm=true; 01029 if(typeid(TransRel().Attribute())!=typeid(const TransAttr&)) tmm=true; 01030 if(typeid(GlobalAttribute())!=typeid(const GlobalAttr&)) tmm=true; 01031 if(tmm) { 01032 return false; 01033 //std::stringstream errstr; 01034 //errstr << "attribute type mismatch in generator " << Name(); 01035 //throw Exception("vGenerator::Valid", errstr.str(), 63); 01036 } 01037 return true; 01038 } 01039 01040 // Clear() 01041 TEMP void THIS::Clear(void) { 01042 FD_DG("TaGenerator(" << this << ")::Clear()"); 01043 BASE::Clear(); 01044 } 01045 01046 01047 // InjectAlphabet(newalphabet) 01048 TEMP void THIS::InjectAlphabet(const EventSet& rNewAlphabet) { 01049 FD_DG("TaGenerator::InjectAlphabet() " << rNewAlphabet.ToString()); 01050 BASE::InjectAlphabet(rNewAlphabet); 01051 } 01052 01053 // InjectAlphabet(newalphabet) 01054 TEMP void THIS::InjectAlphabet(const TaEventSet<EventAttr>& rNewAlphabet) { 01055 FD_DG("TaGenerator::InjectAlphabet(TaEventSet<EventAttr>) " << rNewAlphabet.ToString()); 01056 #ifdef FAUDES_CHECKED 01057 if(rNewAlphabet.SymbolTablep()!=mpEventSymbolTable) { 01058 std::stringstream errstr; 01059 errstr << "symboltable mismatch aka not implemented" << std::endl; 01060 throw Exception("TaGenerator::InjectAlphabet", errstr.str(), 88); 01061 } 01062 #endif 01063 *pAlphabet=rNewAlphabet; 01064 mpAlphabet->Name("Alphabet"); 01065 } 01066 01067 // InsEvent(index) 01068 TEMP bool THIS::InsEvent(Idx index) { 01069 FD_DG("TaGenerator(" << this << ")::InsEvent(" << index << ")"); 01070 return pAlphabet->Insert(index); 01071 } 01072 01073 // InsEvent(rName) 01074 TEMP Idx THIS::InsEvent(const std::string& rName) { 01075 FD_DG("TaGenerator(" << this << ")::InsEvent(\"" << rName << "\")"); 01076 return pAlphabet->Insert(rName); 01077 } 01078 01079 // InsEvent(index, attr) 01080 TEMP bool THIS::InsEvent(Idx index, const EventAttr& attr) { 01081 FD_DG("TaGenerator(" << this << ")::InsEvent(" << index << " " << attr.ToString() << ")"); 01082 return pAlphabet->Insert(index, attr); 01083 } 01084 01085 // InsEvent(rName) 01086 TEMP Idx THIS::InsEvent(const std::string& rName, const EventAttr& attr) { 01087 FD_DG("TaGenerator(" << this << ")::InsEvent(\"" << rName << attr.ToString() << "\")"); 01088 return pAlphabet->Insert(rName, attr); 01089 } 01090 01091 // InsState() 01092 TEMP Idx THIS::InsState(void) { 01093 FD_DG("TaGenerator(" << this << ")::InsState()"); 01094 return mpStates->Insert(); 01095 } 01096 01097 // InsState(attr) 01098 TEMP Idx THIS::InsState(const StateAttr& attr) { 01099 FD_DG("TaGenerator(" << this << ")::InsState(attr)"); 01100 return pStates->Insert(attr); 01101 } 01102 01103 // InsState(index) 01104 TEMP bool THIS::InsState(Idx index) { 01105 FD_DG("TaGenerator(" << this << ")::InsState(" << index << ")"); 01106 return mpStates->Insert(index); 01107 } 01108 01109 // InsState(index, attr) 01110 TEMP bool THIS::InsState(Idx index, const StateAttr& rAttr) { 01111 FD_DG("TaGenerator(" << this << ")::InsState(" << index << ",rAttr)"); 01112 return pStates->Insert(index,rAttr); 01113 } 01114 01115 // InsState(rName) 01116 TEMP Idx THIS::InsState(const std::string& rName) { 01117 FD_DG("TaGenerator(" << this << ")::InsState(\"" << rName << "\")"); 01118 Idx index=mpStates->Insert(); 01119 StateName(index,rName); 01120 return index; 01121 } 01122 01123 // InsState(rName, attr) 01124 TEMP Idx THIS::InsState(const std::string& rName, const StateAttr& attr) { 01125 FD_DG("TaGenerator(" << this << ")::InsState(\"" << rName << "\", attr)"); 01126 Idx index=mpStates->Insert(); 01127 StateName(index,rName); 01128 StateAttribute(index,attr); 01129 return index; 01130 } 01131 01132 01133 // InjectStates(rNewStates) 01134 TEMP void THIS::InjectStates(const StateSet& rNewStates) { 01135 FD_DG("TaGenerator(" << this << ")::InjectStates(" 01136 << rNewStates.ToString() << ")"); 01137 BASE::InjectStates(rNewStates); 01138 } 01139 01140 // InjectStates(rNewStates) 01141 TEMP void THIS::InjectStates(const TaStateSet<StateAttr>& rNewStates) { 01142 FD_DG("TaGenerator(" << this << ")::InjectStates(" 01143 << rNewStates.ToString() << ")"); 01144 *pStates=rNewStates; 01145 mpStates->Name("States"); 01146 mpStateSymbolTable->RestrictDomain(*mpStates); 01147 } 01148 01149 01150 01151 // InjectTransRel(rNewtransrel) 01152 TEMP void THIS::InjectTransRel(const TransSet& rNewTransRel) { 01153 FD_DG("TaGenerator::InjectTransRel(...)"); 01154 *mpTransRel=rNewTransRel; 01155 } 01156 01157 // InjectTransRel(rNewtransrel) 01158 TEMP void THIS::InjectTransRel(const ATransSet& rNewTransRel) { 01159 FD_DG("TaGenerator::InjectTransRel(...)"); 01160 *pTransRel=rNewTransRel; 01161 } 01162 01163 01164 // SetTransition(rX1, rEv, rX2) 01165 TEMP bool THIS::SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rX2) { 01166 return BASE::SetTransition(rX1,rEv,rX2); 01167 } 01168 01169 01170 // SetTransition(x1, ev, x2) 01171 TEMP bool THIS::SetTransition(Idx x1, Idx ev, Idx x2) { 01172 return SetTransition(Transition(x1,ev,x2)); 01173 } 01174 01175 // SetTransition(rTransition) 01176 TEMP bool THIS::SetTransition(const Transition& rTransition) { 01177 FD_DG("TaGenerator(" << this << ")::SetTransition(" << rTransition.X1 << "," 01178 << rTransition.Ev << "," << rTransition.X2 << ")"); 01179 #ifdef FAUDES_CHECKED 01180 if (! mpStates->Exists(rTransition.X1)) { 01181 std::stringstream errstr; 01182 errstr << "TaGenerator::SetTransition: state " << rTransition.X1 01183 << " not in stateset"; 01184 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95); 01185 } 01186 if (! mpAlphabet->Exists(rTransition.Ev)) { 01187 std::stringstream errstr; 01188 errstr << "TaGenerator::SetTransition: event " << rTransition.Ev 01189 << " not in alphabet "; 01190 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95); 01191 } 01192 if (! mpStates->Exists(rTransition.X2)) { 01193 std::stringstream errstr; 01194 errstr << "TaGenerator::SetTransition: state " << rTransition.X2 01195 << " not in stateset"; 01196 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95); 01197 } 01198 #endif 01199 return mpTransRel->Insert(rTransition); 01200 } 01201 01202 // SetTransition(rTransition, rAttr) 01203 TEMP bool THIS::SetTransition(const Transition& rTransition, const TransAttr& rAttr) { 01204 FD_DG("TaGenerator(" << this << ")::SetTransition(" << rTransition.X1 << "," 01205 << rTransition.Ev << "," << rTransition.X2 << ", [attr:]" << rAttr.ToString() << ")"); 01206 #ifdef FAUDES_CHECKED 01207 if (! mpStates->Exists(rTransition.X1)) { 01208 std::stringstream errstr; 01209 errstr << "TaGenerator::SetTransition: state " << rTransition.X1 01210 << " not in stateset"; 01211 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95); 01212 } 01213 if (! mpAlphabet->Exists(rTransition.Ev)) { 01214 std::stringstream errstr; 01215 errstr << "TaGenerator::SetTransition: event " << rTransition.Ev 01216 << " not in alphabet "; 01217 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95); 01218 } 01219 if (! mpStates->Exists(rTransition.X2)) { 01220 std::stringstream errstr; 01221 errstr << "TaGenerator::SetTransition: state " << rTransition.X2 01222 << " not in stateset"; 01223 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95); 01224 } 01225 #endif 01226 return pTransRel->Insert(rTransition,rAttr); 01227 } 01228 01229 // TransAttribute(trans, attr) 01230 TEMP void THIS::TransAttribute(const Transition& rTrans, const TransAttr& rAttr) { 01231 FD_DG("TaGenerator(" << this << ")::TransAttribute(" 01232 << TStr(rTrans) << ",\"" << rAttr.ToString() << "\")"); 01233 pTransRel->Attribute(rTrans, rAttr); 01234 } 01235 01236 // TransAttribute(index, attr) 01237 TEMP void THIS::TransAttribute(const Transition& rTrans, const Type& rAttr) { 01238 FD_DG("TaGenerator(" << this << ")::TransAttribute(" 01239 << TStr(rTrans) << ",\"" << rAttr.ToString() << "\")"); 01240 const TransAttr* attrp = dynamic_cast<const TransAttr*>(&rAttr); 01241 if(!attrp) { 01242 std::stringstream errstr; 01243 errstr << "cannot cast event attribute " << rAttr.ToString() << " for generator " << Name(); 01244 throw Exception("TaGenerator::TransAttribute", errstr.str(), 63); 01245 } 01246 mpTransRel->Attribute(rTrans, *attrp); 01247 } 01248 01249 // TransAttributep(trans) 01250 TEMP TransAttr* THIS::TransAttributep(const Transition& rTrans) { 01251 return pTransRel->Attributep(rTrans); 01252 } 01253 01254 01255 // TransAttribute(trans) 01256 TEMP const TransAttr& THIS::TransAttribute(const Transition& rTrans) const { 01257 return pTransRel->Attribute(rTrans); 01258 } 01259 01260 // EventAttribute(index, attr) 01261 TEMP void THIS::EventAttribute(Idx index, const EventAttr& rAttr) { 01262 FD_DG("TaGenerator(" << this << ")::EventAttribute(" 01263 << EStr(index) << ",\"" << rAttr.ToString() << "\")"); 01264 pAlphabet->Attribute(index, rAttr); 01265 } 01266 01267 // EventAttribute(index, attr) 01268 TEMP void THIS::EventAttribute(Idx index, const Type& rAttr) { 01269 FD_DG("TaGenerator(" << this << ")::EventAttribute(" 01270 << EStr(index) << ",\"" << rAttr.ToString() << "\")"); 01271 const EventAttr* attrp = dynamic_cast<const EventAttr*>(&rAttr); 01272 if(!attrp) { 01273 std::stringstream errstr; 01274 errstr << "cannot cast event attribute " << rAttr.ToString() << " for generator " << Name(); 01275 throw Exception("TaGenerator::EventAttribute", errstr.str(), 63); 01276 } 01277 pAlphabet->Attribute(index, *attrp); 01278 } 01279 01280 // EventAttribute(index) 01281 TEMP const EventAttr& THIS::EventAttribute(Idx index) const { 01282 return pAlphabet->Attribute(index); 01283 } 01284 01285 // EventAttributep(index) 01286 TEMP EventAttr* THIS::EventAttributep(Idx index) { 01287 return pAlphabet->Attributep(index); 01288 } 01289 01290 // EventAttribute(rName) 01291 TEMP const EventAttr& THIS::EventAttribute(const std::string& rName) const { 01292 return EventAttribute(EventIndex(rName)); 01293 } 01294 01295 // EventAttributep(rName) 01296 TEMP EventAttr* THIS::EventAttributep(const std::string& rName) { 01297 return EventAttributep(EventIndex(rName)); 01298 } 01299 01300 // StateAttribute(index, attr) 01301 TEMP void THIS::StateAttribute(Idx index, const StateAttr& rAttr) { 01302 FD_DG("TaGenerator(" << this << ")::StateAttribute(" 01303 << index << ",\"" << rAttr.ToString() << "\")"); 01304 mpStates->Attribute(index, rAttr); 01305 } 01306 01307 // StateAttribute(index, attr) 01308 TEMP void THIS::StateAttribute(Idx index, const Type& rAttr) { 01309 FD_DG("TaGenerator(" << this << ")::StateAttribute(" 01310 << SStr(index) << ",\"" << rAttr.ToString() << "\")"); 01311 const StateAttr* attrp = dynamic_cast<const StateAttr*>(&rAttr); 01312 if(!attrp) { 01313 std::stringstream errstr; 01314 errstr << "cannot cast event attribute " << rAttr.ToString() << " for generator " << Name(); 01315 throw Exception("TaGenerator::StateAttribute", errstr.str(), 63); 01316 } 01317 mpStates->Attribute(index, *attrp); 01318 } 01319 01320 01321 // StateAttribute(index) 01322 TEMP const StateAttr& THIS::StateAttribute(Idx index) const { 01323 return pStates->Attribute(index); 01324 } 01325 01326 // StateAttributep(index) 01327 TEMP StateAttr* THIS::StateAttributep(Idx index) { 01328 return pStates->Attributep(index); 01329 } 01330 01331 // Alphabet() 01332 TEMP const TaEventSet<EventAttr>& THIS::Alphabet(void) const { 01333 return *pAlphabet; 01334 } 01335 01336 // States() 01337 TEMP const TaStateSet<StateAttr>& THIS::States(void) const { 01338 return *pStates; 01339 } 01340 01341 // TransRel() 01342 TEMP const typename THIS::ATransSet& THIS::TransRel(void) const { 01343 return *pTransRel; 01344 } 01345 01346 // TransRel(res) 01347 TEMP void THIS::TransRel(TransSetX1EvX2& res) const { mpTransRel->ReSort(res); } 01348 TEMP void THIS::TransRel(TransSetEvX1X2& res) const { mpTransRel->ReSort(res); } 01349 TEMP void THIS::TransRel(TransSetEvX2X1& res) const { mpTransRel->ReSort(res); } 01350 TEMP void THIS::TransRel(TransSetX2EvX1& res) const { mpTransRel->ReSort(res); } 01351 TEMP void THIS::TransRel(TransSetX2X1Ev& res) const { mpTransRel->ReSort(res); } 01352 TEMP void THIS::TransRel(TransSetX1X2Ev& res) const { mpTransRel->ReSort(res); } 01353 01354 01355 #undef THIS 01356 #undef TEMP 01357 #undef BASE 01358 01359 01360 01361 } // namespace faudes 01362 01363 #endif 01364 |
libFAUDES 2.18b --- 2010-12-17 --- c++ source docu by doxygen 1.6.3