]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/creaButtonContainer/model/functor.h
fc0b7718d8a28ca9f884fb539c7636d68a182fcb
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / creaButtonContainer / model / functor.h
1 /*!
2  * @file functor.h
3  * @brief Defines TFunctor class
4  * @author Diego CACERES (diego.caceres[AT]creatis.insa-lyon.fr)
5  * @date  2011-06-02
6  */
7
8 #ifndef TFUNCTOR_H_
9 #define TFUNCTOR_H_
10
11 #include <string>
12 #include <exception>
13
14 /*!     @namespace <creaButtonContainer>
15  *      @brief Contains the creaButtonContainer library included in creaMaracasVisu.
16  */
17 namespace creaButtonContainer
18 {
19         /*! @namespace <creaButtonContainer::model>
20          *      @brief Contains the implementation of the model in creaButtonContainer library.
21          *      @see <a href="http://en.wikipedia.org/wiki/Model-view-controller">MVC Software Architecture</a>
22          */
23         namespace model
24         {
25                 //typedef definition.
26                 /*!     @typedef std::string ButtonIDType;
27                  *      @brief Defines the ButtonIDType type.
28                  */
29                 typedef std::string ButtonIDType;
30                 //end of typedef definition
31                 /*! @class TFunctor functor.h "functor.h"
32                  *      @brief This is an abstract class for call_back functions.
33                  */
34                 class TFunctor
35                 {
36                         public:
37                                 // two possible functions to call member function. virtual cause derived
38                                 // classes will use a pointer to an object and a pointer to a member function
39                                 /*! @fn virtual void TFunctor::operator()( const ButtonIDType &buttonName )
40                                  *      @brief  To make the function call.
41                                  *      Call_Back function.
42                                  *      @param buttonName
43                                  */
44                                 virtual void
45                                 operator()( const ButtonIDType &buttonName )=0; // call using operator
46                                 /*! @fn
47                                  *  @brief Call using function.
48                                  *  Call_Back function.
49                                  *      @param buttonName
50                                  */
51                                 virtual void
52                                 Call( const ButtonIDType &buttonName )=0;
53                 };
54
55                 // derived template class
56                 /*! @tparam <typename TClass>
57                  *      @brief TClass makes TConcreteFunctor usable for all Classes.
58                  */
59                 template< typename TClass >
60                         /*! @class TConcreteFunctor: public TFunctor  functor.h "functor.h"
61                          *      @brief This class allows to make call_back functions.
62                          */
63                         class TConcreteFunctor : public TFunctor
64                         {
65                                 public:
66                                         /*! @fn TConcreteFunctor::TConcreteFunctor( TClass* _pt2Object, void
67                                          (TClass::*_fpt)( const ButtonIDType &buttonName ) );
68                                          *      @brief This is the parameterized constructor.
69                                          *      Takes pointer to an object and pointer to a member and stores them in two private variables
70                                          *      @param _pt2Object Pointer to object.
71                                          *      @param _fpt Pointer to the function.
72                                          *      @param buttonName The ID of the button (ButtonName).
73                                          */
74                                         TConcreteFunctor( TClass* _pt2Object, void
75                                         (TClass::*_fpt)( const ButtonIDType &buttonName ) );
76                                         // -------------------------------------------------------------------------------
77                                         /*! @fn virtual void TConcreteFunctor::operator()( const ButtonIDType &buttonName );
78                                          *      @brief Override operator "()". Execute member function.
79                                          *      @see TFunctor
80                                          *      @param buttonName
81                                          *      @exception std::bad_alloc
82                                          */
83                                         virtual void
84                                         operator()( const ButtonIDType &buttonName );
85                                         // -------------------------------------------------------------------------------
86                                         /*! @fn virtual void TConcreteFunctor::Call( const ButtonIDType &buttonName );
87                                          *      @brief Override function "Call". Execute member function
88                                          *      @see TFunctor
89                                          *      @param buttonName
90                                          *      @exception std::bad_alloc
91                                          */
92                                         virtual void
93                                         Call( const ButtonIDType &buttonName );
94                                         // -------------------------------------------------------------------------------
95                                 private:
96                                         void
97                                         (TClass::*fpt)( const ButtonIDType &buttonName ); //! <void (TClass::*fpt) Pointer to member function.
98                                         TClass* pt2Object; //! <TClass* pointer to object.
99                         };
100
101         }//ecapseman
102 }//ecapseman
103
104 //! @include "functor.txx"
105 #include "functor.txx"
106
107 #endif /* TFUNCTOR_H_ */