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 copies attributes 00281 * if types can be casted. Use AssignWithoutAttributes 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 Assign 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 that 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 enabled. 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 * @param x1 01196 * Predecessor state 01197 * @param ev 01198 * Event 01199 * @param x2 01200 * Successor state 01201 * 01202 * @return 01203 * true / false 01204 */ 01205 bool ExistsTransition(Idx x1, Idx ev, Idx x2) const; 01206 01207 /** 01208 * test for transition 01209 * 01210 * 01211 * @param rTrans 01212 * transition 01213 * 01214 * @return 01215 * true / false 01216 */ 01217 bool ExistsTransition(const Transition& rTrans) const; 01218 01219 /** 01220 * Test for transition given by x1, ev 01221 * 01222 * @param x1 01223 * Predecessor state 01224 * @param ev 01225 * Event 01226 * 01227 * @return 01228 * true / false 01229 */ 01230 bool ExistsTransition(Idx x1, Idx ev) const; 01231 01232 /** 01233 * Test for transition given by x1 01234 * 01235 * @param x1 01236 * Predecessor state 01237 * 01238 * @return 01239 * true / false 01240 */ 01241 bool ExistsTransition(Idx x1) const; 01242 01243 /** 01244 * Return reference to transition relation 01245 * 01246 * @return TransRel 01247 */ 01248 const TransSet& TransRel(void) const; 01249 01250 /** 01251 * Get copy of trantision relation sorted by other compare 01252 * operator, e.g. "x2,ev,x1" 01253 * 01254 * @param res 01255 * resulting transition relation 01256 */ 01257 void TransRel(TransSetX1EvX2& res) const; 01258 void TransRel(TransSetEvX1X2& res) const; 01259 void TransRel(TransSetEvX2X1& res) const; 01260 void TransRel(TransSetX2EvX1& res) const; 01261 void TransRel(TransSetX2X1Ev& res) const; 01262 void TransRel(TransSetX1X2Ev& res) const; 01263 01264 /** 01265 * Convebience function. 01266 * 01267 * @param rX1 01268 * Name of Predecessor state 01269 * @param rEv 01270 * Name of Event 01271 * @param rX2 01272 * Name of Successor state 01273 * 01274 * @return 01275 * Transition as specified. 01276 */ 01277 Transition TransitionByNames( 01278 const std::string& rX1, const std::string& rEv, const std::string& rX2) const; 01279 01280 /** @} doxygen group */ 01281 01282 01283 01284 /***************************************** 01285 ***************************************** 01286 ***************************************** 01287 *****************************************/ 01288 01289 /** @name Write Access to Core Members */ 01290 /** @{ doxygen group */ 01291 01292 01293 /** 01294 * Add an existing event to alphabet by index. It is an error to insert 01295 * an event index that is not known to the mpEventSymbolTable. 01296 * 01297 * @param index 01298 * Event index 01299 * @return 01300 * True, if event was new to alphabet 01301 */ 01302 bool InsEvent(Idx index); 01303 01304 /** 01305 * Add named event to generator. An entry in the mpEventSymbolTable will 01306 * be made if event name is not known so far. 01307 * 01308 * @param rName 01309 * Name of the event to add 01310 * 01311 * @return 01312 * New unique index 01313 */ 01314 Idx InsEvent(const std::string& rName); 01315 01316 /** 01317 * Add new named events to generator. 01318 * If the event allready exists, the attribute is maintained. 01319 * 01320 * @param events 01321 * EventSet 01322 */ 01323 void InsEvents(const EventSet& events); 01324 01325 /** 01326 * Delete event from generator by index. mpEventSymbolTable stays untouched. 01327 * Transitions containing event will be removed too. 01328 * 01329 * @param index 01330 * Index of event 01331 * @return 01332 * True, if event was in alphabet 01333 * 01334 */ 01335 bool DelEvent(Idx index); 01336 01337 /** 01338 * Delete event from generator by name. mpEventSymbolTable stays untouched. 01339 * Transitions containing event will be removed too. 01340 * 01341 * @param rName 01342 * Name of event 01343 * @return 01344 * True, if event was in alphabet 01345 * 01346 */ 01347 bool DelEvent(const std::string& rName); 01348 01349 /** 01350 * Delete a set of events from generator. mpEventSymbolTable stays untouched. 01351 * Transitions containing events will be removed too. 01352 * 01353 * @param rEvents 01354 * EventSet containing events to remove 01355 */ 01356 void DelEvents(const EventSet& rEvents); 01357 01358 /** 01359 * Delete event from alphabet without consistency check. The event is only 01360 * deleted from mpAlphabet but not from transition relation. 01361 * 01362 * @param index 01363 * Index of event 01364 * @return 01365 * True, if event was in alphabet 01366 * 01367 */ 01368 bool DelEventFromAlphabet(Idx index); 01369 01370 /** 01371 * Set mpAlphabet without consistency check. 01372 * Sets the alphabet incl attributes, if provided. 01373 * 01374 * @param rNewalphabet 01375 * EventSet with new alphabet 01376 */ 01377 void InjectAlphabet(const EventSet& rNewalphabet); 01378 01379 /** 01380 * Restricts mpAlphabet without consistency check. 01381 * Maintains attributes if any. 01382 * 01383 * @param rNewalphabet 01384 * EventSet with alphabet 01385 */ 01386 void RestrictAlphabet(const EventSet& rNewalphabet); 01387 01388 /** 01389 * Add new anonymous state to generator 01390 * 01391 * @return 01392 * Index of new unique state 01393 */ 01394 Idx InsState(void); 01395 01396 /** 01397 * Add (perhaps new) state to generator 01398 * 01399 * @return 01400 * True to indicate that state was new to generator 01401 */ 01402 bool InsState(Idx index); 01403 01404 /** 01405 * Add new named state to generator. 01406 * 01407 * @param rName 01408 * Name of the state to add 01409 * 01410 * @return 01411 * Index of new unique state 01412 * 01413 * @exception Exception 01414 * Name already exists (id 44) 01415 */ 01416 Idx InsState(const std::string& rName); 01417 01418 /** 01419 * Delete a state from generator by index. 01420 * Cleans mpStates, mInitStates, mMarkedStates, mpTransRel and mpStateSymbolTable. 01421 * 01422 * @param index 01423 * Index of state to delete. 01424 * @return 01425 * True, if state was in stateset 01426 */ 01427 bool DelState(Idx index); 01428 01429 /** 01430 * Delete a state from generator by name. 01431 * Cleans mpStates, mInitStates, mMarkedStates, mpTransRel and mpStateSymbolTable. 01432 * 01433 * @param rName 01434 * Name of state to delete. Will be erased in mpStateSymbolTable too 01435 * @return 01436 * True, if state was in stateset 01437 * 01438 * @exception Exception 01439 * - Symbolic name not known (id 90) 01440 */ 01441 bool DelState(const std::string& rName); 01442 01443 /** 01444 * Delete a set of states 01445 * Cleans mpStates, mInitStates, mMarkedStates, mpTransrel, and mpStateSymboltable 01446 * 01447 * @param rDelStates 01448 * StateSet containing states aka indicees to delete 01449 */ 01450 void DelStates(const StateSet& rDelStates); 01451 01452 01453 /** 01454 * Delete a state from generator without consistency check. This removes the 01455 * state from mpStates and mpStateSymbolTable but doesn't touch mpTransRel, 01456 * mInitStates and mMarkedStates. 01457 * 01458 * @param index 01459 * Index of state to delete. 01460 * @return 01461 * True, if state was in stateset 01462 * 01463 */ 01464 bool DelStateFromStates(Idx index); 01465 01466 /** 01467 * Delete a state from generator without consistency check. This removes the 01468 * state from mpStates and mpStateSymbolTable but doesn't touch mpTransRel, 01469 * mInitStates and mMarkedStates. 01470 * Index to delete is given by iterator. 01471 * 01472 * @param pos 01473 * StateSet::Iterator 01474 * @return 01475 * Iteraror to next state 01476 */ 01477 StateSet::Iterator DelStateFromStates(StateSet::Iterator pos); 01478 01479 /** 01480 * Inject an existing state index into generators mStates 01481 * Use with care! For use in performance optimized functions. 01482 * 01483 * @param index 01484 * State index to inject 01485 */ 01486 void InjectState(Idx index); 01487 01488 /** 01489 * Inject a complete state set without consistency checks (without attributes) 01490 * 01491 * @param rNewStates 01492 * StateSet 01493 */ 01494 void InjectStates(const StateSet& rNewStates); 01495 01496 01497 /** 01498 * Create new anonymous state and set as initial state 01499 * 01500 * @return 01501 * Index of new unique 01502 */ 01503 Idx InsInitState(void); 01504 01505 /** 01506 * Add (perhaps new) state to generator and turn it 01507 * into a initial state. 01508 * 01509 * @param index 01510 * State to insert 01511 * @return 01512 * True to indicate that state was new to generator 01513 */ 01514 bool InsInitState(Idx index); 01515 01516 /** 01517 * Create a new named state and set as initial state 01518 * 01519 * @param rName 01520 * Name of the state to add 01521 * 01522 * @return 01523 * Index of new unique state 01524 */ 01525 Idx InsInitState(const std::string& rName); 01526 01527 /** 01528 * Create new anonymous state and set as marked state 01529 * 01530 * @return 01531 * Index of new unique state 01532 */ 01533 Idx InsMarkedState(void); 01534 01535 /** 01536 * Add (perhaps new) state to generator and turn it 01537 * into a marked state. 01538 * 01539 * @param index 01540 * State to insert 01541 * @return 01542 * True to indicate that state was new to generator 01543 */ 01544 bool InsMarkedState(Idx index); 01545 01546 /** 01547 * Create a new named state and set as marked state 01548 * 01549 * @param rName 01550 * Name of the state to add 01551 * 01552 * @return 01553 * Index of new unique state 01554 */ 01555 Idx InsMarkedState(const std::string& rName); 01556 01557 /** 01558 * Set an existing state as initial state by index. 01559 * 01560 * @param index 01561 * Index of state to set as initial state 01562 * @exception Exception 01563 * - State index not found in generator (id 91) 01564 */ 01565 void SetInitState(Idx index); 01566 01567 /** 01568 * Set an existing state as initial state by name. 01569 * 01570 * @param rName 01571 * Name of state to set as initial state 01572 * 01573 * @exception Exception 01574 * - State name not known in generator (id 90) 01575 */ 01576 void SetInitState(const std::string& rName); 01577 01578 /** 01579 * Replace mInitStates with StateSet given as parameter without consistency checks. 01580 * 01581 * @param rNewInitStates 01582 * StateSet containing new mInitStates 01583 */ 01584 void InjectInitStates(const StateSet& rNewInitStates); 01585 01586 /** 01587 * Unset an existing state as initial state by index 01588 * 01589 * Define FAUDES_CHECKED for consistency checks. 01590 * 01591 * @param index 01592 * State index 01593 * 01594 * @exception Exception 01595 * - State index not found in generator (id 91) 01596 */ 01597 void ClrInitState(Idx index); 01598 01599 /** 01600 * Unset an existing state as initial state by name 01601 * 01602 * @param rName 01603 * State name 01604 * 01605 * @exception Exception 01606 * - State name not known in generator (id 90) 01607 */ 01608 void ClrInitState(const std::string& rName); 01609 01610 /** 01611 * Unset an existing state as initial state by iterator 01612 * 01613 * @param pos 01614 * StateSet::iterator 01615 * @return 01616 * Iterator to next init state 01617 */ 01618 StateSet::Iterator ClrInitState(StateSet::Iterator pos); 01619 01620 /** 01621 * Clear all mInitStates 01622 */ 01623 void ClearInitStates(void); 01624 01625 /** 01626 * Set an existing state as marked state by index 01627 * 01628 * @param index 01629 * Index of state to set as initial state 01630 * @exception Exception 01631 * - State index not found in generator (id 91) 01632 */ 01633 void SetMarkedState(Idx index); 01634 01635 /** 01636 * Set an existing state as marked state by name. 01637 * 01638 * @param rName 01639 * Name of state to set as marked state 01640 * 01641 * @exception Exception 01642 * - State name not known in generator (id 90) 01643 */ 01644 void SetMarkedState(const std::string& rName); 01645 01646 /** 01647 * Unset an existing state as marked state by index 01648 * 01649 * @param index 01650 * State index 01651 * 01652 * @exception Exception 01653 * - State index not found in generator (id 91) 01654 */ 01655 void ClrMarkedState(Idx index); 01656 01657 /** 01658 * Unset an existing state as marked state by name 01659 * 01660 * @param rName 01661 * State name 01662 * 01663 * @exception Exception 01664 * - State index not found in generator (id 91) 01665 */ 01666 void ClrMarkedState(const std::string& rName); 01667 01668 /** 01669 * Unset an existing state as marked state by iterator 01670 * 01671 * @param pos 01672 * StateSet::iterator 01673 * @return 01674 * Iterator to next marked state 01675 */ 01676 StateSet::Iterator ClrMarkedState(StateSet::Iterator pos); 01677 01678 /** 01679 * Clear all marked states 01680 */ 01681 void ClearMarkedStates(void); 01682 01683 /** 01684 * Replace mMarkedStates with StateSet given as parameter without consistency checks. 01685 * 01686 * @param rNewMarkedStates 01687 * StateSet containing new marked states 01688 */ 01689 void InjectMarkedStates(const StateSet& rNewMarkedStates); 01690 01691 /** 01692 * Add a transition to generator by indices. States and event 01693 * must already exist. 01694 * 01695 * @param x1 01696 * Predecessor state index 01697 * @param ev 01698 * Event index 01699 * @param x2 01700 * Successor state index 01701 * 01702 * @return 01703 * True, if the transition was new the generator 01704 * 01705 * @exception Exception 01706 * - state or event not in generator (id 95) 01707 */ 01708 bool SetTransition(Idx x1, Idx ev, Idx x2); 01709 01710 /** 01711 * Add a transition to generator by names. Statename and eventname 01712 * must already exist. 01713 * 01714 * @param rX1 01715 * Predecessor state name 01716 * @param rEv 01717 * Event name 01718 * @param rX2 01719 * Successor state name 01720 * 01721 * @return 01722 * True, if the transition was new the generator 01723 * 01724 * @exception Exception 01725 * - state or event not in generator (id 95) 01726 * - state name not known (id 90) 01727 * - event name not known (id 66) 01728 */ 01729 bool SetTransition(const std::string& rX1, const std::string& rEv, 01730 const std::string& rX2); 01731 01732 /** 01733 * Add a transition to generator. States and event 01734 * must already exist. 01735 * 01736 * 01737 * @param rTransition 01738 * Transition 01739 * 01740 * @return 01741 * True, if the transition was new the generator 01742 * @exception Exception 01743 * - state or event not in generator (id 95) 01744 */ 01745 bool SetTransition(const Transition& rTransition); 01746 01747 /** 01748 * Remove a transition by indices 01749 * 01750 * @param x1 01751 * Predecessor state index 01752 * @param ev 01753 * Event index 01754 * @param x2 01755 * Successor state index 01756 */ 01757 void ClrTransition(Idx x1, Idx ev, Idx x2); 01758 01759 /** 01760 * Remove a transition by transition object 01761 * 01762 * @param rTrans 01763 * Transition object 01764 */ 01765 void ClrTransition(const Transition& rTrans); 01766 01767 /** 01768 * Remove a transition by iterator 01769 * 01770 * @param it 01771 * TransSet::iterator 01772 * @return 01773 * Iterator to next transition 01774 */ 01775 TransSet::Iterator ClrTransition(TransSet::Iterator it); 01776 01777 /** 01778 * Remove a transitions by state and event 01779 * 01780 * @param x1 01781 * Predecessor state index 01782 * @param ev 01783 * Event index 01784 */ 01785 void ClrTransitions(Idx x1, Idx ev); 01786 01787 /** 01788 * Remove a transitions by state 01789 * 01790 * @param x1 01791 * Predecessor state index 01792 */ 01793 void ClrTransitions(Idx x1); 01794 01795 /** 01796 * Clear all transitions 01797 */ 01798 void ClearTransRel(void); 01799 01800 /** 01801 * Set transition without consistency check. 01802 * 01803 * @param rTrans 01804 * Transition to insert 01805 */ 01806 void InjectTransition(const Transition& rTrans); 01807 01808 /** 01809 * Set transition relation without consistency check (no attributes) 01810 * 01811 * @param rNewtransrel 01812 * TransRel to insert 01813 */ 01814 void InjectTransRel(const TransSet& rNewtransrel); 01815 01816 /** @} doxygen group */ 01817 01818 01819 01820 /***************************************** 01821 ***************************************** 01822 ***************************************** 01823 *****************************************/ 01824 01825 /** @name Attributes */ 01826 /** @{ doxygen group */ 01827 01828 01829 /** 01830 * Clear Attributes 01831 */ 01832 virtual void ClearAttributes(void); 01833 01834 /** 01835 * Updates internal attributes. 01836 * This method does nothing and may be reimplemented 01837 * by a any class that adds semantics to attributes 01838 * Eg. you may set a particular state flag, if this state 01839 * is reachable. 01840 * 01841 * @return True if value changed 01842 */ 01843 virtual bool UpdateAttributes(void) {return false;}; 01844 01845 /** 01846 * Clear event attributes 01847 */ 01848 virtual void ClearEventAttributes(void); 01849 01850 /** 01851 * Clear attribute for existing event 01852 * 01853 * @param index 01854 * Event index 01855 */ 01856 virtual void ClrEventAttribute(Idx index); 01857 01858 /** 01859 * Set attribute for existing event. 01860 * This version uses a dynamic cast 01861 * to test the actual type of the provided attribute. An exception is 01862 * thrown for an invalid attribute type. 01863 * In a context where 01864 * the attribute type is known, you may prefer the TaGenerator method. 01865 * 01866 * @param index 01867 * Event index 01868 * @param rAttr 01869 * New attribute 01870 * 01871 * @exception Exception 01872 * - Index not found in alphabet (id 60) 01873 * - Cannot cast attribute (id 63) 01874 */ 01875 virtual void EventAttribute(Idx index, const Type& rAttr); 01876 01877 /** 01878 * Set attributes for existing events. 01879 * This version uses a dynamic cast 01880 * to test the actual type of the provided attributes. An exception is 01881 * thrown for an invalid attribute type. 01882 * 01883 * @param rEventSet 01884 * Set of attributed events 01885 * @exception Exception 01886 * - Element not found in alphabet (id 60) 01887 * - Cannot cast attribute (id 63) 01888 */ 01889 virtual void EventAttributes(const EventSet& rEventSet); 01890 01891 /** 01892 * Event attribute lookup. 01893 * In a context where 01894 * the attribute type is known, you may prefer the TaGenerator method. 01895 * 01896 * @param index 01897 * 01898 * @return 01899 * reference to attribute 01900 */ 01901 virtual const AttributeVoid& EventAttribute(Idx index) const; 01902 01903 /** 01904 * Event attribute lookup. 01905 * In a context where the attribute type is known, 01906 * you may prefer the TaGenerator method. 01907 * 01908 * @param rName 01909 * 01910 * @return 01911 * reference to attribute 01912 */ 01913 virtual const AttributeVoid& EventAttribute(const std::string& rName) const; 01914 01915 /** 01916 * Event attribute pointer to access Attribute methods. 01917 * If there are no attributes (plain vGenerator) this method 01918 * returs 0. If there are attributes, an explicit default value 01919 * may be inserted. 01920 * In a context where the attribute type is known, 01921 * you may prefer the TaGenerator method. 01922 * 01923 * @param index 01924 * 01925 * @return 01926 * pointer to attribute 01927 */ 01928 virtual AttributeVoid* EventAttributep(Idx index); 01929 01930 /** 01931 * Event attribute pointer to access Attribute methods. 01932 * If there are no attributes (plain vGenerator) this method 01933 * returs 0. If there are attributes, an explicit default value 01934 * may be inserted. 01935 * In a context where the attribute type is known, 01936 * you may prefer the TaGenerator method. 01937 * 01938 * @param rName 01939 * 01940 * @return 01941 * pointer to attribute 01942 */ 01943 virtual AttributeVoid* EventAttributep(const std::string& rName); 01944 01945 01946 /** 01947 * Clear state attributes 01948 */ 01949 virtual void ClearStateAttributes(void); 01950 01951 /** 01952 * Clear attribute for existing state 01953 * 01954 * @param index 01955 * State index 01956 */ 01957 virtual void ClrStateAttribute(Idx index); 01958 01959 /** 01960 * Set attribute for existing state. 01961 * This version uses a dynamic cast 01962 * to test the actual type of the provided attribute. An exception is 01963 * thrown for an invalid attribute type. 01964 * In a context where 01965 * the attribute type is known, you may prefer the TaGenerator method. 01966 * 01967 * @param index 01968 * State index 01969 * @param rAttr 01970 * New attribute 01971 * 01972 * @exception Exception 01973 * - Index not found in Stateset (id 60) 01974 * - Cannot cast attribute (id 63) 01975 */ 01976 virtual void StateAttribute(Idx index, const Type& rAttr); 01977 01978 /** 01979 * State attribute lookup. 01980 * In a context where the attribute type is known, 01981 * you may prefer the TaGenerator method. 01982 * 01983 * @param index 01984 * State index 01985 * 01986 * @return Ref to attribute of state 01987 */ 01988 virtual const AttributeVoid& StateAttribute(Idx index) const; 01989 01990 /** 01991 * State attribute pointer to access Attribute methods. 01992 * If there are no attributes (plain vGenerator) this method 01993 * returns 0. If there are attributes, an explicit default value 01994 * may be inserted. 01995 * In a context where the attribute type is known, 01996 * you may prefer the TaGenerator method. 01997 * 01998 * @param index 01999 * State index 02000 * 02001 * @return Pointer to attribute of state 02002 */ 02003 virtual AttributeVoid* StateAttributep(Idx index); 02004 02005 /** 02006 * Clear transition attributes 02007 */ 02008 virtual void ClearTransAttributes(void); 02009 02010 /** 02011 * Set attribute for existing transition. 02012 * This version uses a dynamic cast 02013 * to test the actual type of the provided attribute. An exception is 02014 * thrown for an invalid attribute type. 02015 * In a context where 02016 * the attribute type is known, you may prefer the TaGenerator method. 02017 * 02018 * @param rTrans 02019 * Transition 02020 * @param rAttr 02021 * New attribute 02022 * 02023 * @exception Exception 02024 * - Transition not found in transition relation(id 60) 02025 * - Cannot cast attribute (id 63) 02026 */ 02027 virtual void TransAttribute(const Transition& rTrans, const Type& rAttr); 02028 02029 02030 /** 02031 * Clear attribute for existing transition 02032 * 02033 * @param rTrans 02034 * transition 02035 */ 02036 virtual void ClrTransAttribute(const Transition& rTrans); 02037 02038 /** 02039 * Transition attribute lookup. 02040 * In a context where the attribute type is known, 02041 * you may prefer the TaGenerator method. 02042 * 02043 * @return 02044 * Attribute 02045 * 02046 */ 02047 virtual const AttributeVoid& TransAttribute(const Transition& rTrans) const; 02048 02049 /** 02050 * Transition attribute pointer to access Attribute methods. 02051 * If there are no attributes (plain vGenerator) this method 02052 * returns 0. If there are attributes, an explicit default value 02053 * may be inserted. 02054 * In a context where the attribute type is known, 02055 * you may prefer the TaGenerator method. 02056 * 02057 * @return 02058 * Attribute pointer 02059 * 02060 */ 02061 virtual AttributeVoid* TransAttributep(const Transition& rTrans); 02062 02063 /** 02064 * Clear global attribute 02065 */ 02066 virtual void ClearGlobalAttribute(void); 02067 02068 /** 02069 * Set global attribute. 02070 * The vGenerator does not have attributes, so this function throws an exception for 02071 * any specified attribute different to AttributeVoid. 02072 * The TaGenarator provides a re-implementation to actually set the global attribute. 02073 * 02074 * @param rAttr 02075 * Attribute 02076 * @exception Exception 02077 * - Cannot cast attribute (id 63) 02078 */ 02079 virtual void GlobalAttribute(const Type& rAttr); 02080 02081 /** 02082 * Set global attribute. 02083 * The vGenerator does not have attributes, so this function does nothing. 02084 * The TaGenarator provides a re-implementation to actually set the global attribute. 02085 * 02086 * @param rAttr 02087 * Attribute 02088 */ 02089 virtual void GlobalAttributeTry(const Type& rAttr); 02090 02091 /** 02092 * Global attribute lookup. 02093 * In a context where the attribute type is known, 02094 * you may prefer the TaGenerator method. 02095 */ 02096 virtual const AttributeVoid& GlobalAttribute(void) const; 02097 02098 02099 /** 02100 * Get attribute pointer 02101 * The global attribute allways exits. For the vGenerator its of 02102 * type AttributeVoid, the TaGenerator sets a nontrivial type. 02103 * In a context where the attribute type is known, 02104 * you may prefer the TaGenerator method. 02105 */ 02106 virtual AttributeVoid* GlobalAttributep(void); 02107 02108 02109 /** @} doxygen group */ 02110 02111 02112 02113 /***************************************** 02114 ***************************************** 02115 ***************************************** 02116 *****************************************/ 02117 02118 /** @name Reachability */ 02119 /** @{ doxygen group */ 02120 02121 02122 /** 02123 * Compute set of accessible states 02124 */ 02125 StateSet AccessibleSet(void) const; 02126 02127 /** 02128 * Make generator accessible. 02129 * 02130 * @return 02131 * True if generator contains at least one initial state 02132 */ 02133 bool Accessible(void); 02134 02135 /** 02136 * Check if generator is accessible 02137 * 02138 * @return 02139 * True if generator is accesssible 02140 */ 02141 bool IsAccessible(void) const; 02142 02143 /** 02144 * Compute set of Coaccessible states 02145 */ 02146 StateSet CoaccessibleSet(void) const; 02147 02148 /** 02149 * Make generator Coaccessible 02150 * 02151 * @return 02152 * True if generator contains at least one marked state 02153 */ 02154 bool Coaccessible(void); 02155 02156 /** 02157 * Check if generator is Coaccessible 02158 * 02159 * @return 02160 * True if generator is coaccessible 02161 */ 02162 bool IsCoaccessible(void) const; 02163 02164 /** 02165 * Compute set of blocking states. 02166 * 02167 * A state is considered blocking it is accessible but not coaccessible. 02168 */ 02169 StateSet BlockingStates(void) const; 02170 02171 02172 /** 02173 * Compute set of terminal states. 02174 * 02175 * A terminal state is a state with no successor state. 02176 * If and only if the set of terminal states is empty, the generator is complete. 02177 * @return 02178 * Set of terminal states. 02179 */ 02180 StateSet TerminalStates(void) const; 02181 02182 02183 /** 02184 * Compute set of terminal states. 02185 * 02186 * A terminal state is a state with no successor state. 02187 * This function returns the the set terminal states contained 02188 * in the specified state ste. 02189 * 02190 * @param rStates 02191 * Set of state indices to restrict the search 02192 * @return 02193 * Set of terminal states. 02194 */ 02195 StateSet TerminalStates(const StateSet& rStates) const; 02196 02197 /** 02198 * Make generator Complete. 02199 * 02200 * This procedure removes all states that are guaranteed to evolve 02201 * into a terminal state within a finite number of transitios. 02202 * The current implementations in initialized by 02203 * the set of terminal states and then performs a backward 02204 * reachability analysis. 02205 * 02206 * @return 02207 * True if generator contains at least one initial state 02208 */ 02209 bool Complete(void); 02210 02211 /** 02212 * Check if generator is complete. 02213 * 02214 * A generator is considered complete, if each state has at least 02215 * one successor state. If the generator is trim, completeness 02216 * is equivalent to completeness of the markede language, ie 02217 * forall s in Lm(G) there exists r in Lm(G) with s<r 02218 * @return 02219 * True if generator is complete 02220 */ 02221 bool IsComplete(void) const; 02222 02223 /** 02224 * Check if generator is complete. 02225 * 02226 * Same as IsComplete(void), however, only the specified 02227 * states are considered. The rational is to e.g. apply the test 02228 * to accessible states only. In that case, the test is equivalent 02229 * to completeness of the generated language. 02230 * 02231 * @param rStates 02232 * Set of state indices to restrict the completeness test 02233 * @return 02234 * True if generator is relatively complete 02235 */ 02236 bool IsComplete(const StateSet& rStates) const; 02237 02238 02239 /** 02240 * Compute set of trim states 02241 */ 02242 StateSet TrimSet(void) const; 02243 02244 /** 02245 * Make generator trim 02246 * 02247 * This function removes all states are not accessible or not 02248 * coaccessible. In other words: only those states are kept, that 02249 * contribute to that marked language. 02250 * 02251 * @return 02252 * True if resulting generator contains at least one initial state and at least one marked state. 02253 */ 02254 bool Trim(void); 02255 02256 /** 02257 * Check if generator is trim. 02258 * 02259 * Returns true if all states are rechable and coreachale. 02260 * 02261 * @return 02262 * True if generator is trim 02263 */ 02264 bool IsTrim(void) const; 02265 02266 02267 /** 02268 * Make generator omega-trim 02269 * 02270 * This function removes states such that the generator becomes 02271 * omega trim while not affecting the induced omega language. 02272 * 02273 * The implementation first make the generator accessible 02274 * and then iteratively removes state that either 02275 * never reach a marked state or that are guaranteed to eventually 02276 * reach a terminal state. There might be a more efficient 02277 * approach. 02278 * 02279 * @return 02280 * True if resulting generator contains at least one initial state and at least one marked state. 02281 */ 02282 bool OmegaTrim(void); 02283 02284 02285 /** 02286 * Check if generator is omega-trim. 02287 * 02288 * Returns true if all states are accessible, coacessible, and 02289 * have a successor state. 02290 * 02291 * @return 02292 * True if generator is omega-trim 02293 */ 02294 bool IsOmegaTrim(void) const; 02295 02296 02297 02298 /** @} doxygen group */ 02299 02300 /***************************************** 02301 ***************************************** 02302 ***************************************** 02303 *****************************************/ 02304 02305 /** @name File IO */ 02306 /** @{ doxygen group */ 02307 02308 /** 02309 * Write generators alphabet to console 02310 */ 02311 void WriteAlphabet(void) const; 02312 02313 /** 02314 * Write generators alphabet to string 02315 * 02316 * @return 02317 * std::string 02318 * @exception Exception 02319 * - IO errors (id 2) 02320 */ 02321 std::string AlphabetToString(void) const; 02322 02323 /** 02324 * Write generators alphabet to tokenwriter 02325 * 02326 * @param rTw 02327 * Reference to TokenWriter 02328 * 02329 * @exception Exception 02330 * - IO errors (id 2) 02331 */ 02332 void WriteAlphabet(TokenWriter& rTw) const; 02333 02334 /** 02335 * Write a stateset to console (no re-indexing). 02336 * Uses WriteStateSet(TokenWriter& rTw, const StateSet&) const to write 02337 * the specified state set to console referring to this generators state names. 02338 * 02339 * @param rStateSet 02340 * Reference to stateset 02341 */ 02342 void WriteStateSet(const StateSet& rStateSet) const; 02343 02344 /** 02345 * Write a stateset to string (no re-indexing). 02346 * Uses WriteStateSet(TokenWriter& rTw, const StateSet&) const to write 02347 * the specified state set to a string referring to this generators state names. 02348 * 02349 * @param rStateSet 02350 * Reference to stateset 02351 * @return 02352 * std::string 02353 * @exception Exception 02354 * - IO errors (id 2) 02355 */ 02356 std::string StateSetToString(const StateSet& rStateSet) const; 02357 02358 /** 02359 * Write a stateset to formated text (no re-indexing). 02360 * Uses WriteStateSet(TokenWriter& rTw, const StateSet&) const to write 02361 * the specified state set to a string referring to this generators state names. 02362 * 02363 * @param rStateSet 02364 * Reference to stateset 02365 * @return 02366 * std::string 02367 * @exception Exception 02368 * - IO errors (id 2) 02369 */ 02370 std::string StateSetToText(const StateSet& rStateSet) const; 02371 02372 /** 02373 * Write a stateset to TokenWriter. 02374 * All native output of external state sets done with this function. 02375 * Technically, a StateSet is a set of plain indices with no references 02376 * to symbolic names. Thus, it is only the context of a Generator that provides 02377 * the symbolic names for file output. 02378 * 02379 * Output of state sets always uses the mMinStateIndexMap to re-index states. 02380 * However, this map is only set up automatically for file output. If You require 02381 * re-indexed output to e.g. a string, you must set up the map by calling SetMinStateIndexMap(). 02382 * To ensure that no re-indexing takes place, call ClearMinStateIndexMap(). 02383 * 02384 * @param rTw 02385 * Reference to TokenWriter 02386 * @param rStateSet 02387 * Reference to stateset 02388 * 02389 * @exception Exception 02390 * - IO errors (id 2) 02391 */ 02392 void WriteStateSet(TokenWriter& rTw, const StateSet& rStateSet) const; 02393 02394 /** 02395 * Write a stateset to TokenWriter (debug version, no re-indexing) 02396 * 02397 * @param rTw 02398 * Reference to TokenWriter 02399 * @param rStateSet 02400 * Reference to stateset 02401 * 02402 * @exception Exception 02403 * - IO errors (id 2) 02404 */ 02405 void DWriteStateSet(TokenWriter& rTw, const StateSet& rStateSet) const; 02406 02407 /** 02408 * Write stateset of this generator to a string (no re-indexing) 02409 * 02410 * @return 02411 * std::string 02412 * @exception Exception 02413 * - IO errors (id 2) 02414 */ 02415 std::string StatesToString(void) const; 02416 02417 /** 02418 * Write stateset of this generator to formated text (no re-indexing) 02419 * 02420 * @return 02421 * std::string 02422 * @exception Exception 02423 * - IO errors (id 2) 02424 */ 02425 std::string StatesToText(void) const; 02426 02427 /** 02428 * Write set of marked states to a string (no re-indexing) 02429 * 02430 * @return 02431 * std::string 02432 * @exception Exception 02433 * - IO errors (id 2) 02434 */ 02435 std::string MarkedStatesToString(void) const; 02436 02437 /** 02438 * Write set of initial states to a string (no re-indexing) 02439 * 02440 * @return 02441 * std::string 02442 * @exception Exception 02443 * - IO errors (id 2) 02444 */ 02445 std::string InitStatesToString(void) const; 02446 02447 /** 02448 * Write transition relation to console (no re-indexing) 02449 */ 02450 void WriteTransRel(void) const; 02451 02452 /** 02453 * Write transition relation to string (no re-indexing) 02454 */ 02455 std::string TransRelToString(void) const; 02456 02457 /** 02458 * Write transition relation to formated text (no re-indexing) 02459 */ 02460 std::string TransRelToText(void) const; 02461 02462 /** 02463 * Write transition relation to tokenwriter. 02464 * Re-indexing and symbolic state names are handled in the same way 02465 * as with state sets: this function refers to the generators state symboltable to 02466 * obtain state names and uses the mMinStateIndexMap to re-index the output. 02467 * 02468 * @param rTw 02469 * Reference to TokenWriter 02470 * 02471 * @exception Exception 02472 * - IO errors (id 2) 02473 */ 02474 void WriteTransRel(TokenWriter& rTw) const; 02475 02476 /** 02477 * Write transition relation to tokenwriter (debug version) 02478 * @param rTw 02479 * Reference to TokenWriter 02480 * 02481 * @exception Exception 02482 * - IO errors (id 2) 02483 */ 02484 void DWriteTransRel(TokenWriter& rTw) const; 02485 02486 02487 /** 02488 * Writes generator to dot input format. 02489 * The dot file format is specified by the graphiz package; see http://www.graphviz.org. 02490 * The package includes the dot command line tool to generate a graphical 02491 * representation of the generators graph. See also GraphWrite(). 02492 * This functions sets the re-indexing to minimal indices. 02493 * 02494 * @param rFileName 02495 * File to write 02496 * 02497 * @exception Exception 02498 * - IO errors (id 2) 02499 */ 02500 virtual void DotWrite(const std::string& rFileName) const; 02501 02502 /** 02503 * Writes generator to dot input format (no re-indexing). 02504 * Variant of DotWrite() without re-indexing. 02505 * 02506 * @param rFileName 02507 * File to write 02508 * 02509 * @exception Exception 02510 * - IO errors (id 2) 02511 */ 02512 virtual void DDotWrite(const std::string& rFileName) const; 02513 02514 /** 02515 * Writes generator to dot input format for export to VioLib. 02516 * Variant of DotWrite() using strategic state and event names 02517 * to simplify import to VioLib (qt widget for graphical representation 02518 * of FAUDES generators). 02519 * 02520 * @param rFileName 02521 * File to write 02522 * @exception Exception 02523 * - IO errors (id 2) 02524 */ 02525 virtual void XDotWrite(const std::string& rFileName) const; 02526 02527 /** 02528 * Read a state set. 02529 * Refer to the generators state symboltable while reading a state set. 02530 * Ignore any attributes. 02531 * 02532 * @param rTr 02533 * Reference to TokenReader 02534 * @param rLabel 02535 * Label of set in source 02536 * @param rStateSet 02537 * Destination state set 02538 * 02539 * @exception Exception 02540 * - IO errors (id 1) 02541 * - token mismatch (id 50, 51, 52, 80, 85) 02542 */ 02543 void ReadStateSet(TokenReader& rTr, const std::string& rLabel, StateSet& rStateSet) const; 02544 02545 02546 /** 02547 * Test whether file-i/o uses minimal state indicees. 02548 * 02549 * @return 02550 * True when minimal state indicees are enabled 02551 */ 02552 bool ReindexOnWrite(void) const; 02553 02554 /** 02555 * Enable/disable minimal state indicees for file-i/o. 02556 * 02557 * @param flag 02558 * True enables reindexing. 02559 */ 02560 void ReindexOnWrite(bool flag); 02561 02562 02563 /** 02564 * Enable/disable reindexing states for file-i/o. 02565 * 02566 * Set default value for re-indexing. Initially, the default 02567 * is set to "false". 02568 * 02569 * @param flag 02570 * True enables reindexing. 02571 */ 02572 static void ReindexOnWriteDefault(bool flag); 02573 02574 02575 /** 02576 * Enable/disable reindexing states for file-i/o. 02577 * 02578 * Set default value for re-indexing. 02579 * 02580 * @return 02581 * True for reindexing enabled. 02582 */ 02583 static bool ReindexOnWriteDefault(void); 02584 02585 02586 /** @} doxygen group */ 02587 02588 02589 /***************************************** 02590 ***************************************** 02591 ***************************************** 02592 *****************************************/ 02593 02594 /** @name Misc */ 02595 /** @{ doxygen group */ 02596 02597 /** 02598 * Return used events (executed in transitions) 02599 * 02600 * @return EventSet 02601 */ 02602 EventSet UsedEvents(void) const; 02603 02604 /** 02605 * Return unused events 02606 * 02607 * @return EventSet 02608 */ 02609 EventSet UnusedEvents(void) const; 02610 02611 /** 02612 * Set the alphabet to used events 02613 */ 02614 void MinimizeAlphabet(void); 02615 02616 /** 02617 * Return active event set at state x1 02618 * 02619 * @param x1 02620 * Index of x1 02621 * 02622 * @return EventSet 02623 */ 02624 EventSet ActiveEventSet(Idx x1) const; 02625 02626 /** 02627 * Return active transition set at state x1 02628 * 02629 * @param x1 02630 * Index of x1 02631 * 02632 * @return EventSet 02633 */ 02634 TransSet ActiveTransSet(Idx x1) const; 02635 02636 /** 02637 * Return the states covered by transitions 02638 * 02639 * @return StateSet 02640 */ 02641 StateSet TransRelStateSpace(void) const; 02642 02643 /** 02644 * Return the successor states of state x1 02645 * 02646 * @return StateSet 02647 */ 02648 StateSet TransRelStateSpace(Idx x1) const; 02649 02650 /** 02651 * Return the successor states of state x1 with event ev 02652 * 02653 * @return StateSet 02654 */ 02655 StateSet TransRelStateSpace(Idx x1, Idx ev) const; 02656 02657 /** 02658 * Check if generator is deterministic. 02659 * 02660 * We require the transition relation to be a partial function 02661 * and at most one initial state. 02662 * 02663 * Note: pre 2.19 libFAUDES also insisted in exactly one initial state. 02664 * 02665 * 02666 * @return 02667 * True if generator is deterministic 02668 */ 02669 bool IsDeterministic(void) const; 02670 02671 /** 02672 * Set minimal index map for file io of generator states 02673 * 02674 * This function is implemented as fake-const to allow for 02675 * const Write function. 02676 * 02677 */ 02678 void SetMinStateIndexMap(void) const; 02679 02680 /** 02681 * Clear minimal index map for 1:1 file io 02682 * 02683 */ 02684 void ClearMinStateIndexMap(void) const; 02685 02686 /** 02687 * Get state index as is it will be written to file. 02688 * 02689 * @param index 02690 * state index 02691 * @return 02692 * minimal index 02693 */ 02694 Idx MinStateIndex(Idx index) const; 02695 02696 02697 /** 02698 * Re-enumerate states. 02699 * 02700 * This method re-enumerates states such that the resulting 02701 * state set consist of consecutive indexes; i.e. Size()=MaxStateIndex(). 02702 * The current implementation sets up the minimal-state-index map used for 02703 * file i/o and applies it to the state set and the transition relation. 02704 * 02705 * Note: libFAUDES does not maintain consecutive state indices. 02706 * This was a design decision and it comes pros and cons. The method MinStateIndex() 02707 * was implemented to provide some limited support for the implementation of algorithms in a 02708 * consecutive state enumeration paradigm. However, mixing both paradigms most likely 02709 * involves an overall performace penalty. 02710 */ 02711 void MinStateIndex(void); 02712 02713 02714 /** 02715 * Get maximum state index used in this generator. 02716 * Returns 0 if no states at all. 02717 * @return 02718 * maximal index 02719 */ 02720 Idx MaxStateIndex(void) const; 02721 02722 02723 /** 02724 * Get state index translation map 02725 * 02726 * @return 02727 * minimal index map 02728 */ 02729 const std::map<Idx,Idx>& MinStateIndexMap(void) const; 02730 02731 02732 /** 02733 * Pretty printable event name for index (eg for debugging). 02734 * 02735 * @param index 02736 * Event index 02737 * 02738 * @return 02739 * std::string 02740 */ 02741 std::string EStr(Idx index) const; 02742 02743 /** 02744 * Return pretty printable state name for index (eg for debugging) 02745 * 02746 * @param index 02747 * State index 02748 * 02749 * @return 02750 * std::string 02751 */ 02752 std::string SStr(Idx index) const; 02753 02754 02755 /** 02756 * Return pretty printable transition (eg for debugging) 02757 * 02758 * @param rTrans 02759 * Transition 02760 * 02761 * @return 02762 * std::string 02763 */ 02764 std::string TStr(const Transition& rTrans) const; 02765 02766 02767 /** 02768 * Produce graphical representation of this generator. 02769 * This method calls the generator's DotWrite function and then processes the output 02770 * with the dot tool from graphiz package. If no output format is given, 02771 * try to guess from filename extension. See also ProcessDot(). 02772 * 02773 * @param rFileName 02774 * Name of output file 02775 * @param rOutFormat 02776 * Graphics file format, eg "png", "jpg", "svg" 02777 * @param rDotExec 02778 * path/name of executable 02779 * @exception Exception 02780 * - IO errors (id 2) 02781 * - error during systemcall for dot (id 3) 02782 */ 02783 void GraphWrite(const std::string& rFileName, const std::string& rOutFormat="", 02784 const std::string& rDotExec="dot") const; 02785 02786 /** 02787 * Order for sorting containers of generators 02788 */ 02789 bool operator < (const vGenerator& rOtherGen) const { 02790 return (mId < rOtherGen.mId); 02791 } 02792 02793 02794 /** @} doxygen group */ 02795 02796 02797 protected: 02798 02799 /** Name of generator */ 02800 std::string mMyName; 02801 02802 /** Number of generator */ 02803 Idx mId; 02804 02805 /** Number of generator objects */ 02806 static Idx msObjectCount; 02807 02808 /** State symbol table (local per Generator)*/ 02809 SymbolTable mStateSymbolTable; 02810 02811 /** Pointer to State symbol table */ 02812 SymbolTable* mpStateSymbolTable; 02813 02814 /** Pointer to Event symbol table */ 02815 SymbolTable* mpEventSymbolTable; 02816 02817 /** Automatic state names */ 02818 bool mStateNamesEnabled; 02819 02820 /** Default for automatic statenames */ 02821 static bool msStateNamesEnabledDefault; 02822 02823 /** Reindex states on file-i/o */ 02824 bool mReindexOnWrite; 02825 02826 /** Default for automatic statenames */ 02827 static bool msReindexOnWriteDefault; 02828 02829 /** Pointer to alphabet (actual type depends on attributes) */ 02830 EventSet* mpAlphabet; 02831 02832 /** Pointer to state set (actual type depends on attributes) */ 02833 StateSet* mpStates; 02834 02835 /** Pointer to ransition relation (actual type depends on attributes) */ 02836 TransSet* mpTransRel; 02837 02838 /** Pointer to lobal attribute (actual type depends on attributes) */ 02839 AttributeVoid* mpGlobalAttribute; 02840 02841 /** Pointer to alphabet prototype (incl. attribute type) */ 02842 const EventSet* pAlphabetPrototype; 02843 02844 /** Pointer to state set prototype (incl. attribute type) */ 02845 const StateSet* pStatesPrototype; 02846 02847 /** Pointer to transition relation prototype (incl. attribute type) */ 02848 const TransSet* pTransRelPrototype; 02849 02850 /** Pointer to global attribute prototype (configures global attribute type) */ 02851 const AttributeVoid* pGlobalPrototype; 02852 02853 /** Static default alphabet prototype (incl. attribute type) */ 02854 static const EventSet& AlphabetVoid(void); 02855 02856 /** Static default state set prototype (incl. attribute type) */ 02857 static const StateSet& StatesVoid(void); 02858 02859 /** Static default transition relation prototype (incl. attribute type) */ 02860 static const TransSet& TransRelVoid(void); 02861 02862 /** Static default global attribute prototype (configures global attribute type) */ 02863 static const AttributeVoid& GlobalVoid(void); 02864 02865 /** Initial states */ 02866 StateSet mInitStates; 02867 02868 /** Marked states */ 02869 StateSet mMarkedStates; 02870 02871 /** Map State indices to consecutive indices */ 02872 std::map<Idx,Idx> mMinStateIndexMap; 02873 02874 /** Allocate my heap members (attribute dependent types) */ 02875 virtual void NewCore(void); 02876 02877 /** Free my heap members (attribute dependent types) */ 02878 virtual void DeleteCore(void); 02879 02880 /** Callback for core update */ 02881 virtual void UpdateCore(void); 02882 02883 /** Configure attribute types */ 02884 void ConfigureAttributeTypes(const AttributeVoid* pNewGlobalPrototype, 02885 const StateSet* pNewStatesPrototype, const EventSet* pNewAlphabetPrototype, 02886 const TransSet* pNewTransRelPrototype); 02887 02888 /** 02889 * Read generator object from TokenReader, see Type::Read for public wrappers. 02890 * 02891 * Virtual function for std token io interface. Context is ignored, 02892 * label defaults to "Generator". 02893 * 02894 * @param rTr 02895 * TokenReader to read from 02896 * @param rLabel 02897 * Section to read 02898 * @param pContext 02899 * Read context to provide contextual information (ignored) 02900 * 02901 * @exception Exception 02902 * - token mismatch (id 50, 51, 52, 80, 85) 02903 * - IO error (id 1) 02904 */ 02905 virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0); 02906 02907 /** 02908 * Write generator to TokenWriter, see Type::Write for public wrappers. 02909 * 02910 * Virtual function for std token io interface. Context is ignored, 02911 * label defaults to "Generator". If the tokenwriter writes to a file, 02912 * state indices will be re-indext to start from 1. 02913 * 02914 * @param rTw 02915 * Reference to TokenWriter 02916 * @param rLabel 02917 * Label of section to write 02918 * @param pContext 02919 * Write context to provide contextual information (ignored) 02920 * 02921 * @exception Exception 02922 * - IO errors (id 2) 02923 */ 02924 virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const; 02925 02926 /** 02927 * Write generator in debugging format to TokenWriter, see Type::DWrite for public wrappers. 02928 * 02929 * Reimplement this method in derived classes to provide the std token io 02930 * interface defined in the public section of Type. 02931 * 02932 * @param rTw 02933 * Reference to TokenWriter 02934 * @param rLabel 02935 * Label of section to write 02936 * @param pContext 02937 * Write context to provide contextual information (ignored) 02938 * 02939 * @exception Exception 02940 * - IO errors (id 2) 02941 */ 02942 virtual void DoDWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const; 02943 02944 /** 02945 * Write generator statistics as comment to TokenWriter, see Type::SWrite for public wrappers. 02946 * 02947 * Reimplement this method in derived classes to provide the std token io 02948 * interface defined in the public section of Type. 02949 * 02950 * @param rTw 02951 * Reference to TokenWriter 02952 * 02953 * @exception Exception 02954 * - IO errors (id 2) 02955 */ 02956 virtual void DoSWrite(TokenWriter& rTw) const; 02957 02958 /** 02959 * Write generator to TokenWriter, see Type::XWrite for public wrappers. 02960 * 02961 * Virtual function for std token io interface. Context is ignored, 02962 * label defaults to "Generator". 02963 * 02964 * @param rTw 02965 * Reference to TokenWriter 02966 * @param rLabel 02967 * Label of section to write 02968 * @param pContext 02969 * Write context to provide contextual information (ignored) 02970 * 02971 * @exception Exception 02972 * - IO errors (id 2) 02973 */ 02974 virtual void DoXWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const; 02975 02976 /** 02977 * Read the generator's name from a file 02978 * 02979 * @param rFileName 02980 * File to read from 02981 * 02982 * @exception Exception 02983 * - IO errors (id 1) 02984 * - token mismatch (id 50, 51, 52) 02985 */ 02986 void ReadGeneratorName(const std::string& rFileName); 02987 02988 /** 02989 * Read the generator's name from a TokenReader 02990 * 02991 * @param rTr 02992 * Reference to TokenReader 02993 * 02994 * @exception Exception 02995 * - IO errors (id 1) 02996 * - token mismatch (id 50, 51, 52) 02997 */ 02998 void ReadGeneratorName(TokenReader& rTr); 02999 03000 /** 03001 * Read the generator's alphabet from a file. 03002 * 03003 * @param rFileName 03004 * File to read from 03005 * 03006 * @exception Exception 03007 * - IO errors (id 1) 03008 * - token mismatch (id 50, 51, 52) 03009 */ 03010 void ReadAlphabet(const std::string& rFileName); 03011 03012 /** 03013 * Read the generator's alphabet from a TokenReader 03014 * 03015 * @param rTr 03016 * Reference to TokenReader 03017 * 03018 * @exception Exception 03019 * - IO errors (id 1) 03020 * - token mismatch (id 50, 51, 52) 03021 */ 03022 void ReadAlphabet(TokenReader& rTr); 03023 03024 /** 03025 * Read the generator's state set from a file. 03026 * This sets up the StateSymbolTable. In contrast 03027 * to ReadStateSet(), this version will accept 03028 * explicit symbol table information. 03029 * 03030 * @param rFileName 03031 * File to read from 03032 * 03033 * @exception Exception 03034 * - IO errors (id 1) 03035 * - token mismatch (id 50, 51, 52) 03036 */ 03037 void ReadStates(const std::string& rFileName); 03038 03039 /** 03040 * Write generators stateset to TokenWriter. 03041 * 03042 * This method differs from the general purpos version 03043 * WriteStateSet(TokenWriter&, const StateSet&) in that it 03044 * can optionally write an explicit symbol table for state names. 03045 * This will happen whenever writing is done without re-indexing 03046 * states. 03047 * 03048 * @param rTw 03049 * Reference to TokenWriter 03050 * @param rStateSet 03051 * Reference to stateset 03052 * 03053 * @exception Exception 03054 * - IO errors (id 2) 03055 */ 03056 void WriteStates(TokenWriter& rTw) const; 03057 03058 /** 03059 * Read the generator's stateset from a TokenReader. 03060 * This sets up the StateSymbolTable 03061 * 03062 * @param rTr 03063 * Reference to TokenReader 03064 * 03065 * @exception Exception 03066 * - IO errors (id 1) 03067 * - token mismatch (id 50, 51, 52) 03068 */ 03069 void ReadStates(TokenReader& rTr); 03070 03071 /** 03072 * Read a stateset from TokenReader in XML format. 03073 * 03074 * This version for file IO supports the XML format introduced with libFAUDES 2.20. 03075 * Note that for Generators and derived classes, the native libFAUDES token 03076 * format is considered the default. To read XML fromated data, 03077 * use the XRead() interface. 03078 * 03079 * @param rTr 03080 * Reference to TokenReader 03081 * @param rStateSet 03082 * Reference to stateset 03083 * @param rLabel 03084 * Section name, defaults to name of set 03085 * 03086 * @exception Exception 03087 * - IO errors (id 1) 03088 * - token mismatch (id 50, 51, 52) 03089 */ 03090 void XReadStateSet(TokenReader& rTr, StateSet& rStateSet, const std::string& rLabel="") const; 03091 03092 /** 03093 * Read the generator's transition relation from a file. 03094 * 03095 * @param rFileName 03096 * File to read from 03097 * 03098 * @exception Exception 03099 * - IO errors (id 1) 03100 * - token mismatch (id 50, 51, 52) 03101 */ 03102 void ReadTransRel(const std::string& rFileName); 03103 03104 /** 03105 * Read the generator's transition relation from a TokenReader. 03106 * 03107 * @param rTr 03108 * Reference to TokenReader 03109 * 03110 * @exception Exception 03111 * - IO errors (id 1) 03112 * - token mismatch (id 50, 51, 52) 03113 */ 03114 void ReadTransRel(TokenReader& rTr); 03115 03116 /** 03117 * Read the generator's transition relation from a TokenReader. 03118 * 03119 * @param rTr 03120 * Reference to TokenReader 03121 * 03122 * @exception Exception 03123 * - IO errors (id 1) 03124 * - token mismatch (id 50, 51, 52) 03125 */ 03126 void XReadTransRel(TokenReader& rTr); 03127 03128 /** 03129 * Write a stateset to TokenWriter in XML format. 03130 * 03131 * This version for file IO supports the XML format introduced with libFAUDES 2.20. 03132 * Note that for Generators and derived classes, the native libFAUDES token 03133 * format is considered the default. To obtain XML fromated output of a Generator, 03134 * use the XWrite() interface. 03135 * 03136 * @param rTw 03137 * Reference to TokenWriter 03138 * @param rStateSet 03139 * Reference to stateset 03140 * @param rLabel 03141 * Section name, defaults to name of set 03142 * 03143 * @exception Exception 03144 * - IO errors (id 2) 03145 */ 03146 void XWriteStateSet(TokenWriter& rTw, const StateSet& rStateSet, const std::string& rLabel="") const; 03147 03148 /** 03149 * Write transition relation to tokenwriter in XML format. 03150 * 03151 * This version for file IO supports the XML format introduced with libFAUDES 2.20. 03152 * Note that for Generators and derived classes, the native libFAUDES token 03153 * format is considered the default. To obtain XML fromated output of a Generator, 03154 * use the XWrite() interface. 03155 * 03156 * 03157 * @param rTw 03158 * Reference to TokenWriter 03159 * 03160 * @exception Exception 03161 * - IO errors (id 2) 03162 */ 03163 void XWriteTransRel(TokenWriter& rTw) const; 03164 03165 03166 }; 03167 03168 /** 03169 * Plain generator, api typedef for generator with no attributes. 03170 * \ingroup GeneratorClasses 03171 */ 03172 typedef vGenerator Generator; 03173 03174 /** 03175 * Convenience typedef for vectors og generators 03176 * \ingroup GeneratorClasses 03177 */ 03178 typedef TBaseVector<Generator> GeneratorVector; 03179 03180 03181 /** 03182 * RTI wrapper function. See also vGenerator::IsAccessible(). 03183 * \ingroup GeneratorFunctions 03184 */ 03185 bool IsAccessible(const vGenerator& rGen); 03186 03187 /** 03188 * RTI wrapper function. See also vGenerator::IsCoaccessible(). 03189 * \ingroup GeneratorFunctions 03190 */ 03191 bool IsCoaccessible(const vGenerator& rGen); 03192 03193 /** 03194 * RTI wrapper function. See also vGenerator::IsTrim(). 03195 * \ingroup GeneratorFunctions 03196 */ 03197 bool IsTrim(const vGenerator& rGen); 03198 03199 /** 03200 * RTI wrapper function. See also vGenerator::IsOmegaTrim(). 03201 * \ingroup GeneratorFunctions 03202 */ 03203 bool IsOmegaTrim(const vGenerator& rGen); 03204 03205 /** 03206 * RTI wrapper function. See also vGenerator::IsComplete(). 03207 * \ingroup GeneratorFunctions 03208 */ 03209 bool IsComplete(const vGenerator& rGen); 03210 03211 /** 03212 * RTI wrapper function. See also vGenerator::IsDeterministic(). 03213 * \ingroup GeneratorFunctions 03214 */ 03215 bool IsDeterministic(const vGenerator& rGen); 03216 03217 03218 /** 03219 * RTI wrapper function. See also vGenerator::Accessible(). 03220 * \ingroup GeneratorFunctions 03221 */ 03222 void Accessible(vGenerator& rGen); 03223 03224 /** 03225 * RTI wrapper function. See also vGenerator::Accessible(). 03226 * \ingroup GeneratorFunctions 03227 */ 03228 void Accessible(const vGenerator& rGen, vGenerator& rRes); 03229 03230 /** 03231 * RTI wrapper function. See also vGenerator::Coaccessible(). 03232 * \ingroup GeneratorFunctions 03233 */ 03234 void Coaccessible(vGenerator& rGen); 03235 03236 /** 03237 * RTI wrapper function. See also vGenerator::Coaccessible(). 03238 * \ingroup GeneratorFunctions 03239 */ 03240 void Coaccessible(const vGenerator& rGen, vGenerator& rRes); 03241 03242 /** 03243 * RTI wrapper function. See also vGenerator::Complete(). 03244 * \ingroup GeneratorFunctions 03245 */ 03246 void Complete(vGenerator& rGen); 03247 03248 /** 03249 * RTI wrapper function. See also vGenerator::Complete(). 03250 * \ingroup GeneratorFunctions 03251 */ 03252 void Complete(const vGenerator& rGen, vGenerator& rRes); 03253 03254 /** 03255 * RTI wrapper function. See also vGenerator::Trim(). 03256 * \ingroup GeneratorFunctions 03257 */ 03258 void Trim(vGenerator& rGen); 03259 03260 /** 03261 * RTI wrapper function. See also vGenerator::Trim(). 03262 * \ingroup GeneratorFunctions 03263 */ 03264 void Trim(const vGenerator& rGen, vGenerator& rRes); 03265 03266 /** 03267 * RTI wrapper function. See also vGenerator::OmegaTrim(). 03268 * \ingroup GeneratorFunctions 03269 */ 03270 void OmegaTrim(vGenerator& rGen); 03271 03272 /** 03273 * RTI wrapper function. See also vGenerator::OmegaTrim(). 03274 * \ingroup GeneratorFunctions 03275 */ 03276 void OmegaTrim(const vGenerator& rGen, vGenerator& rRes); 03277 03278 /** 03279 * RTI wrapper function. 03280 * \ingroup GeneratorFunctions 03281 */ 03282 void MarkAllStates(vGenerator& rGen); 03283 03284 /** 03285 * RTI wrapper function. 03286 * \ingroup GeneratorFunctions 03287 */ 03288 void AlphabetExtract(const vGenerator& rGen, EventSet& rRes); 03289 03290 03291 /** 03292 * RTI convenience function. 03293 */ 03294 void SetIntersection(const vGenerator& rGenA, const vGenerator& rGenB, EventSet& rRes); 03295 03296 /** 03297 * RTI convenience function. 03298 */ 03299 void SetIntersection(const GeneratorVector& rGenVec, EventSet& rRes); 03300 03301 /** 03302 * RTI convenience function. 03303 */ 03304 void SetUnion(const vGenerator& rGenA, const vGenerator& rGenB, EventSet& rRes); 03305 03306 /** 03307 * RTI convenience function. 03308 */ 03309 void SetUnion(const GeneratorVector& rGenVec, EventSet& rRes); 03310 03311 /** 03312 * RTI convenience function. 03313 */ 03314 void SetDifference(const vGenerator& rGenA, const vGenerator& rGenB, EventSet& rRes); 03315 03316 03317 03318 03319 } // namespace faudes 03320 03321 /* 03322 03323 #define FAUDES_GENERATOR_DECLARATION(gtype,GlobalAttr,StateAttr,EventAttr,TransAttr) \ 03324 public: \ 03325 virtual void EventAttribute(Idx index, const EventAttr& rAttr); \ 03326 virtual void EventAttributes(const TaEventSet<EventAttr>& rEventSet); \ 03327 virtual const EventAttr& EventAttribute(Idx index) const; \ 03328 virtual const EventAttr& EventAttribute(const std::string& rName) const; \ 03329 virtual EventAttr* EventAttributep(Idx index); \ 03330 virtual EventAttr* EventAttributep(const std::string& rName); \ 03331 virtual void StateAttribute(Idx index, const StateAttr& rAttr); \ 03332 virtual const StateAttr& StateAttribute(Idx index) const; \ 03333 virtual StateAttr* StateAttributep(Idx index); \ 03334 virtual void TransAttribute(const Transition& rTrans, const TransAttr& rAttr); \ 03335 virtual const TransAttr& TransAttribute(const Transition& rTrans) const; \ 03336 virtual TransAttr* TransAttributep(const Transition& rTrans); \ 03337 virtual void GlobalAttribute(const GlobalAttr& rAttr); \ 03338 virtual void GlobalAttributeTry(const Type& rAttr); \ 03339 virtual const GlobalAttr& GlobalAttribute(void) const; \ 03340 virtual GlobalAttr* GlobalAttributep(void); 03341 03342 #define FAUDES_GENERATOR_IMPLEMENTATION(gtype,GlobalAttr,StateAttr,EventAttr,TransAttr) \ 03343 public: \ 03344 virtual void EventAttribute(Idx index, const EventAttr& rAttr); \ 03345 virtual void EventAttributes(const TaEventSet<EventAttr>& rEventSet); \ 03346 virtual const EventAttr& EventAttribute(Idx index) const; \ 03347 virtual const EventAttr& EventAttribute(const std::string& rName) const; \ 03348 virtual EventAttr* EventAttributep(Idx index); \ 03349 virtual EventAttr* EventAttributep(const std::string& rName); \ 03350 virtual void StateAttribute(Idx index, const StateAttr& rAttr); \ 03351 virtual const StateAttr& StateAttribute(Idx index) const; \ 03352 virtual StateAttr* StateAttributep(Idx index); \ 03353 virtual void TransAttribute(const Transition& rTrans, const TransAttr& rAttr); \ 03354 virtual const TransAttr& TransAttribute(const Transition& rTrans) const; \ 03355 virtual TransAttr* TransAttributep(const Transition& rTrans); \ 03356 virtual void GlobalAttribute(const GlobalAttr& rAttr); \ 03357 virtual void GlobalAttributeTry(const Type& rAttr); \ 03358 virtual const GlobalAttr& GlobalAttribute(void) const; \ 03359 virtual GlobalAttr* GlobalAttributep(void); 03360 03361 */ 03362 03363 03364 #endif 03365 |
libFAUDES 2.22k --- 2013.04.02 --- c++ source docu by doxygen