SourceForge Project Site
Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

FSMTransition.h

Go to the documentation of this file.
00001 #if !defined(AFX_FSMTRANSITION_H__0E355DD5_595A_429E_950B_03A7F175172E__INCLUDED_)
00002 #define AFX_FSMTRANSITION_H__0E355DD5_595A_429E_950B_03A7F175172E__INCLUDED_
00003 
00004 #if _MSC_VER > 1000
00005 #pragma once
00006 #endif // _MSC_VER > 1000
00007 
00008 /*
00009  * The Finite State Machine (FSM) Library
00010  * Copyright (C) 2002 Siemens C-LAB Paderborn
00011  * All rights reserved.
00012  *
00013  * This program is  free  software;  you can redistribute it and/or modify it
00014  * under the terms of the  GNU Lesser General Public License  as published by 
00015  * the  Free Software Foundation;  either version 2.1 of the License,  or (at 
00016  * your option) any later version.
00017  *
00018  * This  program  is  distributed in  the  hope that it will  be useful,  but
00019  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00020  * or  FITNESS FOR A  PARTICULAR PURPOSE.  See the  GNU Lesser General Public  
00021  * License for more details.
00022  *
00023  * You should  have received  a copy of the GNU Lesser General Public License
00024  * along with  this program;  if not, write to the  Free Software Foundation,
00025  * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
00026  */
00027 
00028 // $Log: FSMTransition.h,v $
00029 // Revision 1.3  2002/08/20 14:48:41  vofka
00030 // FiniteStateMachine-config.h removed from installing. Loading exported to the loader class. Saver introduced. Error codes exported to FSMErrorCodes.
00031 //
00032 // Revision 1.2  2002/07/22 17:21:00  vofka
00033 // SimpleTransition, PushTransition, PopTransition added, not implemented yet
00034 //
00035 // Revision 1.1  2002/06/28 11:10:36  vofka
00036 // first time on sourceforge.net cvs
00037 //
00038 // Revision 1.6  2002/06/20 12:22:10  bobka
00039 // LGPL license
00040 //
00041 // Revision 1.5  2002/05/03 23:21:57  bobka
00042 // Loader externalisiert, aber der alte ist noch drin.
00043 // Iterators for states und variables added.
00044 // some minor bugs fixed.
00045 //
00046 // Revision 1.4  2002/01/16 11:53:44  bobka
00047 // ???
00048 //
00049 // Revision 1.3  2001/11/28 15:42:00  bobka
00050 // a lot of changes
00051 //
00052 // Revision 1.2  2001/11/23 09:27:58  bobka
00053 // Load/Save funktioniert.
00054 // FSM* im Fileformat entfernt.
00055 // streams entfernt.
00056 // Laeuft unter Win32 und unter WinCE (WinCE_STL Modul auschecken)
00057 // static library unter WinCE funktioniert nicht, nur DLL.
00058 //
00059 // Revision 1.1  2001/11/15 10:37:32  bobka
00060 // initial checkin
00061 // not tested on linux!
00062 //
00063 
00064 // Base-Class
00065 #include "FSMObject.h"
00066 
00068 namespace FSM {
00069 
00070 // forward reference
00071 class CFiniteStateMachine;
00072 class CFSMAction;
00073 class CFSMCondition;
00074 
00075 typedef list< CFSMAction* > Action_List;
00076 typedef list< CFSMCondition* > Condition_List;
00077 
00081 class CFSMTransition :  public CFSMObject
00082 {
00083         public:
00084                 friend class CFSMState;
00085                 friend class CFiniteStateMachine;
00086 
00087                 // Actions
00088                 CFSMAction* AddAction(const char *className);
00090                 CFSMAction* GetAction(int index) const;
00091                 bool DeleteAction(CFSMAction *action);
00092 
00098                 Action_List::const_iterator GetActionsBegin() const;
00099 
00101                 Action_List::const_iterator GetActionsEnd() const;
00102                 
00103                 // Conditions
00104                 CFSMCondition* AddCondition(const char *className="TestVariable");
00106                 CFSMCondition* GetCondition(int index) const;
00107                 bool DeleteCondition(CFSMCondition *condition);
00108 
00114                 Condition_List::const_iterator GetConditionsBegin() const;
00115 
00117                 Condition_List::const_iterator GetConditionsEnd() const;
00118                 
00119                 // Get/Set
00120                 CFSMState*   GetFromState() const;        // get the FromState Attribute
00121                 const char * GetOnEvent() const;          // get the OnEvent Attribute
00122                 void SetOnEvent(const char* event="ANY"); // 
00123 
00124         protected:
00125 
00126                 // Set
00127                 void SetFromState(const char *stateName);
00128 
00130                 
00135                 virtual bool Check(bool &result, const char *event, void *a, void *b); 
00136                 
00141                 virtual bool Execute(const char* event, void *a, void *b);
00142                 
00147                 virtual bool Activate();
00148                 
00153                 virtual bool Deactivate();
00154 
00155                 CFSMTransition();
00156                 virtual ~CFSMTransition();
00157         private:
00158 
00159                 Action_List m_Actions;
00160                 Condition_List m_Conditions;
00161                 string m_FromState;
00162                 string m_ToState;
00163                 string m_Event;
00164 };
00165 
00169 class CFSMSimpleTransition :  public CFSMTransition
00170 {
00171         public:
00172                 friend class CFSMState;
00173                 friend class CFiniteStateMachine;
00174 
00175                 // Get/Set
00176                 CFSMState*   GetToState() const;          // get the ToState Attribute
00177                 void SetToState(const char *stateName);   // set the ToState attribute
00178 
00179                 virtual bool SetParameter(const char* paramName, const char* paramValue);
00180                 
00181         protected:
00182                 // Construction/Destruction
00183                 static CFSMObject *Create();
00184                 virtual void DeleteThis();
00185 
00186 
00188 
00192                 virtual bool SaveParameters(CFSMSaver* out) const;
00193                 
00198                 virtual bool Execute(const char* event, void *a, void *b);
00199                 
00200                 CFSMSimpleTransition();
00201                 virtual ~CFSMSimpleTransition();
00202         private:
00203 
00204                 string m_ToState;
00205 };
00206 
00210 class CFSMPushTransition :  public CFSMSimpleTransition
00211 {
00212         public:
00213                 friend class CFSMState;
00214                 friend class CFiniteStateMachine;
00215                 
00216         protected:
00217                 // Construction/Destruction
00218                 static CFSMObject *Create();
00219                 virtual void DeleteThis();
00220 
00221 
00223                 
00228                 virtual bool Execute(const char* event, void *a, void *b);
00229                 
00230                 CFSMPushTransition();
00231                 virtual ~CFSMPushTransition();
00232         private:
00233 
00234 };
00235 
00239 class CFSMPopTransition :  public CFSMTransition
00240 {
00241         public:
00242                 friend class CFSMState;
00243                 friend class CFiniteStateMachine;
00244                 
00245         protected:
00246                 // Construction/Destruction
00247                 static CFSMObject *Create();
00248                 virtual void DeleteThis();
00249 
00250 
00252                 
00257                 virtual bool Execute(const char* event, void *a, void *b);
00258                 
00259                 CFSMPopTransition();
00260                 virtual ~CFSMPopTransition();
00261         private:
00262 
00263 };
00264 
00265 }; // namespace FSM
00266 
00267 #endif // !defined(AFX_FSMTRANSITION_H__0E355DD5_595A_429E_950B_03A7F175172E__INCLUDED_)

© 2002 by C-LAB
generated by doxygen