pd_attributes.h

Go to the documentation of this file.
00001 /** @file pd_attributes.h  Attributes for pushdown automata */
00002 
00003 
00004 /* Pushdown plugin for FAU Discrete Event Systems Library (libfaudes)
00005 
00006    Copyright (C) 2013  Stefan Jacobi, Sven Schneider, Anne-Kathrin Hess
00007 
00008 */
00009 
00010 
00011 #ifndef FAUDES_PD_ATTRIBUTES_H
00012 #define FAUDES_PD_ATTRIBUTES_H
00013 
00014 #include "corefaudes.h"
00015 #include "pd_basics.h"
00016 #include "pd_merge.h"
00017 #include <utility>
00018 
00019 namespace faudes {
00020   
00021 /**
00022  * 
00023  * State attribute with substates. Merged substates should only needed to be accessed for debugging.
00024  *
00025  * @ingroup PushdownPlugin  
00026  *
00027  */
00028 
00029 class AttributePushdownState : public AttributeFlags {
00030 
00031 FAUDES_TYPE_DECLARATION(Void,AttributePushdownState,AttributeFlags)
00032 
00033  public:
00034 
00035   /** Constructor */
00036   AttributePushdownState(void) : AttributeFlags() { mpMerge = NULL; mDfaState = 0;};
00037   
00038   /** Destructor 
00039    * 
00040    * deletes mpMerge
00041    */
00042   ~AttributePushdownState();
00043   
00044   /** 
00045    * Test for default value (ie default flags)
00046    *
00047    * @return
00048    *  True for default value
00049    */
00050   virtual bool IsDefault(void) const {return AttributeFlags::IsDefault() && mpMerge == NULL;};
00051 
00052   /**
00053    * Sets the mpMerge parameter. Allocates memory for the pointer.
00054    * The reference given in the parameter will be copied into the new memory.
00055    * Current mpMerge will be deleted.
00056    * 
00057    * @param rMerge
00058    *    the merge parameter
00059    */
00060   void SetMerge(const MergeAbstract& rMerge);
00061   
00062   /**
00063    * Getter for Merge
00064    * 
00065    * @return
00066    *    mpMerge
00067    */
00068   const MergeAbstract* Merge() const { return mpMerge;}
00069   
00070   /**
00071    * Setter for DfaState
00072    * 
00073    * @return
00074    *    mDfaState
00075    */
00076   void DfaState(const Idx dfaState) { mDfaState = dfaState;}
00077   
00078   /**
00079    * Getter for DfaState
00080    * 
00081    * @return
00082    *    mDfaState
00083    */
00084   const Idx DfaState() const { return mDfaState;}
00085   
00086   private:
00087     
00088   /** Substates  */
00089   MergeAbstract* mpMerge;
00090   /** Associated DFA state */
00091   Idx mDfaState;
00092  
00093  protected:
00094 
00095 
00096   /**
00097    * Assignment method. 
00098    *
00099    * @param rSrcAttr
00100    *    Source to assign from
00101    */
00102   void DoAssign(const AttributePushdownState& rSrcAttr);
00103 
00104 
00105   /**
00106    * Test equality. 
00107    *
00108    * @param rOther
00109    *    Other attribute to compare with.
00110    */
00111   bool DoEqual(const AttributePushdownState& rOther) const;
00112 
00113   /**
00114    * Reads the attribute from TokenReader, see AttributeVoid for public wrappers.
00115    * 
00116    * If the current token indicates a invariant section, the method reads the invariant
00117    * from that section. Else, it does nothing. Exceptions may only be thrown
00118    * on invalid data within the timing section. The context argument is ignored, the
00119    * label argument can be used to override the default section name Invariant.
00120    *
00121    * @param rTr
00122    *   TokenReader to read from
00123    * @param rLabel
00124    *   Section to read
00125    * @param pContext
00126    *   Read context to provide contextual information
00127    *
00128    * @exception Exception
00129    *   - IO error (id 1)
00130    */
00131   virtual void DoRead(TokenReader& rTr, const std::string& rLabel="", const Type* pContext=0);
00132  
00133   /**
00134    * Writes the attribute to TokenWriter, see AttributeVoid for public wrappers.
00135    *
00136    * Writes am Invariant section to include data on the invariant. The label argument
00137    * can be used to set a section label different the the default Invariant. 
00138    * Th context argument is ignored.  
00139    *
00140    * @param rTw
00141    *   TokenWriter to write to
00142    * @param rLabel
00143    *   Section to write
00144    * @param pContext
00145    *   Write context to provide contextual information
00146    *
00147    * @exception Exception
00148    *   - IO error (id 2)
00149    */
00150   virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="", const Type* pContext=0) const;
00151   
00152   virtual void DoXWrite(TokenWriter& rTw, const std::string& rLabel="", const Type* pContext=0) const {DoWrite(rTw,rLabel,pContext); };
00153 
00154 }; // class AttributePushdownState
00155 
00156   
00157 /**
00158  *
00159  * Transition attribute with pop and push.
00160  *
00161  * @ingroup PushdownPlugin  
00162  *
00163  */
00164 typedef  std::set<std::pair<std::vector<Idx>,std::vector<Idx> > > PopPushSet;
00165 
00166 class AttributePushdownTransition : public AttributeVoid {
00167 
00168 FAUDES_TYPE_DECLARATION(Void,AttributePushdownTransition,AttributeVoid)
00169 
00170  public:
00171 
00172   /** Constructor */
00173   AttributePushdownTransition(void) : AttributeVoid() { };
00174 
00175   /** 
00176    * Test for default value (ie default flags)
00177    *
00178    * @return
00179    *  True for default value
00180    */
00181   virtual bool  IsDefault(void) const {
00182      return mPopPush.empty();
00183   }; 
00184   
00185   /** Pop and Push. To allow transitions with the same start state, event and event state, but with different pop and push, pop and push are stored in a vector of pop/push pairs. */
00186   PopPushSet mPopPush;
00187   
00188   /**
00189    * Getter for PopPush
00190    * 
00191    * @return
00192    *    mPopPush
00193    */
00194   const PopPushSet& PopPush() const { return mPopPush;}
00195   
00196   /**
00197    * Delete a pop push pair from the the transitions
00198    * 
00199    * @param rPop
00200    *    the pop part of the pair to delete
00201    * * @param rPush
00202    *    the push part of the pair to delete
00203    * @return
00204    *    true if pair did exist and deletion was successful, else false
00205    */
00206   bool ClrPopPush(const std::vector<Idx>& rPop, const std::vector<Idx>& rPush);
00207   
00208  protected:
00209 
00210   /**
00211    * Assignment method. 
00212    *
00213    * @param rSrcAttr
00214    *    Source to assign from
00215    */
00216   void DoAssign(const AttributePushdownTransition& rSrcAttr);
00217 
00218   /**
00219    * Test equality. 
00220    *
00221    * @param rOther
00222    *    Other attribute to compare with.
00223    */
00224   bool DoEqual(const AttributePushdownTransition& rOther) const;
00225 
00226   /**
00227    * Reads the attribute from TokenReader, see AttributeVoid for public wrappers.
00228    * 
00229    * If the current token indicates a timing section, the method reads the guard and reset 
00230    * timing data from that section. Else it does nothing. Exceptions may only be thrown
00231    * on invalid data within the timing section. The context argument is ignored, the
00232    * label argument can be used to override the default section name Timing.
00233    *
00234    * @param rTr
00235    *   TokenReader to read from
00236    * @param rLabel
00237    *   Section to read
00238    * @param pContext
00239    *   Read context to provide contextual information
00240    *
00241    * @exception Exception
00242    *   - IO error (id 1)
00243    */
00244   virtual void DoRead(TokenReader& rTr,const std::string& rLabel="", const Type* pContext=0);
00245  
00246   /**
00247    * Writes the attribute to TokenWriter, see AttributeVoid for public wrappers.
00248    *
00249    * Writes a Timing section to include data on the guard and resets. The label argument
00250    * can be used to set a section label different the the default Timing. 
00251    * Th context argument is ignored.  
00252    *
00253    * @param rTw
00254    *   TokenWriter to write to
00255    * @param rLabel
00256    *   Section to write
00257    * @param pContext
00258    *   Write context to provide contextual information
00259    *
00260    * @exception Exception
00261    *   - IO error (id 2)
00262    */
00263   virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="", const Type* pContext=0) const;
00264 
00265   virtual void DoXWrite(TokenWriter& rTw, const std::string& rLabel="", const Type* pContext=0) const {DoWrite(rTw,rLabel,pContext); };
00266 
00267 
00268 
00269 }; // class AttributePushdownTransition
00270 
00271 /**
00272  *
00273  * Global attribute with stack alphabet and stack bottom.
00274  *
00275  * @ingroup PushdownPlugin  
00276  *
00277  */
00278 
00279 class AttributePushdownGlobal : public AttributeVoid {
00280 
00281 FAUDES_TYPE_DECLARATION(Void,AttributePushdownGlobal,AttributeVoid)
00282 
00283  public:
00284 
00285   /** Constructor */
00286   AttributePushdownGlobal(void) {
00287     mpStackSymbolTable=mStackSymbols.SymbolTablep();};
00288 
00289   /** 
00290    * Test for default value (no stack symbols)
00291    *
00292    * @return
00293    *  True for default value
00294    */
00295   virtual bool IsDefault(void) const {return mStackSymbols.Empty(); };
00296 
00297   /** Stack Symbols */
00298     StackSymbolSet mStackSymbols;
00299     Idx mStackBottom;
00300 
00301   /** Pointer to stack symbol table */
00302     SymbolTable* mpStackSymbolTable;
00303 
00304  protected:
00305 
00306   /**
00307    * Assignment method. 
00308    *
00309    * @param rSrcAttr
00310    *    Source to assign from
00311    */
00312   void DoAssign(const AttributePushdownGlobal& rSrcAttr);
00313 
00314   /**
00315    * Test equality. 
00316    *
00317    * @param rOther
00318    *    Other attribute to compare with.
00319    */
00320   bool DoEqual(const AttributePushdownGlobal& rOther) const;
00321 
00322   /**
00323    * Reads the attribute from TokenReader, see AttributeVoid for public wrappers.
00324    * 
00325    * If the current token indicates a Clocks section, the method reads the global
00326    * timing data from that section. Else, it does nothing. Exceptions may only be thrown
00327    * on invalid data within the timing section. The context argument is ignored, the
00328    * label argument can be used to override the default section name Clocks.
00329    *
00330    * @param rTr
00331    *   TokenReader to read from
00332    * @param rLabel
00333    *   Section to read
00334    * @param pContext
00335    *   Read context to provide contextual information
00336    *
00337    * @exception Exception
00338    *   - IO error (id 1)
00339    */
00340   virtual void DoRead(TokenReader& rTr,const std::string& rLabel="", const Type* pContext=0);
00341  
00342   /**
00343    * Writes the attribute to TokenWriter, see AttributeVoid for public wrappers.
00344    *
00345    * Writes a Clocks section to include global timing data. The label argument
00346    * can be used to set a section label different the the default Clocks. 
00347    * Th context argument is ignored.  
00348    *
00349    * @param rTw
00350    *   TokenWriter to write to
00351    * @param rLabel
00352    *   Section to write
00353    * @param pContext
00354    *   Write context to provide contextual information
00355    *
00356    * @exception Exception
00357    *   - IO error (id 2)
00358    */
00359   virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="", const Type* pContext=0) const;
00360   
00361   virtual void DoXWrite(TokenWriter& rTw, const std::string& rLabel="", const Type* pContext=0) const {DoWrite(rTw,rLabel,pContext); };
00362 
00363 };
00364 
00365 
00366 
00367 
00368 
00369 } // namespace faudes
00370 
00371 #endif

libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen