|
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> msAlphabetTaGen; 00783 00784 /** Static default state set prototype (incl. attribute type) */ 00785 static const TaIndexSet<StateAttr> msStatesTaGen; 00786 00787 /** Static default transition relation prototype (incl. attribute type) */ 00788 static const ATransSet msTransRelTaGen; 00789 00790 /** Static default global attribute prototype (configures global attribute type) */ 00791 static const GlobalAttr msGlobalTaGen; 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 // default prototypes (static) 00810 TEMP const TaNameSet<EventAttr> THIS::msAlphabetTaGen; 00811 TEMP const TaIndexSet<StateAttr> THIS::msStatesTaGen; 00812 TEMP const TaTransSet<TransAttr> THIS::msTransRelTaGen; 00813 TEMP const GlobalAttr THIS::msGlobalTaGen; 00814 00815 // Generator::Generator(void) 00816 TEMP THIS::TaGenerator(void) : 00817 // init base 00818 vGenerator() 00819 { 00820 FD_DG("TaGenerator(" << this << ")::TaGenerator()"); 00821 // re-allocate core members with nontrivial attribute types 00822 ConfigureAttributeTypes(&msGlobalTaGen,&msStatesTaGen,&msAlphabetTaGen,&msTransRelTaGen); 00823 NewCore(); 00824 FD_DG("TaGenerator(" << this << ")::TaGenerator(): done"); 00825 } 00826 00827 // Generator::Generator(rOtherGen) 00828 TEMP THIS::TaGenerator(const TaGenerator& rOtherGen) : 00829 // init base 00830 vGenerator() 00831 { 00832 FD_DG("TaGenerator(" << this << ")::TaGenerator(" << &rOtherGen << ")"); 00833 // re-allocate core members with nontrivial attribute types 00834 ConfigureAttributeTypes(&msGlobalTaGen,&msStatesTaGen,&msAlphabetTaGen,&msTransRelTaGen); 00835 NewCore(); 00836 // have a 1:1 copy (incl sym tables) 00837 Assign(rOtherGen); 00838 } 00839 00840 00841 // Generator::Generator(rOtherGen) 00842 TEMP THIS::TaGenerator(const vGenerator& rOtherGen) : 00843 // init base 00844 vGenerator() 00845 { 00846 FD_DG("TaGenerator(" << this << ")::TaGenerator([v]" << &rOtherGen << ")"); 00847 // re-allocate core members with nontrivial attribute types 00848 ConfigureAttributeTypes(&msGlobalTaGen,&msStatesTaGen,&msAlphabetTaGen,&msTransRelTaGen); 00849 NewCore(); 00850 // have a 1:1 copy (incl sym tables) 00851 Assign(rOtherGen); 00852 } 00853 00854 // Generator::Generator(rFileName) 00855 TEMP THIS::TaGenerator(const std::string& rFileName) : 00856 // init base 00857 vGenerator() 00858 { 00859 FD_DG("TaGenerator(" << this << ")::TaGenerator(" << rFileName << ")"); 00860 // re-allocate core members with nontrivial attribute types 00861 ConfigureAttributeTypes(&msGlobalTaGen,&msStatesTaGen,&msAlphabetTaGen,&msTransRelTaGen); 00862 NewCore(); 00863 // set some defaults 00864 mStateNamesEnabled=true; 00865 // do read 00866 Read(rFileName); 00867 // get original statenames default 00868 mStateNamesEnabled=msStateNamesEnabledDefault; 00869 } 00870 00871 // allocate core on heap 00872 TEMP void THIS::NewCore(void) { 00873 FD_DG("TaGenerator(" << this << ")::NewCore()"); 00874 // call base, incl virtual call back of UpdateCore 00875 BASE::NewCore(); 00876 } 00877 00878 // indicate new core 00879 TEMP void THIS::UpdateCore(void) { 00880 // let base do an update (fixes names) 00881 BASE::UpdateCore(); 00882 // have pointer with my attribute 00883 pGlobalAttribute = dynamic_cast< GlobalAttr* >(mpGlobalAttribute); 00884 pAlphabet = dynamic_cast< TaNameSet<EventAttr>* >(mpAlphabet); 00885 pStates = dynamic_cast< TaIndexSet<StateAttr>* >(mpStates); 00886 pTransRel = dynamic_cast< ATransSet* >(mpTransRel); 00887 // check for type mismatche 00888 bool tmm=false; 00889 if(pGlobalAttribute==0 && mpGlobalAttribute!=0) tmm=true; 00890 if(pAlphabet==0 && mpAlphabet!=0) tmm=true; 00891 if(pStates==0 && mpStates!=0) tmm=true; 00892 if(pTransRel==0 && mpTransRel!=0) tmm=true; 00893 if(tmm) { 00894 std::stringstream errstr; 00895 errstr << "cannot cast attributes for generator " << Name(); 00896 throw Exception("vGenerator::UpdateCore", errstr.str(), 63); 00897 } 00898 } 00899 00900 00901 // Copy(gen) from identical type 00902 TEMP THIS& THIS::Assign(const TaGenerator& rGen) { 00903 FD_DG("TaGenerator(" << this << ")::Assign(" << &rGen << ")"); 00904 // prepare result (call clear for virtual stuff) 00905 Clear(); 00906 // have same event symboltable 00907 EventSymbolTablep(rGen.mpEventSymbolTable); 00908 // copy state symboltable 00909 StateSymbolTable(rGen.mStateSymbolTable); 00910 // set other members 00911 Name(rGen.Name()); 00912 *pGlobalAttribute=*rGen.pGlobalAttribute; 00913 *pStates= *rGen.pStates; 00914 *pAlphabet = *rGen.pAlphabet; 00915 *pTransRel= *rGen.pTransRel; 00916 mInitStates = rGen.mInitStates; 00917 mMarkedStates = rGen.mMarkedStates; 00918 mStateNamesEnabled=rGen.mStateNamesEnabled; 00919 // copy add on stuff 00920 mMinStateIndexMap=rGen.mMinStateIndexMap; 00921 #ifdef FAUDES_DEBUG_CODE 00922 if(!Valid()) { 00923 FD_DG("TaGenerator()::Assign(): invalid generator"); 00924 DWrite(); 00925 abort(); 00926 } 00927 #endif 00928 return *this; 00929 } 00930 00931 // Copy(gen) to other generator type 00932 TEMP THIS& THIS::Assign(const vGenerator& rGen) { 00933 FD_DG("TaGenerator(" << this << ")::Assign([v]" << &rGen << ")"); 00934 FD_DG("TaGenerator(" << this << ")::Assign(): src type " << typeid(rGen).name()); 00935 FD_DG("TaGenerator(" << this << ")::Assign(): dst type " << typeid(*this).name()); 00936 // call base 00937 BASE::Assign(rGen); 00938 // report 00939 #ifdef FAUDES_DEBUG_GENERATOR 00940 // FD_DG("TaGenerator(" << this << ")::Copy([type " << typeid(rGen).name() <<"]" << &rGen << "): report"); 00941 // Write(); 00942 // rGen.Write(); 00943 #endif 00944 return *this; 00945 } 00946 00947 00948 // Move(gen) destructive copy 00949 TEMP void THIS::Move(TaGenerator& rGen) { 00950 FD_DG("TaGenerator(" << this << ")::Move(" << &rGen << ")"); 00951 // call base 00952 BASE::Move(rGen); 00953 } 00954 00955 00956 // Move(gen) destructive copy 00957 TEMP void THIS::Move(vGenerator& rGen) { 00958 FD_DG("TaGenerator(" << this << ")::Move([v]" << &rGen << ")"); 00959 // call base 00960 BASE::Move(rGen); 00961 } 00962 00963 // Generator::~Generator 00964 TEMP THIS::~TaGenerator(void) { 00965 FD_DG("TaGenerator(" << this << ")::~TaGenerator()"); 00966 } 00967 00968 // New 00969 TEMP THIS* THIS::New(void) const { 00970 // allocate 00971 THIS* res = new THIS; 00972 // fix base data 00973 res->EventSymbolTablep(BASE::mpEventSymbolTable); 00974 res->mStateNamesEnabled=BASE::mStateNamesEnabled; 00975 return res; 00976 } 00977 00978 // Copy 00979 TEMP THIS* THIS::Copy(void) const { 00980 // allocate 00981 THIS* res = new THIS(*this); 00982 // done 00983 return res; 00984 } 00985 00986 // NewAGen() 00987 TEMP THIS THIS::NewAGen(void) const { 00988 THIS res; 00989 // fix base data 00990 res.EventSymbolTablep(BASE::mpEventSymbolTable); 00991 res.mStateNamesEnabled=BASE::mStateNamesEnabled; 00992 return res; 00993 } 00994 00995 00996 // operator= 00997 TEMP TaGenerator<GlobalAttr,StateAttr,EventAttr,TransAttr>& THIS::operator= (const TaGenerator& rOtherGen) { 00998 FD_DG("TaGenerator(" << this << ")::operator = " << &rOtherGen); 00999 return Assign(rOtherGen); 01000 } 01001 01002 // operator= 01003 TEMP TaGenerator<GlobalAttr,StateAttr,EventAttr,TransAttr>& THIS::operator= (const vGenerator& rOtherGen) { 01004 FD_DG("TaGenerator(" << this << ")::operator = [v]" << &rOtherGen); 01005 return Assign(rOtherGen); 01006 } 01007 01008 // Valid() 01009 TEMP bool THIS::Valid(void) { 01010 FD_DG("TaGenerator(" << this << ")::Valid()"); 01011 if(!BASE::Valid()) return false; 01012 // test types 01013 bool tmm=false; 01014 if(typeid(Alphabet().Attribute())!=typeid(const EventAttr&)) tmm=true; 01015 if(typeid(States().Attribute())!=typeid(const StateAttr&)) tmm=true; 01016 if(typeid(TransRel().Attribute())!=typeid(const TransAttr&)) tmm=true; 01017 if(typeid(GlobalAttribute())!=typeid(const GlobalAttr&)) tmm=true; 01018 if(tmm) { 01019 return false; 01020 //std::stringstream errstr; 01021 //errstr << "attribute type mismatch in generator " << Name(); 01022 //throw Exception("vGenerator::Valid", errstr.str(), 63); 01023 } 01024 return true; 01025 } 01026 01027 // Clear() 01028 TEMP void THIS::Clear(void) { 01029 FD_DG("TaGenerator(" << this << ")::Clear()"); 01030 BASE::Clear(); 01031 } 01032 01033 01034 // InjectAlphabet(newalphabet) 01035 TEMP void THIS::InjectAlphabet(const EventSet& rNewAlphabet) { 01036 FD_DG("TaGenerator::InjectAlphabet() " << rNewAlphabet.ToString()); 01037 BASE::InjectAlphabet(rNewAlphabet); 01038 } 01039 01040 // InjectAlphabet(newalphabet) 01041 TEMP void THIS::InjectAlphabet(const TaEventSet<EventAttr>& rNewAlphabet) { 01042 FD_DG("TaGenerator::InjectAlphabet(TaEventSet<EventAttr>) " << rNewAlphabet.ToString()); 01043 #ifdef FAUDES_CHECKED 01044 if(rNewAlphabet.SymbolTablep()!=mpEventSymbolTable) { 01045 std::stringstream errstr; 01046 errstr << "symboltable mismatch aka not implemented" << std::endl; 01047 throw Exception("TaGenerator::InjectAlphabet", errstr.str(), 88); 01048 } 01049 #endif 01050 *pAlphabet=rNewAlphabet; 01051 mpAlphabet->Name("Alphabet"); 01052 } 01053 01054 // InsEvent(index) 01055 TEMP bool THIS::InsEvent(Idx index) { 01056 FD_DG("TaGenerator(" << this << ")::InsEvent(" << index << ")"); 01057 return pAlphabet->Insert(index); 01058 } 01059 01060 // InsEvent(rName) 01061 TEMP Idx THIS::InsEvent(const std::string& rName) { 01062 FD_DG("TaGenerator(" << this << ")::InsEvent(\"" << rName << "\")"); 01063 return pAlphabet->Insert(rName); 01064 } 01065 01066 // InsEvent(index, attr) 01067 TEMP bool THIS::InsEvent(Idx index, const EventAttr& attr) { 01068 FD_DG("TaGenerator(" << this << ")::InsEvent(" << index << " " << attr.ToString() << ")"); 01069 return pAlphabet->Insert(index, attr); 01070 } 01071 01072 // InsEvent(rName) 01073 TEMP Idx THIS::InsEvent(const std::string& rName, const EventAttr& attr) { 01074 FD_DG("TaGenerator(" << this << ")::InsEvent(\"" << rName << attr.ToString() << "\")"); 01075 return pAlphabet->Insert(rName, attr); 01076 } 01077 01078 // InsState() 01079 TEMP Idx THIS::InsState(void) { 01080 FD_DG("TaGenerator(" << this << ")::InsState()"); 01081 return mpStates->Insert(); 01082 } 01083 01084 // InsState(attr) 01085 TEMP Idx THIS::InsState(const StateAttr& attr) { 01086 FD_DG("TaGenerator(" << this << ")::InsState(attr)"); 01087 return pStates->Insert(attr); 01088 } 01089 01090 // InsState(index) 01091 TEMP bool THIS::InsState(Idx index) { 01092 FD_DG("TaGenerator(" << this << ")::InsState(" << index << ")"); 01093 return mpStates->Insert(index); 01094 } 01095 01096 // InsState(index, attr) 01097 TEMP bool THIS::InsState(Idx index, const StateAttr& rAttr) { 01098 FD_DG("TaGenerator(" << this << ")::InsState(" << index << ",rAttr)"); 01099 return pStates->Insert(index,rAttr); 01100 } 01101 01102 // InsState(rName) 01103 TEMP Idx THIS::InsState(const std::string& rName) { 01104 FD_DG("TaGenerator(" << this << ")::InsState(\"" << rName << "\")"); 01105 Idx index=mpStates->Insert(); 01106 StateName(index,rName); 01107 return index; 01108 } 01109 01110 // InsState(rName, attr) 01111 TEMP Idx THIS::InsState(const std::string& rName, const StateAttr& attr) { 01112 FD_DG("TaGenerator(" << this << ")::InsState(\"" << rName << "\", attr)"); 01113 Idx index=mpStates->Insert(); 01114 StateName(index,rName); 01115 StateAttribute(index,attr); 01116 return index; 01117 } 01118 01119 01120 // InjectStates(rNewStates) 01121 TEMP void THIS::InjectStates(const StateSet& rNewStates) { 01122 FD_DG("TaGenerator(" << this << ")::InjectStates(" 01123 << rNewStates.ToString() << ")"); 01124 BASE::InjectStates(rNewStates); 01125 } 01126 01127 // InjectStates(rNewStates) 01128 TEMP void THIS::InjectStates(const TaStateSet<StateAttr>& rNewStates) { 01129 FD_DG("TaGenerator(" << this << ")::InjectStates(" 01130 << rNewStates.ToString() << ")"); 01131 *pStates=rNewStates; 01132 mpStates->Name("States"); 01133 mpStateSymbolTable->RestrictDomain(*mpStates); 01134 } 01135 01136 01137 01138 // InjectTransRel(rNewtransrel) 01139 TEMP void THIS::InjectTransRel(const TransSet& rNewTransRel) { 01140 FD_DG("TaGenerator::InjectTransRel(...)"); 01141 *mpTransRel=rNewTransRel; 01142 } 01143 01144 // InjectTransRel(rNewtransrel) 01145 TEMP void THIS::InjectTransRel(const ATransSet& rNewTransRel) { 01146 FD_DG("TaGenerator::InjectTransRel(...)"); 01147 *pTransRel=rNewTransRel; 01148 } 01149 01150 01151 // SetTransition(rX1, rEv, rX2) 01152 TEMP bool THIS::SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rX2) { 01153 return BASE::SetTransition(rX1,rEv,rX2); 01154 } 01155 01156 01157 // SetTransition(x1, ev, x2) 01158 TEMP bool THIS::SetTransition(Idx x1, Idx ev, Idx x2) { 01159 return SetTransition(Transition(x1,ev,x2)); 01160 } 01161 01162 // SetTransition(rTransition) 01163 TEMP bool THIS::SetTransition(const Transition& rTransition) { 01164 FD_DG("TaGenerator(" << this << ")::SetTransition(" << rTransition.X1 << "," 01165 << rTransition.Ev << "," << rTransition.X2 << ")"); 01166 #ifdef FAUDES_CHECKED 01167 if (! mpStates->Exists(rTransition.X1)) { 01168 std::stringstream errstr; 01169 errstr << "TaGenerator::SetTransition: state " << rTransition.X1 01170 << " not in stateset"; 01171 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95); 01172 } 01173 if (! mpAlphabet->Exists(rTransition.Ev)) { 01174 std::stringstream errstr; 01175 errstr << "TaGenerator::SetTransition: event " << rTransition.Ev 01176 << " not in alphabet "; 01177 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95); 01178 } 01179 if (! mpStates->Exists(rTransition.X2)) { 01180 std::stringstream errstr; 01181 errstr << "TaGenerator::SetTransition: state " << rTransition.X2 01182 << " not in stateset"; 01183 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95); 01184 } 01185 #endif 01186 return mpTransRel->Insert(rTransition); 01187 } 01188 01189 // SetTransition(rTransition, rAttr) 01190 TEMP bool THIS::SetTransition(const Transition& rTransition, const TransAttr& rAttr) { 01191 FD_DG("TaGenerator(" << this << ")::SetTransition(" << rTransition.X1 << "," 01192 << rTransition.Ev << "," << rTransition.X2 << ", [attr:]" << rAttr.ToString() << ")"); 01193 #ifdef FAUDES_CHECKED 01194 if (! mpStates->Exists(rTransition.X1)) { 01195 std::stringstream errstr; 01196 errstr << "TaGenerator::SetTransition: state " << rTransition.X1 01197 << " not in stateset"; 01198 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95); 01199 } 01200 if (! mpAlphabet->Exists(rTransition.Ev)) { 01201 std::stringstream errstr; 01202 errstr << "TaGenerator::SetTransition: event " << rTransition.Ev 01203 << " not in alphabet "; 01204 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95); 01205 } 01206 if (! mpStates->Exists(rTransition.X2)) { 01207 std::stringstream errstr; 01208 errstr << "TaGenerator::SetTransition: state " << rTransition.X2 01209 << " not in stateset"; 01210 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95); 01211 } 01212 #endif 01213 return pTransRel->Insert(rTransition,rAttr); 01214 } 01215 01216 // TransAttribute(trans, attr) 01217 TEMP void THIS::TransAttribute(const Transition& rTrans, const TransAttr& rAttr) { 01218 FD_DG("TaGenerator(" << this << ")::TransAttribute(" 01219 << TStr(rTrans) << ",\"" << rAttr.ToString() << "\")"); 01220 pTransRel->Attribute(rTrans, rAttr); 01221 } 01222 01223 // TransAttribute(index, attr) 01224 TEMP void THIS::TransAttribute(const Transition& rTrans, const Type& rAttr) { 01225 FD_DG("TaGenerator(" << this << ")::TransAttribute(" 01226 << TStr(rTrans) << ",\"" << rAttr.ToString() << "\")"); 01227 const TransAttr* attrp = dynamic_cast<const TransAttr*>(&rAttr); 01228 if(!attrp) { 01229 std::stringstream errstr; 01230 errstr << "cannot cast event attribute " << rAttr.ToString() << " for generator " << Name(); 01231 throw Exception("TaGenerator::TransAttribute", errstr.str(), 63); 01232 } 01233 mpTransRel->Attribute(rTrans, *attrp); 01234 } 01235 01236 // TransAttributep(trans) 01237 TEMP TransAttr* THIS::TransAttributep(const Transition& rTrans) { 01238 return pTransRel->Attributep(rTrans); 01239 } 01240 01241 01242 // TransAttribute(trans) 01243 TEMP const TransAttr& THIS::TransAttribute(const Transition& rTrans) const { 01244 return pTransRel->Attribute(rTrans); 01245 } 01246 01247 // EventAttribute(index, attr) 01248 TEMP void THIS::EventAttribute(Idx index, const EventAttr& rAttr) { 01249 FD_DG("TaGenerator(" << this << ")::EventAttribute(" 01250 << EStr(index) << ",\"" << rAttr.ToString() << "\")"); 01251 pAlphabet->Attribute(index, rAttr); 01252 } 01253 01254 // EventAttribute(index, attr) 01255 TEMP void THIS::EventAttribute(Idx index, const Type& rAttr) { 01256 FD_DG("TaGenerator(" << this << ")::EventAttribute(" 01257 << EStr(index) << ",\"" << rAttr.ToString() << "\")"); 01258 const EventAttr* attrp = dynamic_cast<const EventAttr*>(&rAttr); 01259 if(!attrp) { 01260 std::stringstream errstr; 01261 errstr << "cannot cast event attribute " << rAttr.ToString() << " for generator " << Name(); 01262 throw Exception("TaGenerator::EventAttribute", errstr.str(), 63); 01263 } 01264 pAlphabet->Attribute(index, *attrp); 01265 } 01266 01267 // EventAttribute(index) 01268 TEMP const EventAttr& THIS::EventAttribute(Idx index) const { 01269 return pAlphabet->Attribute(index); 01270 } 01271 01272 // EventAttributep(index) 01273 TEMP EventAttr* THIS::EventAttributep(Idx index) { 01274 return pAlphabet->Attributep(index); 01275 } 01276 01277 // EventAttribute(rName) 01278 TEMP const EventAttr& THIS::EventAttribute(const std::string& rName) const { 01279 return EventAttribute(EventIndex(rName)); 01280 } 01281 01282 // EventAttributep(rName) 01283 TEMP EventAttr* THIS::EventAttributep(const std::string& rName) { 01284 return EventAttributep(EventIndex(rName)); 01285 } 01286 01287 // StateAttribute(index, attr) 01288 TEMP void THIS::StateAttribute(Idx index, const StateAttr& rAttr) { 01289 FD_DG("TaGenerator(" << this << ")::StateAttribute(" 01290 << index << ",\"" << rAttr.ToString() << "\")"); 01291 mpStates->Attribute(index, rAttr); 01292 } 01293 01294 // StateAttribute(index, attr) 01295 TEMP void THIS::StateAttribute(Idx index, const Type& rAttr) { 01296 FD_DG("TaGenerator(" << this << ")::StateAttribute(" 01297 << SStr(index) << ",\"" << rAttr.ToString() << "\")"); 01298 const StateAttr* attrp = dynamic_cast<const StateAttr*>(&rAttr); 01299 if(!attrp) { 01300 std::stringstream errstr; 01301 errstr << "cannot cast event attribute " << rAttr.ToString() << " for generator " << Name(); 01302 throw Exception("TaGenerator::StateAttribute", errstr.str(), 63); 01303 } 01304 mpStates->Attribute(index, *attrp); 01305 } 01306 01307 01308 // StateAttribute(index) 01309 TEMP const StateAttr& THIS::StateAttribute(Idx index) const { 01310 return pStates->Attribute(index); 01311 } 01312 01313 // StateAttributep(index) 01314 TEMP StateAttr* THIS::StateAttributep(Idx index) { 01315 return pStates->Attributep(index); 01316 } 01317 01318 // Alphabet() 01319 TEMP const TaEventSet<EventAttr>& THIS::Alphabet(void) const { 01320 return *pAlphabet; 01321 } 01322 01323 // States() 01324 TEMP const TaStateSet<StateAttr>& THIS::States(void) const { 01325 return *pStates; 01326 } 01327 01328 // TransRel() 01329 TEMP const typename THIS::ATransSet& THIS::TransRel(void) const { 01330 return *pTransRel; 01331 } 01332 01333 // TransRel(res) 01334 TEMP void THIS::TransRel(TransSetX1EvX2& res) const { mpTransRel->ReSort(res); } 01335 TEMP void THIS::TransRel(TransSetEvX1X2& res) const { mpTransRel->ReSort(res); } 01336 TEMP void THIS::TransRel(TransSetEvX2X1& res) const { mpTransRel->ReSort(res); } 01337 TEMP void THIS::TransRel(TransSetX2EvX1& res) const { mpTransRel->ReSort(res); } 01338 TEMP void THIS::TransRel(TransSetX2X1Ev& res) const { mpTransRel->ReSort(res); } 01339 TEMP void THIS::TransRel(TransSetX1X2Ev& res) const { mpTransRel->ReSort(res); } 01340 01341 01342 #undef THIS 01343 #undef TEMP 01344 #undef BASE 01345 01346 01347 01348 } // namespace faudes 01349 01350 #endif 01351 |
libFAUDES 2.16b --- 2010-9-8 --- c++ source docu by doxygen 1.6.3