t-suw****@users*****
t-suw****@users*****
2007年 9月 23日 (日) 23:48:09 JST
Index: AquaSKK/src/statemachine/GenericStateMachine.h diff -u AquaSKK/src/statemachine/GenericStateMachine.h:1.1.2.2 AquaSKK/src/statemachine/GenericStateMachine.h:1.1.2.3 --- AquaSKK/src/statemachine/GenericStateMachine.h:1.1.2.2 Sun Sep 16 09:21:45 2007 +++ AquaSKK/src/statemachine/GenericStateMachine.h Sun Sep 23 23:48:08 2007 @@ -74,8 +74,8 @@ const ParamType& Param() const { return param_; } void SetParam(const ParamType& arg) { param_ = arg; } - bool IsSystem() const { return signal_ < USER_EVENT; } - bool IsUser() const { return !IsSystem(); } + bool IsSystem() const { return signal_ < USER_EVENT; } + bool IsUser() const { return !IsSystem(); } static GenericEvent& Probe() { static GenericEvent evt(PROBE); return evt; } static GenericEvent& Entry() { static GenericEvent evt(ENTRY_EVENT); return evt; } @@ -229,13 +229,13 @@ // ====================================================================== // state machine // ====================================================================== - template <class StateContainer, template <typename Handler, typename Event> class Inspector = EmptyInspector> + template <typename StateContainer, template <typename Handler, typename Event> class Inspector = EmptyInspector> class GenericStateMachine { public: - typedef typename StateContainer::Handler Handler; - typedef typename StateContainer::Event Event; - typedef typename StateContainer::State State; - typedef typename StateContainer::Output Output; + typedef typename StateContainer::State State; + typedef typename StateContainer::Event Event; + typedef typename StateContainer::Handler Handler; + typedef typename StateContainer::Output Output; private: StateContainer container_; @@ -410,6 +410,8 @@ GenericStateMachine(const StateContainer& src) : container_(src), top_(&StateContainer::TopState), active_(0) {} ~GenericStateMachine() { + if(!container_.ExitOnDestruct()) return; + for(Handler tmp = active_; tmp != 0; tmp = getSuperState(tmp)) { exitAction(tmp); } @@ -464,6 +466,30 @@ }; // ====================================================================== + // base state container + // ====================================================================== + template <typename StateContainer, typename ParamType = int, typename ResultType = int> + struct BaseStateContainer { + typedef GenericState<StateContainer> State; + typedef GenericEvent<ParamType> Event; + typedef State (StateContainer::*Handler)(const Event&); + typedef ResultType Output; + + // derived class must define this method + virtual const Handler InitialState() const = 0; + + virtual bool ExitOnDestruct() const { return true; } + + virtual State TopState(const Event& event) { + switch(event) { + case INIT_EVENT: + return State::Initial(InitialState()); + } + return 0; + } + }; + + // ====================================================================== // state container traits // ====================================================================== template <typename T> @@ -475,27 +501,4 @@ }; } -// ====================================================================== -// helper macro -// ====================================================================== - -#define DECLARE_ImportantTypes(container, param, result) \ - typedef GenericState<container> State; \ - typedef GenericEvent<param> Event; \ - typedef State (container::*Handler)(const Event&); \ - typedef result Output; - -#define DECLARE_TopState(container, initial) \ - State TopState(const Event& event) { \ - switch(event) { \ - case INIT_EVENT: \ - return State::Initial(&container::initial); \ - } \ - return 0; \ - } - -#define DECLARE_StateContainer(container, param, result, initial) \ - DECLARE_ImportantTypes(container, param, result) \ - DECLARE_TopState(container, initial) - #endif // INC__GenericStateMachine__ Index: AquaSKK/src/statemachine/SKKEngine.h diff -u AquaSKK/src/statemachine/SKKEngine.h:1.1.2.1 AquaSKK/src/statemachine/SKKEngine.h:1.1.2.2 --- AquaSKK/src/statemachine/SKKEngine.h:1.1.2.1 Sun Sep 2 12:36:25 2007 +++ AquaSKK/src/statemachine/SKKEngine.h Sun Sep 23 23:48:08 2007 @@ -1,5 +1,5 @@ /* -*- C++ -*- - $Id: SKKEngine.h,v 1.1.2.1 2007/09/02 03:36:25 t-suwa Exp $ + $Id: SKKEngine.h,v 1.1.2.2 2007/09/23 14:48:08 t-suwa Exp $ MacOS X implementation of the SKK input method. @@ -42,9 +42,10 @@ DEFINE_State(LatinInput), DEFINE_State(Ascii), DEFINE_State(Jisx0208Latin), - DEFINE_State(PreConversion), + DEFINE_State(Compose), DEFINE_State(EntryInput), DEFINE_State(Japanese), + DEFINE_State(Okuri), DEFINE_State(Abbreviation), DEFINE_State(EntryCompletion), DEFINE_State(SelectCandidate), Index: AquaSKK/src/statemachine/SKKEnvironment.cpp diff -u AquaSKK/src/statemachine/SKKEnvironment.cpp:1.1.2.1 AquaSKK/src/statemachine/SKKEnvironment.cpp:1.1.2.2 --- AquaSKK/src/statemachine/SKKEnvironment.cpp:1.1.2.1 Sun Sep 2 12:36:25 2007 +++ AquaSKK/src/statemachine/SKKEnvironment.cpp Sun Sep 23 23:48:08 2007 @@ -33,10 +33,6 @@ delete controller_; } -const Output& SKKEnvironment::Result() const { - return controller_->Result(); -} - // ====================================================================== // level 1ï¼ããªå ¥å // ====================================================================== @@ -229,9 +225,9 @@ } // ====================================================================== -// level 1ï¼å¤æå +// level 1ï¼è¦åºãèªæ§ç¯ // ====================================================================== -State SKKEnvironment::PreConversion(const Event& event) { +State SKKEnvironment::Compose(const Event& event) { switch(event) { case SKK_ENTER: return controller_->HandleEnter(); @@ -268,7 +264,7 @@ } // ====================================================================== -// level 2 (sub of PreConversion)ï¼è¦åºãèªå ¥å +// level 2 (sub of Compose)ï¼è¦åºãèªå ¥å // ====================================================================== State SKKEnvironment::EntryInput(const Event& event) { const SKKEventParam& param = event.Param(); @@ -284,7 +280,7 @@ return controller_->HandleInput(param); } - return &SKKEnvironment::PreConversion; + return &SKKEnvironment::Compose; } // ====================================================================== @@ -301,6 +297,19 @@ } // ====================================================================== +// level 3 (sub of EntryInput)ï¼éã +// ====================================================================== +State SKKEnvironment::Okuri(const Event& event) { + switch(event) { + case ENTRY_EVENT: + controller_->ChangeState(SKK::OkuriInput); + return 0; + } + + return &SKKEnvironment::EntryInput; +} + +// ====================================================================== // level 3 (sub of EntryInput)ï¼çç¥è¡¨è¨ // ====================================================================== State SKKEnvironment::Abbreviation(const Event& event) { @@ -315,7 +324,7 @@ } // ====================================================================== -// level 2 (sub of PreConversion)ï¼è¦åºãèªè£å® +// level 2 (sub of Compose)ï¼è¦åºãèªè£å® // ====================================================================== State SKKEnvironment::EntryCompletion(const Event& event) { const SKKEventParam& param = event.Param(); @@ -332,7 +341,7 @@ (event == SKK_CHAR && (param.IsNextCandidate() || param.IsNextCompletion() || param.IsPrevCompletion()))) { - return &SKKEnvironment::PreConversion; + return &SKKEnvironment::Compose; } // è£å®ãã¼ä»¥å¤ãªãå±¥æ´ã«è»¢éãã Index: AquaSKK/src/statemachine/SKKEnvironment.h diff -u AquaSKK/src/statemachine/SKKEnvironment.h:1.1.2.1 AquaSKK/src/statemachine/SKKEnvironment.h:1.1.2.2 --- AquaSKK/src/statemachine/SKKEnvironment.h:1.1.2.1 Sun Sep 2 12:36:25 2007 +++ AquaSKK/src/statemachine/SKKEnvironment.h Sun Sep 23 23:48:08 2007 @@ -23,23 +23,20 @@ #include "GenericStateMachine.h" #include "SKKEventParam.h" -#include "SKKEventResult.h" using namespace statemachinecxx_sourceforge_jp; class SKKController; // å®è¡ç°å¢ -class SKKEnvironment { +class SKKEnvironment : public BaseStateContainer<SKKEnvironment, SKKEventParam> { SKKController* controller_; public: - DECLARE_StateContainer(SKKEnvironment, SKKEventParam, SKKEventResult, KanaInput); - SKKEnvironment(); ~SKKEnvironment(); - const Output& Result() const; + const Handler InitialState() const { return &SKKEnvironment::KanaInput; } // level 1 (initial state) State KanaInput(const Event& event); @@ -57,16 +54,17 @@ State Jisx0208Latin(const Event& event); // level 1 - State PreConversion(const Event& event); + State Compose(const Event& event); - // level 2 (sub of PreConversion) + // level 2 (sub of Compose) State EntryInput(const Event& event); // lelvel 3 (sub of EntryInput) State Japanese(const Event& event); + State Okuri(const Event& event); State Abbreviation(const Event& event); - // level 2 (sub of PreConversion) + // level 2 (sub of Compose) State EntryCompletion(const Event& event); // level 1 Index: AquaSKK/src/statemachine/SKKEventResult.cpp diff -u AquaSKK/src/statemachine/SKKEventResult.cpp:1.1.2.1 AquaSKK/src/statemachine/SKKEventResult.cpp:removed --- AquaSKK/src/statemachine/SKKEventResult.cpp:1.1.2.1 Sun Sep 2 12:36:25 2007 +++ AquaSKK/src/statemachine/SKKEventResult.cpp Sun Sep 23 23:48:09 2007 @@ -1,35 +0,0 @@ -/* -*- C++ -*- - MacOS X implementation of the SKK input method. - - Copyright (C) 2007 Tomotaka SUWA <t.suw****@mac*****> - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#include "SKKEventResult.h" - -SKKEventResult::SKKEventResult() : impl_(new SKKEventResultImpl()) {} - -SKKEventResult::SKKEventResult(const SKKEventResult&) : impl_(new SKKEventResultImpl()) {} - -void SKKEventResult::Update() { - impl_->Update(); -} - -bool SKKEventResult::EventIsHandled() const { - // const ã¡ã½ãããªã®ã§ããã¤ã³ã¿çµç±ã§å é¨å®è£ ã®ç¶æ ãæ´æ° - return impl_->TestAndReset(); - // ãã®å®è£ ã¯ãããããã®ã§ã代æ¿æ¡ãæ¤è¨ããã㨠-} Index: AquaSKK/src/statemachine/SKKEventResult.h diff -u AquaSKK/src/statemachine/SKKEventResult.h:1.1.2.1 AquaSKK/src/statemachine/SKKEventResult.h:removed --- AquaSKK/src/statemachine/SKKEventResult.h:1.1.2.1 Sun Sep 2 12:36:25 2007 +++ AquaSKK/src/statemachine/SKKEventResult.h Sun Sep 23 23:48:09 2007 @@ -1,64 +0,0 @@ -/* -*- C++ -*- - MacOS X implementation of the SKK input method. - - Copyright (C) 2007 Tomotaka SUWA <t.suw****@mac*****> - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#ifndef INC__SKKEventResult__ -#define INC__SKKEventResult__ - -#include <memory> - -// å é¨å®è£ -class SKKEventResultImpl { - bool handled_; - bool backup_; - -public: - SKKEventResultImpl() : handled_(false), backup_(false) {} - ~SKKEventResultImpl() {} - - void Update() { - handled_ = !backup_; - } - - // separate query from modifier ã®ååããã¶ã - bool TestAndReset() { - bool ret = handled_ == backup_; - - backup_ = handled_; - - return ret; - } -}; - -// å¦ççµæ -class SKKEventResult { - std::auto_ptr<SKKEventResultImpl> impl_; - -public: - SKKEventResult(); - SKKEventResult(const SKKEventResult& src); - - // ã¤ãã³ããå¦çããå ´åã¯å¼ã³åºã - void Update(); - - // ã¤ãã³ãã¯å¦çããããï¼ - bool EventIsHandled() const; -}; - -#endif