]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/creaButtonContainer/model/functor.h
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / creaButtonContainer / model / functor.h
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 /*!
27  * @file functor.h
28  * @brief Defines TFunctor class
29  * @author Diego CACERES (diego.caceres[AT]creatis.insa-lyon.fr)
30  * @date  2011-06-02
31  */
32
33 #ifndef TFUNCTOR_H_
34 #define TFUNCTOR_H_
35
36 #include <string>
37 #include <exception>
38
39 /*!     @namespace <creaButtonContainer>
40  *      @brief Contains the creaButtonContainer library included in creaMaracasVisu.
41  */
42 namespace creaButtonContainer
43 {
44         /*! @namespace <creaButtonContainer::model>
45          *      @brief Contains the implementation of the model in creaButtonContainer library.
46          *      @see <a href="http://en.wikipedia.org/wiki/Model-view-controller">MVC Software Architecture</a>
47          */
48         namespace model
49         {
50                 //typedef definition.
51                 /*!     @typedef std::string ButtonIDType;
52                  *      @brief Defines the ButtonIDType type.
53                  */
54                 typedef std::string ButtonIDType;
55                 //end of typedef definition
56                 /*! @class TFunctor functor.h "functor.h"
57                  *      @brief This is an abstract class for call_back functions.
58                  */
59                 class TFunctor
60                 {
61                         public:
62                                 // two possible functions to call member function. virtual cause derived
63                                 // classes will use a pointer to an object and a pointer to a member function
64                                 /*! @fn virtual void TFunctor::operator()( const ButtonIDType &buttonName )
65                                  *      @brief  To make the function call.
66                                  *      Call_Back function.
67                                  *      @param buttonName
68                                  */
69                                 virtual void
70                                 operator()( const ButtonIDType &buttonName )=0; // call using operator
71                                 /*! @fn
72                                  *  @brief Call using function.
73                                  *  Call_Back function.
74                                  *      @param buttonName
75                                  */
76                                 virtual void
77                                 Call( const ButtonIDType &buttonName )=0;
78                 };
79
80                 // derived template class
81                 /*! @tparam <typename TClass>
82                  *      @brief TClass makes TConcreteFunctor usable for all Classes.
83                  */
84                 template< typename TClass >
85                         /*! @class TConcreteFunctor: public TFunctor  functor.h "functor.h"
86                          *      @brief This class allows to make call_back functions.
87                          */
88                         class TConcreteFunctor : public TFunctor
89                         {
90                                 public:
91                                         /*! @fn TConcreteFunctor::TConcreteFunctor( TClass* _pt2Object, void
92                                          (TClass::*_fpt)( const ButtonIDType &buttonName ) );
93                                          *      @brief This is the parameterized constructor.
94                                          *      Takes pointer to an object and pointer to a member and stores them in two private variables
95                                          *      @param _pt2Object Pointer to object.
96                                          *      @param _fpt Pointer to the function.
97                                          *      @param buttonName The ID of the button (ButtonName).
98                                          */
99                                         TConcreteFunctor( TClass* _pt2Object, void
100                                         (TClass::*_fpt)( const ButtonIDType &buttonName ) );
101                                         // -------------------------------------------------------------------------------
102                                         /*! @fn virtual void TConcreteFunctor::operator()( const ButtonIDType &buttonName );
103                                          *      @brief Override operator "()". Execute member function.
104                                          *      @see TFunctor
105                                          *      @param buttonName
106                                          *      @exception std::bad_alloc
107                                          */
108                                         virtual void
109                                         operator()( const ButtonIDType &buttonName );
110                                         // -------------------------------------------------------------------------------
111                                         /*! @fn virtual void TConcreteFunctor::Call( const ButtonIDType &buttonName );
112                                          *      @brief Override function "Call". Execute member function
113                                          *      @see TFunctor
114                                          *      @param buttonName
115                                          *      @exception std::bad_alloc
116                                          */
117                                         virtual void
118                                         Call( const ButtonIDType &buttonName );
119                                         // -------------------------------------------------------------------------------
120                                 private:
121                                         void
122                                         (TClass::*fpt)( const ButtonIDType &buttonName ); //! <void (TClass::*fpt) Pointer to member function.
123                                         TClass* pt2Object; //! <TClass* pointer to object.
124                         };
125
126         }//ecapseman
127 }//ecapseman
128
129 //! @include "functor.txx"
130 #include "functor.txx"
131
132 #endif /* TFUNCTOR_H_ */