|
libFAUDES
Sections
Index
|
cfl_generator.hGo to the documentation of this file.00001 /** @file cfl_generator.h Class vGenerator */ 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_VGENERATOR_H 00025 #define FAUDES_VGENERATOR_H 00026 00027 #include "cfl_definitions.h" 00028 #include "cfl_exception.h" 00029 #include "cfl_types.h" 00030 #include "cfl_symboltable.h" 00031 #include "cfl_indexset.h" 00032 #include "cfl_nameset.h" 00033 #include "cfl_transset.h" 00034 #include "cfl_token.h" 00035 #include "cfl_tokenreader.h" 00036 #include "cfl_tokenwriter.h" 00037 00038 #include <map> 00039 #include <set> 00040 #include <sstream> 00041 #include <cstdlib> 00042 #include <cassert> 00043 00044 namespace faudes { 00045 00046 /** 00047 * Base class of all FAUDES generators. 00048 * 00049 * \section GeneratorMembers Overview 00050 * 00051 * The faudes::Generator models the plain five-tupel G = (X, Sigma, Delta, X_0, X_m) to represent 00052 * the marked language L(G) and closed language L_m(G), respectively. It provides read and write 00053 * access to core menbers, e.g. methods for inserting/deleting events, states 00054 * and transitions. 00055 * 00056 * 00057 * States, events and transitions in a generator can be addressed in three alternative methods: 00058 * 00059 * - by index, involves a search on a sorted set (efficient) 00060 * - by name, involves two searches on sorted sets (not quite so efficient) 00061 * - by iterator, involves pointer dereferencing (very efficient) 00062 * 00063 * For read access, const refererences to sets are provided. In order to allow for consistency checks, 00064 * write access is via generator methods only. When the compiletime option FAUDES_CHECKED is 00065 * defined, write methods throw an exception on inconsistent data, eg. setting an initial state 00066 * that is not an element of the state set, or introducing a transition with an event label that 00067 * is not in the alphabet. 00068 * 00069 * 00070 * \section SecEventsVersusStates Events Versus States 00071 * 00072 * While both events and states are represented by the integer type faudes::Idx, there 00073 * is a fundamental distinction between both, that stems our choice to use the generator 00074 * as a tool to represent a formal language. From this perspective, events are global enteties while states 00075 * are local to the respective generator. Any two events are related while states only 00076 * compare within a generator. 00077 * 00078 * In consequence of the different role of events and states, there is one global 00079 * sybmoltable that provides event name resolution, while there is a local state symbol table for 00080 * each generator. Furthermore, state names are considered cosmetic and hence are optional, while 00081 * event names are mandatory. 00082 * 00083 * Example: two machines both refer to the event name "alpha" that models the process of passing 00084 * a workpiece from one machine to the other. In libFAUDES this is indeed modelled as one event 00085 * which is represented by one index. However, both machines may have a state "Idle" which indicates 00086 * that the respective machine is idle. In libFAUDES the two states are treated locally to the 00087 * generators and whether or not they have the same index is regarded irrelevant. 00088 * 00089 * The generator class carries a flag to indicate that functions with result type 00090 * generator shall attach names to the newly created states, perhaps based on the state names 00091 * of the respective arguments. Turning of this feature and avoiding state names alltogether 00092 * considerably increases libFAUDES performance. 00093 * 00094 * \section GeneratorFileFormat File IO 00095 * 00096 * Generators inherit the standard token IO interface from the libFAUDES general purpose base Type, 00097 * so you may use Read and Write functions for generators. The file-format consists of a generator section that includes 00098 * one subsection for each core member. It is illustrated by the below example 00099 * 00100 * @code 00101 * <Generator> 00102 * % libFAUDES Generator for the simple machine 00103 * "simple machine" 00104 * 00105 * <Alphabet> 00106 * "alpha" "beta" "mue" "lambda" 00107 * </Alphabet> 00108 * 00109 * <States> 00110 * "idle" "busy" "down" 00111 * </States> 00112 * 00113 * <TransRel> 00114 * "idle" "alpha" "busy" 00115 * "busy" "beta" "idle" 00116 * "busy" "mue" "down" 00117 * "down" "lambda" "idle" 00118 * </TransRel> 00119 * 00120 * <InitStates> 00121 * "idle" 00122 * </InitStates> 00123 * 00124 * <MarkedStates> 00125 * "idle" 00126 * </MarkedStates> 00127 * </Generator> 00128 * @endcode 00129 * 00130 * Note that for file IO states may be represented either ba symbolic name or index. 00131 * However, when writing a file indices will be chosen consecutively and beginning at 1. 00132 * Thus, state indices are not maintained by file IO. Events are always represented by their 00133 * symbolic name. 00134 * 00135 * \section GeneratorAttributes Attributes 00136 * 00137 * libFAUDES generators provide an interface to access so called attributes, ie data that 00138 * is optionally attached to individual states, events, transitions, or globally to the generator. 00139 * 00140 * The faudes::Generator's interface to attributes is abstract in the sense that a generator 00141 * is not aware of the actual type of its attributes. 00142 * Instances of the class Generator indeed have trivial attributes that hold no data at all. 00143 * To use attributes, you are meant to instantiate objects of the derived class TaGenerator 00144 * with template parameters to specify attribute types. Basic algorithms 00145 * implemented for plain generators will accept attributed generators as arguments. Such algorithms may 00146 * occasionally inspect or set attributes using the abstract interface and C++ dynamic casts. For 00147 * specialised algorithms that refer to extended generator semantics, we recommend derived 00148 * generator classes as argument type. 00149 * 00150 * 00151 * @ingroup GeneratorClasses 00152 */ 00153 00154 00155 class vGenerator : public Type { 00156 00157 public: 00158 00159 /** @name Constructors & Destructor */ 00160 /** @{ doxygen group */ 00161 00162 /** 00163 * Default constructor 00164 */ 00165 vGenerator(void); 00166 00167 /** 00168 * Copy-constructror 00169 */ 00170 vGenerator(const vGenerator& rOtherGen); 00171 00172 /** 00173 * Construct from file. This constructor 00174 * effectively uses the DoRead(TokenReader&) function to read. 00175 * 00176 * @param rFileName 00177 * Name of file 00178 * 00179 * @exception Exception 00180 * - IO errors (id 1) 00181 * - Token mismatch (id 50, 51, 52, 80, 85) 00182 */ 00183 vGenerator(const std::string& rFileName); 00184 00185 /** 00186 * Construct on heap. 00187 * Technically not a constructor, this function creates a vGenerator with the 00188 * same event symboltable. It is the callers reponsebilty to delete the object 00189 * when no longer needed. Derived classes must reimplement 00190 * this function to create an object of the same class and the same event 00191 * symboltable. The StateNamesEnabled indicator should be copied, too. 00192 * 00193 * @return 00194 * New vGenerator 00195 */ 00196 virtual vGenerator* New(void) const; 00197 00198 /** 00199 * Construct copy on heap. 00200 * Technically not a constructor, this function creates a vGenerator with the 00201 * same event symboltable. It is the callers reponsebilty to delete the object 00202 * when no longer needed. Derived classes must reimplement 00203 * this function to create an object of the same class and the same event 00204 * symboltable. The StateNamesEnabled indicator should be copied, too. 00205 * 00206 * @return 00207 * New vGenerator 00208 */ 00209 virtual vGenerator* Copy(void) const; 00210 00211 /** 00212 * Destructor 00213 */ 00214 virtual ~vGenerator(void); 00215 00216 /** @} doxygen group */ 00217 00218 /***************************************** 00219 ***************************************** 00220 ***************************************** 00221 *****************************************/ 00222 00223 /** @name Copy and Assignment */ 00224 /** @{ doxygen group */ 00225 00226 00227 /** 00228 * Copy from other vGenerator. 00229 * The current implementation tries to be smart and copy attributes 00230 * if types can be casted. Use CopyWithoutAttributes to 00231 * explicitely ignore attributes. 00232 * 00233 * @param rSrc 00234 * Source to copy from. 00235 */ 00236 virtual vGenerator& Assign(const vGenerator& rSrc); 00237 00238 /** 00239 * Copy from other faudes type. 00240 * The current implementation tests whether the source 00241 * object can be casted to a generator and then performs 00242 * the according assignment. 00243 * 00244 * @param rSrc 00245 * Source to copy from. 00246 */ 00247 virtual vGenerator& Assign(const Type& rSrc); 00248 00249 /** 00250 * Copy from other vGenerator, ignore attributes. 00251 * 00252 * @param rGen 00253 * Source to copy from. 00254 */ 00255 virtual vGenerator& AssignWithoutAttributes(const vGenerator& rGen); 00256 00257 /** 00258 * Destructive copy to other vGenerator. 00259 * Copy method with increased performance at the cost of invalidating 00260 * the source data. If attribute types of source and destination differ, 00261 * a std copy is invoked. 00262 * 00263 * 00264 * @param rGen 00265 * Destination for copy operation. 00266 */ 00267 virtual void Move(vGenerator& rGen); 00268 00269 /** 00270 * Assignment operator (uses Copy method) 00271 * Note: you must reimplement this operator in derived 00272 * classes in order to handle internal pointers correctly. 00273 * 00274 * @param rOtherGen 00275 * Other generator 00276 */ 00277 virtual vGenerator& operator= (const vGenerator& rOtherGen); 00278 00279 /** 00280 * Create another version of this generator. 00281 * Assembles a copy of this generator, however, with versioned events. 00282 * The new event names are created by appending an underscore and a specified string. 00283 * State names and indices as well as any attributes are maintained. 00284 * 00285 * @param rVersion 00286 * String value to be appended to event names 00287 * @param rResGen 00288 * Resulting versioned generator 00289 * 00290 * @exception Exception 00291 * - Source must not match destination (id 96) 00292 */ 00293 virtual void Version(const std::string& rVersion, vGenerator& rResGen) const; 00294 00295 /** 00296 * Create another version of this generator. 00297 * Assembles a copy of this generator, however, with versioned events. 00298 * The new event names are created by appending an underscore and a numeric index. 00299 * State names and indices as well as any attributes are maintained. 00300 * 00301 * @param version 00302 * Numeric value to be appended to event names 00303 * @param rResGen 00304 * Resulting versioned generator 00305 * @exception Exception 00306 * - Source must not match destination (id 96) 00307 */ 00308 virtual void Version(Idx version, vGenerator& rResGen) const; 00309 00310 /** 00311 * Create another version of this generator. 00312 * Assembles a copy of this generator, however, with versioned events. 00313 * The new event names are created by replacing all substrings matching 00314 * a specified string pattern by a replacement string. 00315 * State names and indices as well as any attributes are maintained. 00316 * 00317 * @param rPattern 00318 * String value to be replaced in event names 00319 * @param rReplacement 00320 * String value to be inserted in event names in place of rPattern 00321 * @param rResGen 00322 * Resulting versioned generator 00323 * @exception Exception 00324 * - Source must not match destination (id 96) 00325 */ 00326 virtual void Version(const std::string& rPattern,const std::string& rReplacement, vGenerator& rResGen) const; 00327 00328 00329 00330 /** @} doxygen group */ 00331 00332 00333 /***************************************** 00334 ***************************************** 00335 ***************************************** 00336 *****************************************/ 00337 00338 /** @name Basic Maintenance */ 00339 /** @{ doxygen group */ 00340 00341 00342 /** 00343 * Set the generator's name 00344 * 00345 * @param rName 00346 * Generator name 00347 */ 00348 void Name(const std::string& rName); 00349 00350 /** 00351 * Get generator's name 00352 * 00353 * @return 00354 * Name of generator 00355 */ 00356 const std::string& Name(void) const; 00357 00358 /** 00359 * Check if generator is valid. 00360 * Performs internal consistency tests, This method is intendend 00361 * to test generators that have been manipulated by methods without 00362 * consistency tests, eg InjectAlphabet. 00363 * 00364 * @return 00365 * True for success 00366 */ 00367 virtual bool Valid(void); 00368 00369 /** 00370 * Clear generator data. 00371 * Clears state set, alphabet and transitionrealtion. Behavioural flags 00372 * eg StateNamesEnabled are maintained. 00373 */ 00374 virtual void Clear(void); 00375 00376 00377 /** 00378 * Clear all states and transitions, maintain alphabet. 00379 */ 00380 void ClearStates(void); 00381 00382 /** 00383 * Get number of events in alphabet 00384 * 00385 * @return 00386 * Number of events 00387 */ 00388 Idx AlphabetSize(void) const; 00389 00390 /** 00391 * Get generator size (number of states) 00392 * 00393 * @return 00394 * Number of states 00395 */ 00396 Idx Size(void) const; 00397 00398 /** 00399 * Get number of transitions 00400 * 00401 * @return 00402 * Number of transitions 00403 */ 00404 Idx TransRelSize(void) const; 00405 00406 /** 00407 * Get number of initial states 00408 * 00409 * @return 00410 * Number of initial states 00411 */ 00412 Idx InitStatesSize(void) const; 00413 00414 /** 00415 * Get number of marked states 00416 * 00417 * @return 00418 * Number of marked states 00419 */ 00420 Idx MarkedStatesSize(void) const; 00421 00422 /** 00423 * Check if generator is empty (no states) 00424 * 00425 * @return 00426 * True if state set is empty 00427 */ 00428 bool Empty(void) const; 00429 00430 /** 00431 * Check if alphabet is Empty 00432 * 00433 * @return 00434 * True if mpAlphabet is empty 00435 */ 00436 bool AlphabetEmpty(void) const; 00437 00438 /** 00439 * Check if transition relation is empty 00440 * 00441 * @return 00442 * True if transition relation is empty 00443 */ 00444 bool TransRelEmpty(void) const; 00445 00446 /** 00447 * Check if set of initial states are empty 00448 * 00449 * @return 00450 * True if mInitStates is empty 00451 */ 00452 bool InitStatesEmpty(void) const; 00453 00454 /** 00455 * Check if set of marked states are empty 00456 * 00457 * @return 00458 * True if mMarkedStates is empty 00459 */ 00460 bool MarkedStatesEmpty(void) const; 00461 00462 00463 /** @} doxygen group */ 00464 00465 /***************************************** 00466 ***************************************** 00467 ***************************************** 00468 *****************************************/ 00469 00470 /** @name Event Symboltable */ 00471 /** @{ doxygen group */ 00472 00473 /** 00474 * Get Pointer to EventSymbolTable currently used 00475 * by this vGenerator. 00476 * 00477 * @return 00478 * Pointer to EventSymbolTable 00479 */ 00480 SymbolTable* EventSymbolTablep(void) const; 00481 00482 /** 00483 * Set EventSymbolTable to be used by this vGenerator. 00484 * This function sets the reference to the event symboltable. The current implementation 00485 * in derived classes clears the generator, future versions may implement a re-indexing. 00486 * 00487 * @param pSymTab 00488 * Pointer to SymbolTable 00489 */ 00490 virtual void EventSymbolTablep(SymbolTable* pSymTab); 00491 00492 /** 00493 * Set EventSymbolTable as given by rOtherGen. 00494 * This function sets the reference to the event symboltable. The current implementation 00495 * clears the generator, future versions may implement a re-indexing. 00496 * 00497 * @param rOtherGen 00498 * Other generator 00499 * 00500 */ 00501 virtual void EventSymbolTablep(const vGenerator& rOtherGen); 00502 00503 /** 00504 * Create EventSet with generator's EventSymbolTable (on stack). 00505 * 00506 * @return 00507 * New empty EventSet on stack 00508 */ 00509 EventSet NewEventSet(void) const; 00510 00511 /** 00512 * Create EventSet with generator's EventSymbolTable (on heap). 00513 * 00514 * @return 00515 * Pointer to new empty EventSet on heap 00516 */ 00517 EventSet* NewEventSetp(void) const; 00518 00519 /** 00520 * Event index lookup 00521 * 00522 * @param rName 00523 * Name of event to lookup 00524 * 00525 * @return 00526 * Valid index or 0 if name unknown to symboltable 00527 */ 00528 Idx EventIndex(const std::string& rName) const; 00529 00530 /** 00531 * Event name lookup 00532 * 00533 * @param index 00534 * Index of event to look up 00535 * 00536 * @return 00537 * Name or empty std::string if non-existent 00538 */ 00539 std::string EventName(Idx index) const; 00540 00541 /** 00542 * Set name for existing event 00543 * 00544 * Note: since the event symboltable is global, this affect all 00545 * generators that refer to the specified event. 00546 * 00547 * @param index 00548 * Event index 00549 * @param rName 00550 * New name 00551 * 00552 * @exception Exception 00553 * - index not found in EventSymbolMap (id 42) 00554 * - name already associated with another index (id 44) 00555 * - event does not exist in generator (id 89) 00556 */ 00557 void EventName(Idx index, const std::string& rName); 00558 00559 /** 00560 * Create a new unique symbolic event name. 00561 * See also SymbolTable::UniqueSymbol(). 00562 * 00563 * @param rName 00564 * suggestion for new state name 00565 */ 00566 std::string UniqueEventName(const std::string& rName) const; 00567 00568 00569 /** 00570 * Rename event in this generator. 00571 * This method renames the specified event. It does so by 00572 * removing and adding transitions. This does not 00573 * effect other generators. 00574 * 00575 * @param event 00576 * Event to rename 00577 * @param rNewName 00578 * New name 00579 * @return 00580 * True, if the new name did already exist 00581 */ 00582 bool EventRename(Idx event, const std::string& rNewName); 00583 00584 00585 /** @} doxygen group */ 00586 00587 /* statics outside doxygen group */ 00588 00589 /** 00590 * Get Pointer to global EventSymbolTable. This is 00591 * a static member of SymbolTable and used as default 00592 * for all derived generator classes and instantiated objects. 00593 * 00594 * @return 00595 * Pointer to global EventSymbolTable 00596 */ 00597 static SymbolTable* GlobalEventSymbolTablep(void); 00598 00599 00600 /***************************************** 00601 ***************************************** 00602 ***************************************** 00603 *****************************************/ 00604 00605 /** @name State Symboltable */ 00606 /** @{ doxygen group */ 00607 00608 00609 /** 00610 * Get StateSymbolTable. 00611 * 00612 * @return 00613 * ref to state-symboltable 00614 */ 00615 const SymbolTable& StateSymbolTable(void) const; 00616 00617 /** 00618 * Set StateSymbolTable. 00619 * 00620 * By convention, state names and indices are local to the 00621 * respective generator. It is most unlikely that you want to use 00622 * this function. 00623 * 00624 * @return 00625 * Pointer to mpStateSymbolTable 00626 */ 00627 void StateSymbolTable(const SymbolTable& rSymTab); 00628 00629 /** 00630 * State index lookup. 00631 * 00632 * @param rName 00633 * 00634 * @return 00635 * Valid index (or 0 for non-existent) 00636 */ 00637 Idx StateIndex(const std::string& rName) const; 00638 00639 /** 00640 * State name lookup 00641 * 00642 * @param index 00643 * 00644 * @return name (or empty string if no such exists) 00645 */ 00646 std::string StateName(Idx index) const; 00647 00648 /** 00649 * Set name of state 00650 * 00651 * @param index 00652 * Index 00653 * @param rName 00654 * Name 00655 * 00656 * @exception Exception 00657 * - name already associated with another index (id 44) 00658 * - state does not exist in generator (id 90) 00659 */ 00660 void StateName(Idx index, const std::string& rName); 00661 00662 /** 00663 * Remove all names from generator's StateSymbolTable 00664 */ 00665 void ClearStateNames(void); 00666 00667 /** 00668 * Clear name for individual state 00669 * 00670 * @param index 00671 * State index 00672 * @exception Exception 00673 * - state does not exist in generator (id 90) 00674 */ 00675 void ClrStateName(Idx index); 00676 00677 /** 00678 * Clear name for individual state 00679 * 00680 * @param rName 00681 * State name 00682 */ 00683 void ClrStateName(const std::string& rName); 00684 00685 /** 00686 * Whether libFAUEDS functions are requested to generate state names. 00687 * Most libFAUDES functions introduce new states to a generator can be enabled 00688 * to also assign (more or less sensible) names to those states. This feature is 00689 * purely cosmetic and may be disabled for performance reasons. 00690 * 00691 * 00692 * @return 00693 * False if ClearStateNames() was called 00694 */ 00695 bool StateNamesEnabled(void) const; 00696 00697 /** 00698 * Enable/disable libFAUEDS functions to automatically generate state names. 00699 * 00700 * @param flag 00701 * True enables statenames / false disables them 00702 */ 00703 void StateNamesEnabled(bool flag); 00704 00705 /** 00706 * Assign each state a default name based on its index. 00707 */ 00708 void SetDefaultStateNames(void); 00709 00710 /** 00711 * For all states without a symbolic name, assign a name 00712 * based on suggested template and the index 00713 * 00714 * @param rTemplate 00715 * basis for name generation 00716 */ 00717 void EnforceStateNames(const std::string& rTemplate); 00718 00719 /** 00720 * Create a new unique symbolic state name. 00721 * See also SymbolTable::UniqueSymbol(). 00722 * 00723 * @param rName 00724 * suggestion for new state name 00725 */ 00726 std::string UniqueStateName(const std::string& rName) const; 00727 00728 00729 /** @} doxygen group */ 00730 00731 /* statics outside doxygen group */ 00732 00733 /** 00734 * Sets the default for automatic state name generation. 00735 * This flag takes effect only on generators newly created by the default 00736 * constructor. The copy constructor copies the state name flag from the 00737 * source generator. See also StateNamesEnabled(bool). 00738 * 00739 * @param flag 00740 * True enables statenames / false disables them 00741 */ 00742 static void StateNamesEnabledDefault(bool flag); 00743 00744 00745 /***************************************** 00746 ***************************************** 00747 ***************************************** 00748 ***************************************** 00749 *****************************************/ 00750 00751 /** @name Read Access to Core Members */ 00752 /** @{ doxygen group */ 00753 00754 /** 00755 * Iterator to Begin() of alphabet 00756 * 00757 * @return 00758 * Iterator to begin of mpAlphabet 00759 */ 00760 EventSet::Iterator AlphabetBegin(void) const; 00761 00762 /** 00763 * Iterator to End() of alphabet 00764 * 00765 * @return 00766 * Iterator to end of mpAlphabet 00767 */ 00768 EventSet::Iterator AlphabetEnd(void) const; 00769 00770 /** 00771 * Test existence of event in alphabet 00772 * 00773 * @param index 00774 * Event index 00775 * 00776 * @return 00777 * True / false 00778 */ 00779 bool ExistsEvent(Idx index) const; 00780 00781 /** 00782 * Test existence of event in alphabet 00783 * 00784 * @param rName 00785 * Event name 00786 * 00787 * @return 00788 * True / false 00789 */ 00790 bool ExistsEvent(const std::string& rName) const; 00791 00792 /** 00793 * Returns a iterator to event index in alphabet 00794 * 00795 * @param index 00796 * Index to find 00797 * 00798 * @return 00799 * Iterator to event index 00800 */ 00801 EventSet::Iterator FindEvent(Idx index) const; 00802 00803 /** 00804 * Returns a iterator to event index in alphabet 00805 * 00806 * @param rName 00807 * Event name of index to find 00808 * 00809 * @return 00810 * Iterator to event index 00811 */ 00812 EventSet::Iterator FindEvent(const std::string& rName) const; 00813 00814 /** 00815 * Return const reference to alphabet 00816 * 00817 * @return EventSet 00818 * Reference to mpAlphabet 00819 */ 00820 const EventSet& Alphabet(void) const; 00821 00822 /** 00823 * Iterator to Begin() of state set 00824 * 00825 * @return 00826 * Iterator to begin of state set 00827 */ 00828 StateSet::Iterator StatesBegin(void) const; 00829 00830 /** 00831 * Iterator to End() of state set 00832 * 00833 * @return 00834 * Iterator to end of state set 00835 */ 00836 StateSet::Iterator StatesEnd(void) const; 00837 00838 /** 00839 * Test existence of state in state set 00840 * 00841 * @param index 00842 * State index 00843 * 00844 * @return 00845 * true / false 00846 */ 00847 bool ExistsState(Idx index) const; 00848 00849 /** 00850 * Test existence of state in state set 00851 * 00852 * @param name 00853 * State name 00854 * 00855 * @return 00856 * true / false 00857 */ 00858 bool ExistsState(const std::string& name) const; 00859 00860 /** 00861 * Returns a iterator to state index in state set 00862 * 00863 * @param index 00864 * Index to find 00865 * 00866 * @return 00867 * StateSet::Iterator to state index 00868 */ 00869 StateSet::Iterator FindState(Idx index) const; 00870 00871 /** 00872 * Returns a iterator to state with specified name 00873 * 00874 * @param rName 00875 * name of state to find 00876 * 00877 * @return 00878 * StateSet::Iterator to state 00879 */ 00880 StateSet::Iterator FindState(const std::string& rName) const; 00881 00882 00883 /** 00884 * Return reference to state set 00885 * 00886 * @return 00887 * StateSet reference incl actual attribute type 00888 */ 00889 const StateSet& States(void) const; 00890 00891 /** 00892 * Return initial state 00893 * 00894 * @return 00895 * Index of initial state 00896 * 00897 * @exception Exception 00898 * - initial state does not exist uniquely (id 92) 00899 */ 00900 Idx InitState(void) const; 00901 00902 /** 00903 * Iterator to Begin() of mInitStates 00904 * 00905 * @return 00906 * Iterator to begin of mInitStates 00907 */ 00908 StateSet::Iterator InitStatesBegin(void) const; 00909 00910 /** 00911 * Iterator to End() of mInitStates 00912 * 00913 * @returns 00914 * Iterator to end of mInitStates 00915 */ 00916 StateSet::Iterator InitStatesEnd(void) const; 00917 00918 /** 00919 * Test existence of state in mInitStates 00920 * 00921 * @param index 00922 * State index 00923 * 00924 * @return 00925 * true / false 00926 */ 00927 bool ExistsInitState(Idx index) const; 00928 00929 /** 00930 * Iterator to state index in mInitStates 00931 * 00932 * @param index 00933 * Index to find 00934 * 00935 * @return 00936 * StateSet::Iterator to state index 00937 */ 00938 StateSet::Iterator FindInitState(Idx index) const; 00939 00940 /** 00941 * Const ref to initial states 00942 * 00943 * @return StateSet 00944 */ 00945 const StateSet& InitStates(void) const; 00946 00947 /** 00948 * Iterator to Begin() of mMarkedStates 00949 * 00950 * @returns 00951 * iterator to Begin of mMarkedStates 00952 */ 00953 StateSet::Iterator MarkedStatesBegin(void) const; 00954 00955 /** 00956 * Iterator to End() of mMarkedStates 00957 * 00958 * @returns 00959 * iterator to End of mMarkedStates 00960 */ 00961 StateSet::Iterator MarkedStatesEnd(void) const; 00962 00963 /** 00964 * Test existence of state in mMarkedStates 00965 * 00966 * @param index 00967 * State index 00968 * 00969 * @return 00970 * true / false 00971 */ 00972 bool ExistsMarkedState(Idx index) const; 00973 00974 /** 00975 * Returns a iterator to state index in mMarkedStates 00976 * 00977 * @param index 00978 * Index to find 00979 * 00980 * @return 00981 * StateSet::Iterator to state index 00982 */ 00983 StateSet::Iterator FindMarkedState(Idx index) const; 00984 00985 /** 00986 * Return const ref of marked states 00987 * 00988 * @return StateSet 00989 */ 00990 const StateSet& MarkedStates(void) const; 00991 00992 /** 00993 * Iterator to Begin() of transition relation 00994 * 00995 * @return 00996 * Iterator to Begin of mpTransRel 00997 */ 00998 TransSet::Iterator TransRelBegin(void) const; 00999 01000 /** 01001 * Iterator to End() of transition relation 01002 * 01003 * @return 01004 * Iterator to End of mpTransRel 01005 */ 01006 TransSet::Iterator TransRelEnd(void) const; 01007 01008 /** 01009 * Iterator to begin of transitions with x1 as predecessor state. 01010 * 01011 * @param x1 01012 * Predecessor state 01013 * 01014 * @return 01015 * iterator to begin of transitions with x1 01016 */ 01017 TransSet::Iterator TransRelBegin(Idx x1) const; 01018 01019 /** 01020 * iterator to end of transitions with x1 as predecessor state. 01021 * 01022 * Note: Set the End(x1) iterator to a variable, so it won't be 01023 * recalculated every iteration. 01024 * 01025 * @param x1 01026 * Predecessor state 01027 * 01028 * @return 01029 * iterator to end of transitions with x1 01030 * (one after last matching transition) 01031 */ 01032 TransSet::Iterator TransRelEnd(Idx x1) const; 01033 01034 /** 01035 * iterator to begin of transitions with x1 as predecessor state and 01036 * event ev. 01037 * 01038 * @param x1 01039 * Predecessor state 01040 * @param ev 01041 * Event 01042 * 01043 * @return 01044 * iterator to begin of transitions with x1 and ev 01045 */ 01046 TransSet::Iterator TransRelBegin(Idx x1, Idx ev) const; 01047 01048 /** 01049 * Iterator to end of transitions with x1 as predecessor state and 01050 * event ev. 01051 * 01052 * Note: Set the End(x1,ev) iterator to a variable, so it won't be 01053 * recalculated every iteration. 01054 * 01055 * @param x1 01056 * Predecessor state 01057 * @param ev 01058 * Event 01059 * 01060 * @return 01061 * iterator to end of transitions with x1 and ev 01062 * (one after last matching transition) 01063 */ 01064 TransSet::Iterator TransRelEnd(Idx x1, Idx ev) const; 01065 01066 /** 01067 * iterator to transition given by x1, ev, x2 01068 * 01069 * 01070 * @param rX1 01071 * name of Predecessor state 01072 * @param rEv 01073 * name of Event 01074 * @param rX2 01075 * name of Successor state 01076 * 01077 * @return 01078 * iterator to transition or end() if not exists 01079 */ 01080 TransSet::Iterator FindTransition( 01081 const std::string& rX1, const std::string& rEv, const std::string& rX2) const; 01082 01083 /** 01084 * Iterator to transition given by x1, ev, x2 01085 * 01086 * 01087 * @param x1 01088 * Predecessor state 01089 * @param ev 01090 * Event 01091 * @param x2 01092 * Successor state 01093 * 01094 * @return 01095 * iterator to transition or End() if not exists 01096 */ 01097 TransSet::Iterator FindTransition(Idx x1, Idx ev, Idx x2) const; 01098 01099 /** 01100 * Iterator to transition 01101 * 01102 * 01103 * @param rTrans 01104 * transition 01105 * 01106 * @return 01107 * iterator to transition or end() if not exists 01108 */ 01109 TransSet::Iterator FindTransition(const Transition& rTrans) const; 01110 01111 /** 01112 * Test for transition given by x1, ev, x2 01113 * 01114 * 01115 * @param rX1 01116 * name of Predecessor state 01117 * @param rEv 01118 * name of Event 01119 * @param rX2 01120 * name of Successor state 01121 * 01122 * @return 01123 * true / false 01124 */ 01125 bool ExistsTransition( 01126 const std::string& rX1, const std::string& rEv, const std::string& rX2) const; 01127 01128 /** 01129 * Test for transition given by x1, ev, x2 01130 * 01131 * 01132 * @param x1 01133 * Predecessor state 01134 * @param ev 01135 * Event 01136 * @param x2 01137 * Successor state 01138 * 01139 * @return 01140 * true / false 01141 */ 01142 bool ExistsTransition(Idx x1, Idx ev, Idx x2) const; 01143 01144 /** 01145 * test for transition 01146 * 01147 * 01148 * @param rTrans 01149 * transition 01150 * 01151 * @return 01152 * true / false 01153 */ 01154 bool ExistsTransition(const Transition& rTrans) const; 01155 01156 /** 01157 * Return reference to transition relation 01158 * 01159 * @return TransRel 01160 */ 01161 const TransSet& TransRel(void) const; 01162 01163 /** 01164 * Get copy of trantision relation sorted by other compare 01165 * operator, e.g. "x2,ev,x1" 01166 * 01167 * @param res 01168 * resulting transition relation 01169 */ 01170 void TransRel(TransSetX1EvX2& res) const; 01171 void TransRel(TransSetEvX1X2& res) const; 01172 void TransRel(TransSetEvX2X1& res) const; 01173 void TransRel(TransSetX2EvX1& res) const; 01174 void TransRel(TransSetX2X1Ev& res) const; 01175 void TransRel(TransSetX1X2Ev& res) const; 01176 01177 /** 01178 * Convebience function. 01179 * 01180 * @param rX1 01181 * Name of Predecessor state 01182 * @param rEv 01183 * Name of Event 01184 * @param rX2 01185 * Name of Successor state 01186 * 01187 * @return 01188 * Transition as specified. 01189 */ 01190 Transition TransitionByNames( 01191 const std::string& rX1, const std::string& rEv, const std::string& rX2) const; 01192 01193 /** @} doxygen group */ 01194 01195 01196 01197 /***************************************** 01198 ***************************************** 01199 ***************************************** 01200 *****************************************/ 01201 01202 /** @name Write Access to Core Members */ 01203 /** @{ doxygen group */ 01204 01205 01206 /** 01207 * Add an existing event to alphabet by index. It is an error to insert 01208 * an event index that is not known to the mpEventSymbolTable. 01209 * 01210 * @param index 01211 * Event index 01212 * @return 01213 * True, if event was new to alphabet 01214 */ 01215 bool InsEvent(Idx index); 01216 01217 /** 01218 * Add named event to generator. An entry in the mpEventSymbolTable will 01219 * be made if event name is not known so far. 01220 * 01221 * @param rName 01222 * Name of the event to add 01223 * 01224 * @return 01225 * New unique index 01226 */ 01227 Idx InsEvent(const std::string& rName); 01228 01229 /** 01230 * Add new named events to generator. 01231 * If the event allready exists, the attribute is maintained. 01232 * 01233 * @param events 01234 * EventSet 01235 */ 01236 void InsEvents(const EventSet& events); 01237 01238 /** 01239 * Delete event from generator by index. mpEventSymbolTable stays untouched. 01240 * Transitions containing event will be removed too. 01241 * 01242 * @param index 01243 * Index of event 01244 * @return 01245 * True, if event was in alphabet 01246 * 01247 */ 01248 bool DelEvent(Idx index); 01249 01250 /** 01251 * Delete event from generator by name. mpEventSymbolTable stays untouched. 01252 * Transitions containing event will be removed too. 01253 * 01254 * @param rName 01255 * Name of event 01256 * @return 01257 * True, if event was in alphabet 01258 * 01259 */ 01260 bool DelEvent(const std::string& rName); 01261 01262 /** 01263 * Delete a set of events from generator. mpEventSymbolTable stays untouched. 01264 * Transitions containing events will be removed too. 01265 * 01266 * @param rEvents 01267 * EventSet containing events to remove 01268 */ 01269 void DelEvents(const EventSet& rEvents); 01270 01271 /** 01272 * Delete event from alphabet without consistency check. The event is only 01273 * deleted from mpAlphabet but not from transition relation. 01274 * 01275 * @param index 01276 * Index of event 01277 * @return 01278 * True, if event was in alphabet 01279 * 01280 */ 01281 bool DelEventFromAlphabet(Idx index); 01282 01283 /** 01284 * Set mpAlphabet without consistency check. 01285 * Sets the alphabet incl attributes, if provided. 01286 * 01287 * @param rNewalphabet 01288 * EventSet with new alphabet 01289 */ 01290 void InjectAlphabet(const EventSet& rNewalphabet); 01291 01292 /** 01293 * Restricts mpAlphabet without consistency check. 01294 * Maintains attributes if any. 01295 * 01296 * @param rNewalphabet 01297 * EventSet with alphabet 01298 */ 01299 void RestrictAlphabet(const EventSet& rNewalphabet); 01300 01301 /** 01302 * Add new anonymous state to generator 01303 * 01304 * @return 01305 * Index of new unique state 01306 */ 01307 Idx InsState(void); 01308 01309 /** 01310 * Add (perhaps new) state to generator 01311 * 01312 * @return 01313 * True to indicate that state was new to generator 01314 */ 01315 bool InsState(Idx index); 01316 01317 /** 01318 * Add new named state to generator. 01319 * 01320 * @param rName 01321 * Name of the state to add 01322 * 01323 * @return 01324 * Index of new unique state 01325 * 01326 * @exception Exception 01327 * Name already exists (id 44) 01328 */ 01329 Idx InsState(const std::string& rName); 01330 01331 /** 01332 * Delete a state from generator by index. 01333 * Cleans mpStates, mInitStates, mMarkedStates, mpTransRel and mpStateSymbolTable. 01334 * 01335 * @param index 01336 * Index of state to delete. 01337 * @return 01338 * True, if state was in stateset 01339 */ 01340 bool DelState(Idx index); 01341 01342 /** 01343 * Delete a state from generator by name. 01344 * Cleans mpStates, mInitStates, mMarkedStates, mpTransRel and mpStateSymbolTable. 01345 * 01346 * @param rName 01347 * Name of state to delete. Will be erased in mpStateSymbolTable too 01348 * @return 01349 * True, if state was in stateset 01350 * 01351 * @exception Exception 01352 * - Symbolic name not known (id 90) 01353 */ 01354 bool DelState(const std::string& rName); 01355 01356 /** 01357 * Delete a set of states 01358 * Cleans mpStates, mInitStates, mMarkedStates, mpTransrel, and mpStateSymboltable 01359 * 01360 * @param rDelStates 01361 * StateSet containing states aka indicees to delete 01362 */ 01363 void DelStates(const StateSet& rDelStates); 01364 01365 01366 /** 01367 * Delete a state from generator without consistency check. This removes the 01368 * state from mpStates and mpStateSymbolTable but doesn't touch mpTransRel, 01369 * mInitStates and mMarkedStates. 01370 * 01371 * @param index 01372 * Index of state to delete. 01373 * @return 01374 * True, if state was in stateset 01375 * 01376 */ 01377 bool DelStateFromStates(Idx index); 01378 01379 /** 01380 * Delete a state from generator without consistency check. This removes the 01381 * state from mpStates and mpStateSymbolTable but doesn't touch mpTransRel, 01382 * mInitStates and mMarkedStates. 01383 * Index to delete is given by iterator. 01384 * 01385 * @param pos 01386 * StateSet::Iterator 01387 * @return 01388 * Iteraror to next state 01389 */ 01390 StateSet::Iterator DelStateFromStates(StateSet::Iterator pos); 01391 01392 /** 01393 * Inject an existing state index into generators mStates 01394 * Use with care! For use in performance optimized functions. 01395 * 01396 * @param index 01397 * State index to inject 01398 */ 01399 void InjectState(Idx index); 01400 01401 /** 01402 * Inject a complete state set without consistency checks (without attributes) 01403 * 01404 * @param rNewStates 01405 * StateSet 01406 */ 01407 void InjectStates(const StateSet& rNewStates); 01408 01409 01410 /** 01411 * Create new anonymous state and set as initial state 01412 * 01413 * @return 01414 * Index of new unique 01415 */ 01416 Idx InsInitState(void); 01417 01418 /** 01419 * Add (perhaps new) state to generator and turn it 01420 * into a initial state. 01421 * 01422 * @param index 01423 * State to insert 01424 * @return 01425 * True to indicate that state was new to generator 01426 */ 01427 bool InsInitState(Idx index); 01428 01429 /** 01430 * Create a new named state and set as initial state 01431 * 01432 * @param rName 01433 * Name of the state to add 01434 * 01435 * @return 01436 * Index of new unique state 01437 */ 01438 Idx InsInitState(const std::string& rName); 01439 01440 /** 01441 * Create new anonymous state and set as marked state 01442 * 01443 * @return 01444 * Index of new unique state 01445 */ 01446 Idx InsMarkedState(void); 01447 01448 /** 01449 * Add (perhaps new) state to generator and turn it 01450 * into a marked state. 01451 * 01452 * @param index 01453 * State to insert 01454 * @return 01455 * True to indicate that state was new to generator 01456 */ 01457 bool InsMarkedState(Idx index); 01458 01459 /** 01460 * Create a new named state and set as marked state 01461 * 01462 * @param rName 01463 * Name of the state to add 01464 * 01465 * @return 01466 * Index of new unique state 01467 */ 01468 Idx InsMarkedState(const std::string& rName); 01469 01470 /** 01471 * Set an existing state as initial state by index. 01472 * 01473 * @param index 01474 * Index of state to set as initial state 01475 * @exception Exception 01476 * - State index not found in generator (id 91) 01477 */ 01478 void SetInitState(Idx index); 01479 01480 /** 01481 * Set an existing state as initial state by name. 01482 * 01483 * @param rName 01484 * Name of state to set as initial state 01485 * 01486 * @exception Exception 01487 * - State name not known in generator (id 90) 01488 */ 01489 void SetInitState(const std::string& rName); 01490 01491 /** 01492 * Replace mInitStates with StateSet given as parameter without consistency checks. 01493 * 01494 * @param rNewInitStates 01495 * StateSet containing new mInitStates 01496 */ 01497 void InjectInitStates(const StateSet& rNewInitStates); 01498 01499 /** 01500 * Unset an existing state as initial state by index 01501 * 01502 * Define FAUDES_CHECKED for consistency checks. 01503 * 01504 * @param index 01505 * State index 01506 * 01507 * @exception Exception 01508 * - State index not found in generator (id 91) 01509 */ 01510 void ClrInitState(Idx index); 01511 01512 /** 01513 * Unset an existing state as initial state by name 01514 * 01515 * @param rName 01516 * State name 01517 * 01518 * @exception Exception 01519 * - State name not known in generator (id 90) 01520 */ 01521 void ClrInitState(const std::string& rName); 01522 01523 /** 01524 * Unset an existing state as initial state by iterator 01525 * 01526 * @param pos 01527 * StateSet::iterator 01528 * @return 01529 * Iterator to next init state 01530 */ 01531 StateSet::Iterator ClrInitState(StateSet::Iterator pos); 01532 01533 /** 01534 * Clear all mInitStates 01535 */ 01536 void ClearInitStates(void); 01537 01538 /** 01539 * Set an existing state as marked state by index 01540 * 01541 * @param index 01542 * Index of state to set as initial state 01543 * @exception Exception 01544 * - State index not found in generator (id 91) 01545 */ 01546 void SetMarkedState(Idx index); 01547 01548 /** 01549 * Set an existing state as marked state by name. 01550 * 01551 * @param rName 01552 * Name of state to set as marked state 01553 * 01554 * @exception Exception 01555 * - State name not known in generator (id 90) 01556 */ 01557 void SetMarkedState(const std::string& rName); 01558 01559 /** 01560 * Unset an existing state as marked state by index 01561 * 01562 * @param index 01563 * State index 01564 * 01565 * @exception Exception 01566 * - State index not found in generator (id 91) 01567 */ 01568 void ClrMarkedState(Idx index); 01569 01570 /** 01571 * Unset an existing state as marked state by name 01572 * 01573 * @param rName 01574 * State name 01575 * 01576 * @exception Exception 01577 * - State index not found in generator (id 91) 01578 */ 01579 void ClrMarkedState(const std::string& rName); 01580 01581 /** 01582 * Unset an existing state as marked state by iterator 01583 * 01584 * @param pos 01585 * StateSet::iterator 01586 * @return 01587 * Iterator to next marked state 01588 */ 01589 StateSet::Iterator ClrMarkedState(StateSet::Iterator pos); 01590 01591 /** 01592 * Clear all marked states 01593 */ 01594 void ClearMarkedStates(void); 01595 01596 /** 01597 * Replace mMarkedStates with StateSet given as parameter without consistency checks. 01598 * 01599 * @param rNewMarkedStates 01600 * StateSet containing new marked states 01601 */ 01602 void InjectMarkedStates(const StateSet& rNewMarkedStates); 01603 01604 /** 01605 * Add a transition to generator by indices. States and event 01606 * must already exist. 01607 * 01608 * @param x1 01609 * Predecessor state index 01610 * @param ev 01611 * Event index 01612 * @param x2 01613 * Successor state index 01614 * 01615 * @return 01616 * True, if the transition was new the generator 01617 * 01618 * @exception Exception 01619 * - state or event not in generator (id 95) 01620 */ 01621 bool SetTransition(Idx x1, Idx ev, Idx x2); 01622 01623 /** 01624 * Add a transition to generator by names. Statename and eventname 01625 * must already exist. 01626 * 01627 * @param rX1 01628 * Predecessor state name 01629 * @param rEv 01630 * Event name 01631 * @param rX2 01632 * Successor state name 01633 * 01634 * @return 01635 * True, if the transition was new the generator 01636 * 01637 * @exception Exception 01638 * - state or event not in generator (id 95) 01639 * - state name not known (id 90) 01640 * - event name not known (id 66) 01641 */ 01642 bool SetTransition(const std::string& rX1, const std::string& rEv, 01643 const std::string& rX2); 01644 01645 /** 01646 * Add a transition to generator. States and event 01647 * must already exist. 01648 * 01649 * 01650 * @param rTransition 01651 * Transition 01652 * 01653 * @return 01654 * True, if the transition was new the generator 01655 * @exception Exception 01656 * - state or event not in generator (id 95) 01657 */ 01658 bool SetTransition(const Transition& rTransition); 01659 01660 /** 01661 * Remove a transition by indices 01662 * 01663 * @param x1 01664 * Predecessor state index 01665 * @param ev 01666 * Event index 01667 * @param x2 01668 * Successor state index 01669 */ 01670 void ClrTransition(Idx x1, Idx ev, Idx x2); 01671 01672 /** 01673 * Remove a transition by transition object 01674 * 01675 * @param rTrans 01676 * Transition object 01677 */ 01678 void ClrTransition(const Transition& rTrans); 01679 01680 /** 01681 * Remove a transition by iterator 01682 * 01683 * @param it 01684 * TransSet::iterator 01685 * @return 01686 * Iterator to next transition 01687 */ 01688 TransSet::Iterator ClrTransition(TransSet::Iterator it); 01689 01690 /** 01691 * Clear all transitions 01692 */ 01693 void ClearTransRel(void); 01694 01695 /** 01696 * Set transition without consistency check. 01697 * 01698 * @param rTrans 01699 * Transition to insert 01700 */ 01701 void InjectTransition(const Transition& rTrans); 01702 01703 /** 01704 * Set transition relation without consistency check (no attributes) 01705 * 01706 * @param rNewtransrel 01707 * TransRel to insert 01708 */ 01709 void InjectTransRel(const TransSet& rNewtransrel); 01710 01711 /** @} doxygen group */ 01712 01713 01714 01715 /***************************************** 01716 ***************************************** 01717 ***************************************** 01718 *****************************************/ 01719 01720 /** @name Attributes */ 01721 /** @{ doxygen group */ 01722 01723 01724 /** 01725 * Clear Attributes 01726 */ 01727 virtual void ClearAttributes(void); 01728 01729 /** 01730 * Updates internal attributes. 01731 * This method does nothing and may be reimplemented 01732 * by a any class that adds semantics to attributes 01733 * Eg. you may set a particular state flag, if this state 01734 * is reachable. 01735 * 01736 * @return True if value changed 01737 */ 01738 virtual bool UpdateAttributes(void) {return false;}; 01739 01740 /** 01741 * Clear event attributes 01742 */ 01743 virtual void ClearEventAttributes(void); 01744 01745 /** 01746 * Clear attribute for existing event 01747 * 01748 * @param index 01749 * Event index 01750 */ 01751 virtual void ClrEventAttribute(Idx index); 01752 01753 /** 01754 * Set attribute for existing event. 01755 * This version uses a dynamic cast 01756 * to test the actual type of the provided attribute. An exception is 01757 * thrown for an invalid attribute type. 01758 * In a context where 01759 * the attribute type is known, you may prefer the TaGenerator method. 01760 * 01761 * @param index 01762 * Event index 01763 * @param rAttr 01764 * New attribute 01765 * 01766 * @exception Exception 01767 * - Index not found in alphabet (id 60) 01768 * - Cannot cast attribute (id 63) 01769 */ 01770 virtual void EventAttribute(Idx index, const Type& rAttr); 01771 01772 /** 01773 * Set attributes for existing events. 01774 * This version uses a dynamic cast 01775 * to test the actual type of the provided attributes. An exception is 01776 * thrown for an invalid attribute type. 01777 * 01778 * @param rEventSet 01779 * Set of attributed events 01780 * @exception Exception 01781 * - Element not found in alphabet (id 60) 01782 * - Cannot cast attribute (id 63) 01783 */ 01784 virtual void EventAttributes(const EventSet& rEventSet); 01785 01786 /** 01787 * Event attribute lookup. 01788 * In a context where 01789 * the attribute type is known, you may prefer the TaGenerator method. 01790 * 01791 * @param index 01792 * 01793 * @return 01794 * reference to attribute 01795 */ 01796 virtual const AttributeVoid& EventAttribute(Idx index) const; 01797 01798 /** 01799 * Event attribute lookup. 01800 * In a context where the attribute type is known, 01801 * you may prefer the TaGenerator method. 01802 * 01803 * @param rName 01804 * 01805 * @return 01806 * reference to attribute 01807 */ 01808 virtual const AttributeVoid& EventAttribute(const std::string& rName) const; 01809 01810 /** 01811 * Event attribute pointer to access Attribute methods. 01812 * If there are no attributes (plain vGenerator) this method 01813 * returs 0. If there are attributes, an explicit default value 01814 * may be inserted. 01815 * In a context where the attribute type is known, 01816 * you may prefer the TaGenerator method. 01817 * 01818 * @param index 01819 * 01820 * @return 01821 * pointer to attribute 01822 */ 01823 virtual AttributeVoid* EventAttributep(Idx index); 01824 01825 /** 01826 * Event attribute pointer to access Attribute methods. 01827 * If there are no attributes (plain vGenerator) this method 01828 * returs 0. If there are attributes, an explicit default value 01829 * may be inserted. 01830 * In a context where the attribute type is known, 01831 * you may prefer the TaGenerator method. 01832 * 01833 * @param rName 01834 * 01835 * @return 01836 * pointer to attribute 01837 */ 01838 virtual AttributeVoid* EventAttributep(const std::string& rName); 01839 01840 01841 /** 01842 * Clear state attributes 01843 */ 01844 virtual void ClearStateAttributes(void); 01845 01846 /** 01847 * Clear attribute for existing state 01848 * 01849 * @param index 01850 * State index 01851 */ 01852 virtual void ClrStateAttribute(Idx index); 01853 01854 /** 01855 * Set attribute for existing state. 01856 * This version uses a dynamic cast 01857 * to test the actual type of the provided attribute. An exception is 01858 * thrown for an invalid attribute type. 01859 * In a context where 01860 * the attribute type is known, you may prefer the TaGenerator method. 01861 * 01862 * @param index 01863 * State index 01864 * @param rAttr 01865 * New attribute 01866 * 01867 * @exception Exception 01868 * - Index not found in Stateset (id 60) 01869 * - Cannot cast attribute (id 63) 01870 */ 01871 virtual void StateAttribute(Idx index, const Type& rAttr); 01872 01873 /** 01874 * State attribute lookup. 01875 * In a context where the attribute type is known, 01876 * you may prefer the TaGenerator method. 01877 * 01878 * @param index 01879 * State index 01880 * 01881 * @return Ref to attribute of state 01882 */ 01883 virtual const AttributeVoid& StateAttribute(Idx index) const; 01884 01885 /** 01886 * State attribute pointer to access Attribute methods. 01887 * If there are no attributes (plain vGenerator) this method 01888 * returns 0. If there are attributes, an explicit default value 01889 * may be inserted. 01890 * In a context where the attribute type is known, 01891 * you may prefer the TaGenerator method. 01892 * 01893 * @param index 01894 * State index 01895 * 01896 * @return Pointer to attribute of state 01897 */ 01898 virtual AttributeVoid* StateAttributep(Idx index); 01899 01900 /** 01901 * Clear transition attributes 01902 */ 01903 virtual void ClearTransAttributes(void); 01904 01905 /** 01906 * Set attribute for existing transition. 01907 * This version uses a dynamic cast 01908 * to test the actual type of the provided attribute. An exception is 01909 * thrown for an invalid attribute type. 01910 * In a context where 01911 * the attribute type is known, you may prefer the TaGenerator method. 01912 * 01913 * @param rTrans 01914 * Transition 01915 * @param rAttr 01916 * New attribute 01917 * 01918 * @exception Exception 01919 * - Transition not found in transition relation(id 60) 01920 * - Cannot cast attribute (id 63) 01921 */ 01922 virtual void TransAttribute(const Transition& rTrans, const Type& rAttr); 01923 01924 01925 /** 01926 * Clear attribute for existing transition 01927 * 01928 * @param rTrans 01929 * transition 01930 */ 01931 virtual void ClrTransAttribute(const Transition& rTrans); 01932 01933 /** 01934 * Transition attribute lookup. 01935 * In a context where the attribute type is known, 01936 * you may prefer the TaGenerator method. 01937 * 01938 * @return 01939 * Attribute 01940 * 01941 */ 01942 virtual const AttributeVoid& TransAttribute(const Transition& rTrans) const; 01943 01944 /** 01945 * Transition attribute pointer to access Attribute methods. 01946 * If there are no attributes (plain vGenerator) this method 01947 * returns 0. If there are attributes, an explicit default value 01948 * may be inserted. 01949 * In a context where the attribute type is known, 01950 * you may prefer the TaGenerator method. 01951 * 01952 * @return 01953 * Attribute pointer 01954 * 01955 */ 01956 virtual AttributeVoid* TransAttributep(const Transition& rTrans); 01957 01958 /** 01959 * Clear global attribute 01960 */ 01961 virtual void ClearGlobalAttribute(void); 01962 01963 /** 01964 * Set global attribute. 01965 * The vGenerator does not have attributes, so this function throws an exception for 01966 * any specified attribute different to AttributeVoid. 01967 * The TaGenarator provides a re-implementation to actually set the global attribute. 01968 * 01969 * @param rAttr 01970 * Attribute 01971 * @exception Exception 01972 * - Cannot cast attribute (id 63) 01973 */ 01974 virtual void GlobalAttribute(const Type& rAttr); 01975 01976 /** 01977 * Set global attribute. 01978 * The vGenerator does not have attributes, so this function does nothing. 01979 * The TaGenarator provides a re-implementation to actually set the global attribute. 01980 * 01981 * @param rAttr 01982 * Attribute 01983 */ 01984 virtual void GlobalAttributeTry(const Type& rAttr); 01985 01986 /** 01987 * Global attribute lookup. 01988 * In a context where the attribute type is known, 01989 * you may prefer the TaGenerator method. 01990 */ 01991 virtual const AttributeVoid& GlobalAttribute(void) const; 01992 01993 01994 /** 01995 * Get attribute pointer 01996 * The global attribute allways exits. For the vGenerator its of 01997 * type AttributeVoid, the TaGenerator sets a nontrivial type. 01998 * In a context where the attribute type is known, 01999 * you may prefer the TaGenerator method. 02000 */ 02001 virtual AttributeVoid* GlobalAttributep(void); 02002 02003 02004 /** @} doxygen group */ 02005 02006 02007 02008 /***************************************** 02009 ***************************************** 02010 ***************************************** 02011 *****************************************/ 02012 02013 /** @name Reachability */ 02014 /** @{ doxygen group */ 02015 02016 02017 /** 02018 * Compute set of accessible states 02019 */ 02020 StateSet AccessibleSet(void) const; 02021 02022 /** 02023 * Make generator accessible. 02024 * 02025 * @return 02026 * True if generator contains at least one initial state 02027 */ 02028 bool Accessible(void); 02029 02030 /** 02031 * Check if generator is accessible 02032 * 02033 * @return 02034 * True if generator is accesssible 02035 */ 02036 bool IsAccessible(void) const; 02037 02038 /** 02039 * Compute set of Coaccessible states 02040 */ 02041 StateSet CoaccessibleSet(void) const; 02042 02043 /** 02044 * Make generator Coaccessible 02045 * 02046 * @return 02047 * True if generator contains at least one marked state 02048 */ 02049 bool Coaccessible(void); 02050 02051 /** 02052 * Check if generator is Coaccessible 02053 * 02054 * @return 02055 * True if generator is coaccessible 02056 */ 02057 bool IsCoaccessible(void) const; 02058 02059 /** 02060 * Compute set of blocking states. 02061 * 02062 * A state is considered blocking it is accessible but not coaccessible. 02063 */ 02064 StateSet BlockingStates(void) const; 02065 02066 02067 /** 02068 * Compute set of terminal states. 02069 * 02070 * A terminal state is a state with no successor state. 02071 * If and only if the set of terminal states is empty, the generator is complete. 02072 * @return 02073 * Set of terminal states. 02074 */ 02075 StateSet TerminalStates(void) const; 02076 02077 02078 /** 02079 * Compute set of terminal states. 02080 * 02081 * A terminal state is a state with no successor state. 02082 * This function returns the the set terminal states contained 02083 * in the specified state ste. 02084 * 02085 * @param rStates 02086 * Set of state indices to restrict the search 02087 * @return 02088 * Set of terminal states. 02089 */ 02090 StateSet TerminalStates(const StateSet& rStates) const; 02091 02092 /** 02093 * Make generator Complete. 02094 * 02095 * This procedure removes all states are guaranteed to evolve 02096 * into a terminal state within a finite number of transitios. 02097 * The current implementations in initialized by 02098 * the set of terminal states and then performs a backward 02099 * reachability analysis. 02100 * 02101 * @return 02102 * True if generator contains at least one initial state 02103 */ 02104 bool Complete(void); 02105 02106 /** 02107 * Check if generator is complete. 02108 * 02109 * A generator is considered complete, if each state has at least 02110 * one successor state. If the generator is trim, completeness 02111 * is equivalent to completeness of the markede language, ie 02112 * forall s in Lm(G) there exists r in Lm(G) with s<r 02113 * @return 02114 * True if generator is complete 02115 */ 02116 bool IsComplete(void) const; 02117 02118 /** 02119 * Check if generator is complete. 02120 * 02121 * Same as IsComplete(void), however, only the specified 02122 * states are considered. The rational is to e.g. apply the test 02123 * to accessible states only. In that case, the test is equivalent 02124 * to completeness of the generated language. 02125 * 02126 * @param rStates 02127 * Set of state indices to restrict the completeness test 02128 * @return 02129 * True if generator is relatively complete 02130 */ 02131 bool IsComplete(const StateSet& rStates) const; 02132 02133 02134 /** 02135 * Compute set of trim states 02136 */ 02137 StateSet TrimSet(void) const; 02138 02139 /** 02140 * Make generator trim 02141 * 02142 * This function removes all states are not accessible or not 02143 * coaccessible. In other words: only those states are kept, that 02144 * contribute to that marked language. 02145 * 02146 * @return 02147 * True if resulting generator contains at least one initial state and at least one marked state. 02148 */ 02149 bool Trim(void); 02150 02151 /** 02152 * Check if generator is trim. 02153 * 02154 * Returns true if all states are rechable and coreachale. 02155 * 02156 * @return 02157 * True if generator is trim 02158 */ 02159 bool IsTrim(void) const; 02160 02161 02162 /** 02163 * Make generator omega-trim 02164 * 02165 * This function removes states such that the generator becomes 02166 * omega trim while not affecting the induced omega language. 02167 * 02168 * The implementation first make the generator accessible 02169 * and then iteratively removes state that either 02170 * never reach a marked state or that are guaranteed to eventually 02171 * reach a terminal state. There might be a more efficient 02172 * approach. 02173 * 02174 * @return 02175 * True if resulting generator contains at least one initial state and at least one marked state. 02176 */ 02177 bool OmegaTrim(void); 02178 02179 02180 /** 02181 * Check if generator is omega-trim. 02182 * 02183 * Returns true if all states are accessible, coacessible, and 02184 * have a successor state. 02185 * 02186 * @return 02187 * True if generator is omega-trim 02188 */ 02189 bool IsOmegaTrim(void) const; 02190 02191 02192 02193 /** @} doxygen group */ 02194 02195 /***************************************** 02196 ***************************************** 02197 ***************************************** 02198 *****************************************/ 02199 02200 /** @name File IO */ 02201 /** @{ doxygen group */ 02202 02203 /** 02204 * Write generators alphabet to console 02205 */ 02206 void WriteAlphabet(void) const; 02207 02208 /** 02209 * Write generators alphabet to string 02210 * 02211 * @return 02212 * std::string 02213 * @exception Exception 02214 * - IO errors (id 2) 02215 */ 02216 std::string AlphabetToString(void) const; 02217 02218 /** 02219 * Write generators alphabet to tokenwriter 02220 * 02221 * @param rTw 02222 * Reference to TokenWriter 02223 * 02224 * @exception Exception 02225 * - IO errors (id 2) 02226 */ 02227 void WriteAlphabet(TokenWriter& rTw) const; 02228 02229 /** 02230 * Write a stateset to console (no re-indexing). 02231 * Uses WriteStateSet(TokenWriter& rTw, const StateSet&) const to write 02232 * the specified state set to console referring to this generators state names. 02233 * 02234 * @param rStateSet 02235 * Reference to stateset 02236 */ 02237 void WriteStateSet(const StateSet& rStateSet) const; 02238 02239 /** 02240 * Write a stateset to string (no re-indexing). 02241 * Uses WriteStateSet(TokenWriter& rTw, const StateSet&) const to write 02242 * the specified state set to a string referring to this generators state names. 02243 * 02244 * @param rStateSet 02245 * Reference to stateset 02246 * @return 02247 * std::string 02248 * @exception Exception 02249 * - IO errors (id 2) 02250 */ 02251 std::string StateSetToString(const StateSet& rStateSet) const; 02252 02253 /** 02254 * Write a stateset to formated text (no re-indexing). 02255 * Uses WriteStateSet(TokenWriter& rTw, const StateSet&) const to write 02256 * the specified state set to a string referring to this generators state names. 02257 * 02258 * @param rStateSet 02259 * Reference to stateset 02260 * @return 02261 * std::string 02262 * @exception Exception 02263 * - IO errors (id 2) 02264 */ 02265 std::string StateSetToText(const StateSet& rStateSet) const; 02266 02267 /** 02268 * Write a stateset to TokenWriter. 02269 * All output of state sets done with this function. 02270 * Recall that a StateSet technically is a set of plain indices, no reference 02271 * to symbolic names. Thus, it is only the context of a Generator that provides 02272 * the symbolic names for file output. 02273 * 02274 * Output of state sets always uses the mMinStateIndexMap to re-index states. 02275 * However, this map is only set up automatically for file output. If You require 02276 * re-indexed output to eg a string, you must set up the map by calling SetMinStateIndexMap(). 02277 * To ensure that no re-indexing takes place, call ClearMinStateIndexMap(). 02278 * 02279 * @param rTw 02280 * Reference to TokenWriter 02281 * @param rStateSet 02282 * Reference to stateset 02283 * 02284 * @exception Exception 02285 * - IO errors (id 2) 02286 */ 02287 void WriteStateSet(TokenWriter& rTw, const StateSet& rStateSet) const; 02288 02289 /** 02290 * Write a stateset to TokenWriter (debug version, no re-indexing) 02291 * 02292 * @param rTw 02293 * Reference to TokenWriter 02294 * @param rStateSet 02295 * Reference to stateset 02296 * 02297 * @exception Exception 02298 * - IO errors (id 2) 02299 */ 02300 void DWriteStateSet(TokenWriter& rTw, const StateSet& rStateSet) const; 02301 02302 02303 /** 02304 * Write stateset of this generator to a string (no re-indexing) 02305 * 02306 * @return 02307 * std::string 02308 * @exception Exception 02309 * - IO errors (id 2) 02310 */ 02311 std::string StatesToString(void) const; 02312 02313 /** 02314 * Write stateset of this generator to formated text (no re-indexing) 02315 * 02316 * @return 02317 * std::string 02318 * @exception Exception 02319 * - IO errors (id 2) 02320 */ 02321 std::string StatesToText(void) const; 02322 02323 /** 02324 * Write set of marked states to a string (no re-indexing) 02325 * 02326 * @return 02327 * std::string 02328 * @exception Exception 02329 * - IO errors (id 2) 02330 */ 02331 std::string MarkedStatesToString(void) const; 02332 02333 /** 02334 * Write set of initial states to a string (no re-indexing) 02335 * 02336 * @return 02337 * std::string 02338 * @exception Exception 02339 * - IO errors (id 2) 02340 */ 02341 std::string InitStatesToString(void) const; 02342 02343 /** 02344 * Write transition relation to console (no re-indexing) 02345 */ 02346 void WriteTransRel(void) const; 02347 02348 /** 02349 * Write transition relation to string (no re-indexing) 02350 */ 02351 std::string TransRelToString(void) const; 02352 02353 /** 02354 * Write transition relation to formated text (no re-indexing) 02355 */ 02356 std::string TransRelToText(void) const; 02357 02358 /** 02359 * Write transition relation to tokenwriter (no re-indexing). 02360 * Re-indexing and symbolic state names are handled in the same way 02361 * as with state sets: this function refers to the generators state symboltable to 02362 * obtain state names and uses the mMinStateIndexMap to re-index the output. 02363 * 02364 * @param rTw 02365 * Reference to TokenWriter 02366 * 02367 * @exception Exception 02368 * - IO errors (id 2) 02369 */ 02370 void WriteTransRel(TokenWriter& rTw) const; 02371 02372 /** 02373 * Write transition relation to tokenwriter (debug version) 02374 * @param rTw 02375 * Reference to TokenWriter 02376 * 02377 * @exception Exception 02378 * - IO errors (id 2) 02379 */ 02380 void DWriteTransRel(TokenWriter& rTw) const; 02381 02382 02383 /** 02384 * Writes generator to dot input format. 02385 * The dot file format is specified by the graphiz package; see http://www.graphviz.org. 02386 * The package includes the dot command line tool to generate a graphical 02387 * representation of the generators graph. See also GraphWrite(). 02388 * This functions sets the re-indexing to minimal indices. 02389 * 02390 * @param rFileName 02391 * File to write 02392 * 02393 * @exception Exception 02394 * - IO errors (id 2) 02395 */ 02396 virtual void DotWrite(const std::string& rFileName) const; 02397 02398 /** 02399 * Writes generator to dot input format (no re-indexing). 02400 * Variant of DotWrite() without re-indexing. 02401 * 02402 * @param rFileName 02403 * File to write 02404 * 02405 * @exception Exception 02406 * - IO errors (id 2) 02407 */ 02408 virtual void DDotWrite(const std::string& rFileName) const; 02409 02410 /** 02411 * Writes generator to dot input format for export to VioLib. 02412 * Variant of DotWrite() using strategic state and event names 02413 * to simplify import to VioLib (qt widget for graphical representation 02414 * of FAUDES generators). 02415 * 02416 * @param rFileName 02417 * File to write 02418 * @exception Exception 02419 * - IO errors (id 2) 02420 */ 02421 virtual void XDotWrite(const std::string& rFileName) const; 02422 02423 /** 02424 * Read a state set. 02425 * Refer to the generators state symboltable while reading a state set. 02426 * Ignore any attributes. 02427 * 02428 * @param rTr 02429 * Reference to TokenReader 02430 * @param rLabel 02431 * Label of set in source 02432 * @param rStateSet 02433 * Destination state set 02434 * 02435 * @exception Exception 02436 * - IO errors (id 1) 02437 * - token mismatch (id 50, 51, 52, 80, 85) 02438 */ 02439 void ReadStateSet(TokenReader& rTr, const std::string& rLabel, StateSet& rStateSet) const; 02440 02441 02442 /** @} doxygen group */ 02443 02444 02445 /***************************************** 02446 ***************************************** 02447 ***************************************** 02448 *****************************************/ 02449 02450 /** @name Misc */ 02451 /** @{ doxygen group */ 02452 02453 /** 02454 * Return used events (executed in transitions) 02455 * 02456 * @return EventSet 02457 */ 02458 EventSet UsedEvents(void) const; 02459 02460 /** 02461 * Return unused events 02462 * 02463 * @return EventSet 02464 */ 02465 EventSet UnusedEvents(void) const; 02466 02467 /** 02468 * Set the alphabet to used events 02469 */ 02470 void MinimizeAlphabet(void); 02471 02472 /** 02473 * Return active event set at state x1 02474 * 02475 * @param x1 02476 * Index of x1 02477 * 02478 * @return EventSet 02479 */ 02480 EventSet ActiveEventSet(Idx x1) const; 02481 02482 /** 02483 * Return active transition set at state x1 02484 * 02485 * @param x1 02486 * Index of x1 02487 * 02488 * @return EventSet 02489 */ 02490 TransSet ActiveTransSet(Idx x1) const; 02491 02492 /** 02493 * Return the states covered by transitions 02494 * 02495 * @return StateSet 02496 */ 02497 StateSet TransRelStateSpace(void) const; 02498 02499 /** 02500 * Return the successor states of state x1 02501 * 02502 * @return StateSet 02503 */ 02504 StateSet TransRelStateSpace(Idx x1) const; 02505 02506 /** 02507 * Check if generator is deterministic. 02508 * We insict in exactly one initial state and for each state and event at most 02509 * one transition (to some successor state). This definition matches the situation 02510 * where a generator is defined to have one inital state as opposed to a set set of initial 02511 * states (which may be empty). In particular, the generated language of a determinitstic 02512 * generator allways includes the empty string and therefor is not the empty set. When 02513 * focus is on the marked language only, this issue does not exists. 02514 * 02515 * @return 02516 * True if generator is deterministic 02517 */ 02518 bool IsDeterministic(void) const; 02519 02520 /** 02521 * Set minimal index map for file io of generator states 02522 * 02523 * This function is implemented as fake-const to allow for 02524 * const Write function. 02525 * 02526 */ 02527 void SetMinStateIndexMap(void) const; 02528 02529 /** 02530 * Clear minimal index map for 1:1 file io 02531 * 02532 */ 02533 void ClearMinStateIndexMap(void) const; 02534 02535 /** 02536 * Get state index as is it will be written to file 02537 * 02538 * @param index 02539 * state index 02540 * @return 02541 * minimal index 02542 */ 02543 Idx MinStateIndex(Idx index) const; 02544 02545 02546 /** 02547 * Get state index translation map 02548 * 02549 * @return 02550 * minimal index map 02551 */ 02552 const std::map<Idx,Idx>& MinStateIndexMap(void) const; 02553 02554 02555 /** 02556 * Pretty printable event name for index (eg for debugging). 02557 * 02558 * @param index 02559 * Event index 02560 * 02561 * @return 02562 * std::string 02563 */ 02564 std::string EStr(Idx index) const; 02565 02566 /** 02567 * Return pretty printable state name for index (eg for debugging) 02568 * 02569 * @param index 02570 * State index 02571 * 02572 * @return 02573 * std::string 02574 */ 02575 std::string SStr(Idx index) const; 02576 02577 02578 /** 02579 * Return pretty printable transition (eg for debugging) 02580 * 02581 * @param rTrans 02582 * Transition 02583 * 02584 * @return 02585 * std::string 02586 */ 02587 std::string TStr(const Transition& rTrans) const; 02588 02589 02590 /** 02591 * Produce graphical representation of this generator. 02592 * This method calls the generator's DotWrite function and then processes the output 02593 * with the dot tool from graphiz package. If no output format is given, 02594 * try to guess from filename extension. See also ProcessDot(). 02595 * 02596 * @param rFileName 02597 * Name of output file 02598 * @param rOutFormat 02599 * Graphics file format, eg "png", "jpg", "svg" 02600 * @param rDotExec 02601 * path/name of executable 02602 * @exception Exception 02603 * - IO errors (id 2) 02604 * - error during systemcall for dot (id 3) 02605 */ 02606 void GraphWrite(const std::string& rFileName, const std::string& rOutFormat="", 02607 const std::string& rDotExec="dot") const; 02608 02609 /** 02610 * Order for sorting containers of generators 02611 */ 02612 bool operator < (const vGenerator& rOtherGen) const { 02613 return (mId < rOtherGen.mId); 02614 } 02615 02616 02617 /** @} doxygen group */ 02618 02619 02620 protected: 02621 02622 /** Name of generator */ 02623 std::string mMyName; 02624 02625 /** Number of generator */ 02626 Idx mId; 02627 02628 /** Number of generator objects */ 02629 static Idx msObjectCount; 02630 02631 /** State symbol table (local per Generator)*/ 02632 SymbolTable mStateSymbolTable; 02633 02634 /** Pointer to State symbol table */ 02635 SymbolTable* mpStateSymbolTable; 02636 02637 /** Pointer to Event symbol table */ 02638 SymbolTable* mpEventSymbolTable; 02639 02640 /** Automatic state names */ 02641 bool mStateNamesEnabled; 02642 02643 /** Default for automatic statenames */ 02644 static bool msStateNamesEnabledDefault; 02645 02646 /** Pointer to alphabet (actual type depends on attributes) */ 02647 EventSet* mpAlphabet; 02648 02649 /** Pointer to state set (actual type depends on attributes) */ 02650 StateSet* mpStates; 02651 02652 /** Pointer to ransition relation (actual type depends on attributes) */ 02653 TransSet* mpTransRel; 02654 02655 /** Pointer to lobal attribute (actual type depends on attributes) */ 02656 AttributeVoid* mpGlobalAttribute; 02657 02658 /** Pointer to alphabet prototype (incl. attribute type) */ 02659 const EventSet* pAlphabetPrototype; 02660 02661 /** Pointer to state set prototype (incl. attribute type) */ 02662 const StateSet* pStatesPrototype; 02663 02664 /** Pointer to transition relation prototype (incl. attribute type) */ 02665 const TransSet* pTransRelPrototype; 02666 02667 /** Pointer to global attribute prototype (configures global attribute type) */ 02668 const AttributeVoid* pGlobalPrototype; 02669 02670 /** Static default alphabet prototype (incl. attribute type) */ 02671 static const EventSet& AlphabetVoid(void); 02672 02673 /** Static default state set prototype (incl. attribute type) */ 02674 static const StateSet& StatesVoid(void); 02675 02676 /** Static default transition relation prototype (incl. attribute type) */ 02677 static const TransSet& TransRelVoid(void); 02678 02679 /** Static default global attribute prototype (configures global attribute type) */ 02680 static const AttributeVoid& GlobalVoid(void); 02681 02682 /** Initial states */ 02683 StateSet mInitStates; 02684 02685 /** Marked states */ 02686 StateSet mMarkedStates; 02687 02688 /** Map State indices to consecutive indices */ 02689 std::map<Idx,Idx> mMinStateIndexMap; 02690 02691 /** Allocate my heap members (attribute dependent types) */ 02692 virtual void NewCore(void); 02693 02694 /** Free my heap members (attribute dependent types) */ 02695 virtual void DeleteCore(void); 02696 02697 /** Callback for core update */ 02698 virtual void UpdateCore(void); 02699 02700 /** Configure attribute types */ 02701 void ConfigureAttributeTypes(const AttributeVoid* pNewGlobalPrototype, 02702 const StateSet* pNewStatesPrototype, const EventSet* pNewAlphabetPrototype, 02703 const TransSet* pNewTransRelPrototype); 02704 02705 /** 02706 * Read generator object from TokenReader, see Type::Read for public wrappers. 02707 * 02708 * Virtual function for std token io interface. Context is ignored, 02709 * label defaults to "Generator". 02710 * 02711 * @param rTr 02712 * TokenReader to read from 02713 * @param rLabel 02714 * Section to read 02715 * @param pContext 02716 * Read context to provide contextual information (ignored) 02717 * 02718 * @exception Exception 02719 * - token mismatch (id 50, 51, 52, 80, 85) 02720 * - IO error (id 1) 02721 */ 02722 virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0); 02723 02724 /** 02725 * Write generator to TokenWriter, see Type::Write for public wrappers. 02726 * 02727 * Virtual function for std token io interface. Context is ignored, 02728 * label defaults to "Generator". If the tokenwriter writes to a file, 02729 * state indices will be re-indext to start from 1. 02730 * 02731 * @param rTw 02732 * Reference to TokenWriter 02733 * @param rLabel 02734 * Label of section to write 02735 * @param pContext 02736 * Write context to provide contextual information (ignored) 02737 * 02738 * @exception Exception 02739 * - IO errors (id 2) 02740 */ 02741 virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const; 02742 02743 /** 02744 * Write generator in debugging format to TokenWriter, see Type::DWrite for public wrappers. 02745 * 02746 * Reimplement this method in derived classes to provide the std token io 02747 * interface defined in the public section of Type. 02748 * 02749 * @param rTw 02750 * Reference to TokenWriter 02751 * @param rLabel 02752 * Label of section to write 02753 * @param pContext 02754 * Write context to provide contextual information (ignored) 02755 * 02756 * @exception Exception 02757 * - IO errors (id 2) 02758 */ 02759 virtual void DoDWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const; 02760 02761 /** 02762 * Write generator statistics as comment to TokenWriter, see Type::SWrite for public wrappers. 02763 * 02764 * Reimplement this method in derived classes to provide the std token io 02765 * interface defined in the public section of Type. 02766 * 02767 * @param rTw 02768 * Reference to TokenWriter 02769 * 02770 * @exception Exception 02771 * - IO errors (id 2) 02772 */ 02773 virtual void DoSWrite(TokenWriter& rTw) const; 02774 02775 /** 02776 * Read the generator's name from a file 02777 * 02778 * @param rFileName 02779 * File to read from 02780 * 02781 * @exception Exception 02782 * - IO errors (id 1) 02783 * - token mismatch (id 50, 51, 52) 02784 */ 02785 void ReadGeneratorName(const std::string& rFileName); 02786 02787 /** 02788 * Read the generator's name from a TokenReader 02789 * 02790 * @param rTr 02791 * Reference to TokenReader 02792 * 02793 * @exception Exception 02794 * - IO errors (id 1) 02795 * - token mismatch (id 50, 51, 52) 02796 */ 02797 void ReadGeneratorName(TokenReader& rTr); 02798 02799 /** 02800 * Read the generator's alphabet from a file. 02801 * 02802 * @param rFileName 02803 * File to read from 02804 * 02805 * @exception Exception 02806 * - IO errors (id 1) 02807 * - token mismatch (id 50, 51, 52) 02808 */ 02809 void ReadAlphabet(const std::string& rFileName); 02810 02811 /** 02812 * Read the generator's alphabet from a TokenReader 02813 * 02814 * @param rTr 02815 * Reference to TokenReader 02816 * 02817 * @exception Exception 02818 * - IO errors (id 1) 02819 * - token mismatch (id 50, 51, 52) 02820 */ 02821 void ReadAlphabet(TokenReader& rTr); 02822 02823 /** 02824 * Read the generator's state set from a file. 02825 * This sets up the StateSymbolTable. 02826 * 02827 * @param rFileName 02828 * File to read from 02829 * 02830 * @exception Exception 02831 * - IO errors (id 1) 02832 * - token mismatch (id 50, 51, 52) 02833 */ 02834 void ReadStates(const std::string& rFileName); 02835 02836 /** 02837 * Read the generator's stateset from a TokenReader. 02838 * This sets up the StateSymbolTable 02839 * 02840 * @param rTr 02841 * Reference to TokenReader 02842 * 02843 * @exception Exception 02844 * - IO errors (id 1) 02845 * - token mismatch (id 50, 51, 52) 02846 */ 02847 void ReadStates(TokenReader& rTr); 02848 02849 /** 02850 * Read the generator's transition relation from a file. 02851 * 02852 * @param rFileName 02853 * File to read from 02854 * 02855 * @exception Exception 02856 * - IO errors (id 1) 02857 * - token mismatch (id 50, 51, 52) 02858 */ 02859 void ReadTransRel(const std::string& rFileName); 02860 02861 /** 02862 * Read the generator's transition relation from a TokenReader. 02863 * 02864 * @param rTr 02865 * Reference to TokenReader 02866 * 02867 * @exception Exception 02868 * - IO errors (id 1) 02869 * - token mismatch (id 50, 51, 52) 02870 */ 02871 void ReadTransRel(TokenReader& rTr); 02872 02873 /** 02874 * Get accessible states by filling accessibleset recursive 02875 * 02876 * @param accessibleset 02877 * Reference to StateSet with accessibel states 02878 * @param startState 02879 * State index to start with 02880 */ 02881 void CheckAccessible(StateSet& accessibleset, Idx startState) const; 02882 02883 /** 02884 * Get Coaccessible states by filling Coaccessibleset recursive 02885 * 02886 * @param Coaccessibleset 02887 * Reference to StateSet with coaccessibel states 02888 * @param rtrel 02889 * Reverse transition relation where x1 <-> x2 02890 * @param startState 02891 * State index to start with 02892 */ 02893 void CheckCoaccessible(StateSet& Coaccessibleset, const TransSetX2EvX1& rtrel, Idx startState) const; 02894 02895 02896 02897 }; 02898 02899 /** 02900 * Plain generator, api typedef for generator with no attributes. 02901 * \ingroup GeneratorClasses 02902 */ 02903 typedef vGenerator Generator; 02904 02905 /** Convenience typedef for generator vectors 02906 * \ingroup GeneratorClasses 02907 */ 02908 typedef TBaseVector<Generator> GeneratorVector; 02909 02910 02911 /** 02912 * RTI wrapper function. See also vGenerator::IsAccessible(). 02913 * \ingroup GeneratorFunctions 02914 */ 02915 bool IsAccessible(const vGenerator& rGen); 02916 02917 /** 02918 * RTI wrapper function. See also vGenerator::IsCoaccessible(). 02919 * \ingroup GeneratorFunctions 02920 */ 02921 bool IsCoaccessible(const vGenerator& rGen); 02922 02923 /** 02924 * RTI wrapper function. See also vGenerator::IsTrim(). 02925 * \ingroup GeneratorFunctions 02926 */ 02927 bool IsTrim(const vGenerator& rGen); 02928 02929 /** 02930 * RTI wrapper function. See also vGenerator::IsOmegaTrim(). 02931 * \ingroup GeneratorFunctions 02932 */ 02933 bool IsOmegaTrim(const vGenerator& rGen); 02934 02935 /** 02936 * RTI wrapper function. See also vGenerator::IsComplete(). 02937 * \ingroup GeneratorFunctions 02938 */ 02939 bool IsComplete(const vGenerator& rGen); 02940 02941 /** 02942 * RTI wrapper function. See also vGenerator::IsDeterministic(). 02943 * \ingroup GeneratorFunctions 02944 */ 02945 bool IsDeterministic(const vGenerator& rGen); 02946 02947 02948 /** 02949 * RTI wrapper function. See also vGenerator::Accessible(). 02950 * \ingroup GeneratorFunctions 02951 */ 02952 void Accessible(vGenerator& rGen); 02953 02954 /** 02955 * RTI wrapper function. See also vGenerator::Accessible(). 02956 * \ingroup GeneratorFunctions 02957 */ 02958 void Accessible(const vGenerator& rGen, vGenerator& rRes); 02959 02960 /** 02961 * RTI wrapper function. See also vGenerator::Coaccessible(). 02962 * \ingroup GeneratorFunctions 02963 */ 02964 void Coaccessible(vGenerator& rGen); 02965 02966 /** 02967 * RTI wrapper function. See also vGenerator::Coaccessible(). 02968 * \ingroup GeneratorFunctions 02969 */ 02970 void Coaccessible(const vGenerator& rGen, vGenerator& rRes); 02971 02972 /** 02973 * RTI wrapper function. See also vGenerator::Complete(). 02974 * \ingroup GeneratorFunctions 02975 */ 02976 void Complete(vGenerator& rGen); 02977 02978 /** 02979 * RTI wrapper function. See also vGenerator::Complete(). 02980 * \ingroup GeneratorFunctions 02981 */ 02982 void Complete(const vGenerator& rGen, vGenerator& rRes); 02983 02984 /** 02985 * RTI wrapper function. See also vGenerator::Trim(). 02986 * \ingroup GeneratorFunctions 02987 */ 02988 void Trim(vGenerator& rGen); 02989 02990 /** 02991 * RTI wrapper function. See also vGenerator::Trim(). 02992 * \ingroup GeneratorFunctions 02993 */ 02994 void Trim(const vGenerator& rGen, vGenerator& rRes); 02995 02996 /** 02997 * RTI wrapper function. See also vGenerator::OmegaTrim(). 02998 * \ingroup GeneratorFunctions 02999 */ 03000 void OmegaTrim(vGenerator& rGen); 03001 03002 /** 03003 * RTI wrapper function. See also vGenerator::OmegaTrim(). 03004 * \ingroup GeneratorFunctions 03005 */ 03006 void OmegaTrim(const vGenerator& rGen, vGenerator& rRes); 03007 03008 /** 03009 * RTI wrapper function. 03010 * \ingroup GeneratorFunctions 03011 */ 03012 void MarkAllStates(vGenerator& rGen); 03013 03014 /** 03015 * RTI wrapper function. 03016 * \ingroup GeneratorFunctions 03017 */ 03018 void AlphabetExtract(const vGenerator& rGen, EventSet& rRes); 03019 03020 03021 /** 03022 * RTI convenience function. 03023 */ 03024 void SetIntersection(const vGenerator& rGenA, const vGenerator& rGenB, EventSet& rRes); 03025 03026 /** 03027 * RTI convenience function. 03028 */ 03029 void SetIntersection(const GeneratorVector& rGenVec, EventSet& rRes); 03030 03031 /** 03032 * RTI convenience function. 03033 */ 03034 void SetUnion(const vGenerator& rGenA, const vGenerator& rGenB, EventSet& rRes); 03035 03036 /** 03037 * RTI convenience function. 03038 */ 03039 void SetUnion(const GeneratorVector& rGenVec, EventSet& rRes); 03040 03041 /** 03042 * RTI convenience function. 03043 */ 03044 void SetDifference(const vGenerator& rGenA, const vGenerator& rGenB, EventSet& rRes); 03045 03046 03047 03048 03049 } // namespace faudes 03050 03051 /* 03052 03053 #define FAUDES_GENERATOR_DECLARATION(gtype,GlobalAttr,StateAttr,EventAttr,TransAttr) \ 03054 public: \ 03055 virtual void EventAttribute(Idx index, const EventAttr& rAttr); \ 03056 virtual void EventAttributes(const TaEventSet<EventAttr>& rEventSet); \ 03057 virtual const EventAttr& EventAttribute(Idx index) const; \ 03058 virtual const EventAttr& EventAttribute(const std::string& rName) const; \ 03059 virtual EventAttr* EventAttributep(Idx index); \ 03060 virtual EventAttr* EventAttributep(const std::string& rName); \ 03061 virtual void StateAttribute(Idx index, const StateAttr& rAttr); \ 03062 virtual const StateAttr& StateAttribute(Idx index) const; \ 03063 virtual StateAttr* StateAttributep(Idx index); \ 03064 virtual void TransAttribute(const Transition& rTrans, const TransAttr& rAttr); \ 03065 virtual const TransAttr& TransAttribute(const Transition& rTrans) const; \ 03066 virtual TransAttr* TransAttributep(const Transition& rTrans); \ 03067 virtual void GlobalAttribute(const GlobalAttr& rAttr); \ 03068 virtual void GlobalAttributeTry(const Type& rAttr); \ 03069 virtual const GlobalAttr& GlobalAttribute(void) const; \ 03070 virtual GlobalAttr* GlobalAttributep(void); 03071 03072 #define FAUDES_GENERATOR_IMPLEMENTATION(gtype,GlobalAttr,StateAttr,EventAttr,TransAttr) \ 03073 public: \ 03074 virtual void EventAttribute(Idx index, const EventAttr& rAttr); \ 03075 virtual void EventAttributes(const TaEventSet<EventAttr>& rEventSet); \ 03076 virtual const EventAttr& EventAttribute(Idx index) const; \ 03077 virtual const EventAttr& EventAttribute(const std::string& rName) const; \ 03078 virtual EventAttr* EventAttributep(Idx index); \ 03079 virtual EventAttr* EventAttributep(const std::string& rName); \ 03080 virtual void StateAttribute(Idx index, const StateAttr& rAttr); \ 03081 virtual const StateAttr& StateAttribute(Idx index) const; \ 03082 virtual StateAttr* StateAttributep(Idx index); \ 03083 virtual void TransAttribute(const Transition& rTrans, const TransAttr& rAttr); \ 03084 virtual const TransAttr& TransAttribute(const Transition& rTrans) const; \ 03085 virtual TransAttr* TransAttributep(const Transition& rTrans); \ 03086 virtual void GlobalAttribute(const GlobalAttr& rAttr); \ 03087 virtual void GlobalAttributeTry(const Type& rAttr); \ 03088 virtual const GlobalAttr& GlobalAttribute(void) const; \ 03089 virtual GlobalAttr* GlobalAttributep(void); 03090 03091 */ 03092 03093 03094 #endif 03095 |
libFAUDES 2.18b --- 2010-12-17 --- c++ source docu by doxygen 1.6.3