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