From 39ec3109c770be957604a5f209eb676799c571df Mon Sep 17 00:00:00 2001 From: smh Date: Tue, 20 Apr 2004 05:47:00 +0000 Subject: [PATCH] Code unification by template usage --- src/Event/SALOME_Event.hxx | 145 +++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) diff --git a/src/Event/SALOME_Event.hxx b/src/Event/SALOME_Event.hxx index 4bf593d53..bcd67378c 100644 --- a/src/Event/SALOME_Event.hxx +++ b/src/Event/SALOME_Event.hxx @@ -100,6 +100,150 @@ private: }; +// Template classes for member function +//------------------------------------- +template +class TMemFunEvent: public SALOME_Event{ +public: + typedef TRes TResult; + TResult myResult; + typedef TResult (TObject::* TAction)(); + TMemFunEvent(TObject* theObject, TAction theAction, + TResult theResult = TResult()): + myObject(theObject), + myAction(theAction), + myResult(theResult) + {} + virtual bool Execute(){ + myResult = (myObject->*myAction)(); + return true; + } +private: + TObject* myObject; + TAction myAction; +}; + + +template +class TVoidMemFunEvent: public SALOME_Event{ +public: + typedef void (TObject::* TAction)(); + TVoidMemFunEvent(TObject* theObject, TAction theAction): + myObject(theObject), + myAction(theAction) + {} + virtual bool Execute(){ + (myObject->*myAction)(); + return true; + } +private: + TObject* myObject; + TAction myAction; +}; + + +// Template for member function with one argument +//----------------------------------------------- +template +class TMemFun1ArgEvent: public SALOME_Event{ +public: + typedef TRes TResult; + TResult myResult; + typedef TResult (TObject::* TAction)(TArg); + TMemFun1ArgEvent(TObject* theObject, TAction theAction, TArg theArg, + TResult theResult = TResult()): + myObject(theObject), + myAction(theAction), + myResult(theResult), + myArg(theArg) + {} + virtual bool Execute(){ + myResult = (myObject->*myAction)(myArg); + return true; + } +private: + TObject* myObject; + TAction myAction; + TStoreArg myArg; +}; + + +template +class TVoidMemFun1ArgEvent: public SALOME_Event{ +public: + typedef void (TObject::* TAction)(TArg); + TVoidMemFun1ArgEvent(TObject* theObject, TAction theAction, TArg theArg): + myObject(theObject), + myAction(theAction), + myArg(theArg) + {} + virtual bool Execute(){ + (myObject->*myAction)(myArg); + return true; + } +private: + TObject* myObject; + TAction myAction; + TStoreArg myArg; +}; + + +// Template for member function with one argument +//----------------------------------------------- +template +class TMemFun2ArgEvent: public SALOME_Event{ +public: + typedef TRes TResult; + TResult myResult; + typedef TResult (TObject::* TAction)(TArg,TArg1); + TMemFun2ArgEvent(TObject* theObject, TAction theAction, + TArg theArg, TArg1 theArg1, + TResult theResult = TResult()): + myObject(theObject), + myAction(theAction), + myResult(theResult), + myArg(theArg), + myArg1(theArg1) + {} + virtual bool Execute(){ + myResult = (myObject->*myAction)(myArg,myArg1); + return true; + } +private: + TObject* myObject; + TAction myAction; + TStoreArg myArg; + TStoreArg1 myArg1; +}; + + +template +class TVoidMemFun2ArgEvent: public SALOME_Event{ +public: + typedef void (TObject::* TAction)(TArg,TArg1); + TVoidMemFun2ArgEvent(TObject* theObject, TAction theAction, TArg theArg, TArg1 theArg1): + myObject(theObject), + myAction(theAction), + myArg(theArg), + myArg1(theArg1) + {} + virtual bool Execute(){ + (myObject->*myAction)(myArg,myArg1); + return true; + } +private: + TObject* myObject; + TAction myAction; + TStoreArg myArg; + TStoreArg1 myArg1; +}; + + +// Template function for processing events with result returing template inline typename TEvent::TResult ProcessEvent(TEvent* theEvent){ theEvent->process(); typename TEvent::TResult aResult = theEvent->myResult; @@ -108,6 +252,7 @@ template inline typename TEvent::TResult ProcessEvent(TEvent* theE } +// Template function for processing events without result inline void ProcessVoidEvent(SALOME_Event* theEvent){ theEvent->process(); theEvent->release(); -- 2.39.2