|
ceStateCoreImpl.h
Go to the documentation of this file.
00001 00002 /* --- Source License 00003 * Author : FX Programmer. 00004 * Contact : CorEngine@gmail.com 00005 * 00006 * Copyright (c) 2010 by FX Programmer. 00007 * 00008 * This source code is free software; you can redistribute it and/or modify it 00009 * under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation; either version 2.1 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This source code is distributed in the hope that it will be useful, but 00014 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00015 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00016 * License for more details. 00017 * 00018 * Redistribution and use in source and binary forms, with or without 00019 * modification, are permitted provided that the following conditions are met: 00020 * 1. The origin of this software must not be misrepresented; you must not 00021 * claim that you wrote the original software. If you use this software 00022 * in a product, an acknowledgement in the product documentation would be 00023 * appreciated but is not required. 00024 * 2. Altered source versions must be clearly marked as such, and must not 00025 * be misrepresented as being the original software. 00026 * 3. Redistributions of source code must retain the above copyright 00027 * notice, this list of conditions and the following disclaimer. 00028 * 00029 * You should have received a copy of the GNU Lesser General Public License 00030 * along with this source code; if not, write to the Free Software Foundation, 00031 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 00032 */ 00033 00039 #ifndef _CE_STATECORE_IMPL_H_ 00040 #define _CE_STATECORE_IMPL_H_ 0x1 00042 #ifndef __cplusplus 00043 #error ceStateCoreImpl.h requires C++ compilation (use a .cpp suffix) 00044 #endif 00045 00046 #if __GNUC__ >= 0x3 00047 #pragma GCC system_header 00048 #endif 00049 00050 #if _MSC_VER > 1000 00051 #pragma once 00052 #pragma warning(disable: 4100) 00053 #endif 00054 00055 #include "ceStateCore.h" 00056 00057 namespace ce { 00058 00059 // --- class IStateManagerImpl --- */ 00060 00061 // #define CE_WITHOUT_GLOBAL_STATE 0x1 00062 // #define CE_FSM_VERIFY 0x1 00063 00067 template <class T> 00068 class IStateManagerImpl 00069 { 00070 public: 00071 00072 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00073 IStateManagerImpl(void) 00074 { 00075 this -> pT = static_cast<T*>(this); 00076 00077 this -> pT -> State = CreateStateManager(); 00078 if (!this -> pT -> State) return; 00079 00080 }; 00081 00082 virtual ~IStateManagerImpl(void) 00083 { DestroyStateManager(&this -> pT -> State); }; 00084 #endif 00085 00086 // #ifdef CE_FSM_VERIFY 00091 inline const short APICALL 00092 VerifyStateManager(void) const 00093 { return (!this -> pT -> State) ? 0x0 : 0x1; }; 00094 // #endif 00095 00096 #ifndef CE_WITHOUT_GLOBAL_STATE 00097 // --- Global State --- */ 00103 inline void APICALL 00104 SetGlobalState(IState *State) const 00105 { this -> pT -> State -> SetGlobalState(State); }; 00106 00110 inline IState* APICALL 00111 GetGlobalState(void) const 00112 { return this -> pT -> State -> GetGlobalState(); }; 00113 // -------------------- */ 00114 #endif // CE_WITHOUT_GLOBAL_STATE 00115 00116 // --- Current State --- */ 00122 inline void APICALL 00123 SetCurrentState(IState *State) const 00124 { this -> pT -> State -> SetCurrentState(State); }; 00125 00129 inline IState* APICALL 00130 GetCurrentState(void) const 00131 { return this -> pT -> State -> GetCurrentState(); }; 00132 // --------------------- */ 00133 00134 // --- Previous State --- */ 00139 inline void APICALL 00140 SetPreviousState(IState *State) const 00141 { this -> pT -> State -> SetPreviousState(State); }; 00142 00146 inline IState* APICALL 00147 GetPreviousState(void) const 00148 { return this -> pT -> State -> GetPreviousState(); }; 00149 // ---------------------- */ 00150 00152 inline void APICALL 00153 Update(void) const 00154 { this -> pT -> State -> Update(); }; 00155 00160 inline void APICALL 00161 ChangeState(IState *State) const 00162 { this -> pT -> State -> ChangeState(State); }; 00163 00165 inline void APICALL 00166 RevertToPreviousState(void) const 00167 { this -> pT -> State -> RevertToPreviousState(); }; 00168 00175 inline short APICALL 00176 IsInState(const IState &State) const 00177 { return this -> pT -> State -> IsInState(State); }; 00178 00179 protected: 00180 00181 IStateManager *State; 00182 00183 private: 00184 00185 T *pT; 00186 00187 IStateManagerImpl(const IStateManagerImpl&); 00188 void operator=(const IStateManagerImpl&); 00189 00190 // DISALLOW_COPY_AND_ASSIGN(IStateManagerImpl); 00191 }; 00192 00193 // --- end class IStateManagerImpl --- */ 00194 00195 } // end namespace ce 00196 00197 #if _MSC_VER > 1000 00198 #pragma warning(default:4100) 00199 #endif 00200 00201 #endif // _CE_STATECORE_IMPL_H_ |
|