2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkAtomicBlackBoxGetSetFunctor.h,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.6 $
34 =========================================================================*/
39 * \brief Class bbtk::AtomicBlackBoxGetFunctor / Class bbtk::AtomicBlackBoxSetFunctor : abstract functors of the Get and Set accessors of the inputs and outputs of a AtomicBlackBox ; Concrete derivatives.
43 * \class bbtk::AtomicBlackBoxGetFunctor
44 * \brief Abstract functor of the Get accessors of the inputs and outputs of a AtomicBlackBox
45 * \class bbtk::AtomicBlackBoxSetFunctor
46 * \brief Abstract functor of the Set accessors of the inputs and outputs of a AtomicBlackBox
47 * \class bbtk::AtomicBlackBoxTGetFunctor
48 * \brief Template for concrete functors of the Get accessors of the inputs and outputs of a AtomicBlackBox (inherits from bbtk::AtomicBlackBoxGetFunctor).
49 * \class bbtk::AtomicBlackBoxTSetFunctor
50 * \brief Template for concrete functors of the Set accessors of the inputs and outputs of a AtomicBlackBox (inherits from bbtk::AtomicBlackBoxSetFunctor).
53 #ifndef __bbtkAtomicBlackBoxGetSetFunctor_h__
54 #define __bbtkAtomicBlackBoxGetSetFunctor_h__
57 #include "bbtkMessageManager.h"
62 // Forward declaration
66 //===========================================================================
67 class BBTK_EXPORT AtomicBlackBoxGetFunctor
70 /// Default constructor
71 AtomicBlackBoxGetFunctor() {}
73 virtual ~AtomicBlackBoxGetFunctor() {}
74 /// Abstract method which applies the "Get" function of AtomicBlackBox o
75 virtual Data Get(AtomicBlackBox* o) = 0;
77 virtual TypeInfo GetTypeInfo() const = 0;
79 virtual std::string GetTypeName() const = 0;
81 virtual std::string GetHumanTypeName() const = 0;
83 virtual bool IsPointerType() const = 0;
86 //===========================================================================
89 //===========================================================================
90 class AtomicBlackBoxSetFunctor
93 /// Default constructor
94 AtomicBlackBoxSetFunctor() {}
96 virtual ~AtomicBlackBoxSetFunctor() {}
97 /// Abstract method which applies the "Set" function of AtomicBlackBox o
98 virtual void Set(AtomicBlackBox* o, const Data&) = 0;
100 virtual TypeInfo GetTypeInfo() const = 0;
102 virtual std::string GetTypeName() const = 0;
104 virtual std::string GetHumanTypeName() const = 0;
106 virtual bool IsPointerType() const = 0;
107 /// Abstract method which applies the "Set" function of AtomicBlackBox o
108 /// using brute force cast to the typed pointer required by the "Set" fun.
109 /// Only works if the param type of the "Set" function is a pointer
110 /// (see template specialization below).
111 /// !!! Use with care !!!
112 virtual void BruteForceSetPointer(AtomicBlackBox* o, void* p) = 0;
115 //===========================================================================
119 //===========================================================================
120 template <class UBB, class T, class TRETURN>
121 class AtomicBlackBoxTGetFunctor : public bbtk::AtomicBlackBoxGetFunctor
124 /// Type of pointer on a UBB::Get method
125 typedef TRETURN (UBB::*GetMethodPointerType)(void); //const
127 /// Construction with the pointer on the Get method
128 AtomicBlackBoxTGetFunctor(GetMethodPointerType g) :
131 bbtkDebugMessage("data",9,"AtomicBlackBoxTGetFunctor<"<<
132 TypeName<UBB>()<<","<<
134 TypeName<TRETURN>()<<
135 ">::AtomicBlackBoxTGetFunctor()"<<std::endl);
138 /// Concrete application of the Get method of object o
139 Data Get(AtomicBlackBox* o)
141 bbtkDebugMessage("data",9,"AtomicBlackBoxTGetFunctor<"<<
142 TypeName<UBB>()<<","<<
144 TypeName<TRETURN>()<<
145 ">::Get()"<<std::endl);
146 return (((UBB*)o)->*mGetMethodPointer)();
149 TypeInfo GetTypeInfo() const { return typeid(T); }
150 std::string GetTypeName() const { return TypeName<T>(); }
151 std::string GetHumanTypeName() const { return HumanTypeName<T>(); }
153 virtual bool IsPointerType() const
155 return boost::is_pointer<T>::value;
159 /// Pointer on the Get method
160 GetMethodPointerType mGetMethodPointer;
162 //===========================================================================
166 //===========================================================================
167 template <class UBB, class T, class TACCESS>
168 class AtomicBlackBoxTSetFunctor : public AtomicBlackBoxSetFunctor
171 /// Type of pointer on a UBB::Set method
172 typedef void (UBB::*SetMethodPointerType)(TACCESS);
174 /// Construction with the pointer on the Set method
175 AtomicBlackBoxTSetFunctor(SetMethodPointerType s) :
178 bbtkDebugMessage("data",9,"AtomicBlackBoxTSetFunctor<"<<
179 TypeName<UBB>()<<","<<
181 TypeName<TACCESS>()<<
182 ">::AtomicBlackBoxTSetFunctor()"<<std::endl);
185 /// Concrete application of the Set method of object o
186 void Set(AtomicBlackBox* o, const Data& d)
188 bbtkDebugMessage("data",9,"AtomicBlackBoxTSetfunctor<"<<
189 TypeName<UBB>()<<","<<
191 TypeName<TACCESS>()<<
192 ">::Set()"<<std::endl);
193 // (((UBB*)o)->*mSetMethodPointer)(*(T*)d);
194 // bbtkAssert( bbtkEqualTypes( d.type(), typeid(T) ) );
195 T t = d.unsafe_get<T>();
196 (((UBB*)o)->*mSetMethodPointer)(t);
197 // bbtkDebugMessage("Kernel",9,"SetOK"<<std::endl);
201 TypeInfo GetTypeInfo() const { return typeid(T); }
202 std::string GetTypeName() const { return TypeName<T>(); }
203 std::string GetHumanTypeName() const { return HumanTypeName<T>(); }
204 virtual bool IsPointerType() const { return false; }
205 virtual void BruteForceSetPointer(AtomicBlackBox* b, void* p)
207 bbtkInternalError("AtomicBlackBoxTSetFunctor<"
208 <<TypeName<UBB>()<<","
210 <<TypeName<TACCESS>()
211 <<">::BruteForceSetPointer("
213 <<" called whereas type '"
215 <<"' is not a pointer type");
218 /// Pointer on the Set method
219 SetMethodPointerType mSetMethodPointer;
221 //===========================================================================
225 //===========================================================================
226 /// Template specialization of AtomicBlackBoxTSetFunctor for pointer types
227 template <class UBB, class T, class TACCESS>
228 class AtomicBlackBoxTSetFunctor<UBB,T*,TACCESS*>
229 : public AtomicBlackBoxSetFunctor
232 /// Type of pointer on a UBB::Set method
233 typedef void (UBB::*SetMethodPointerType)(TACCESS*);
235 /// Construction with the pointer on the Set method
236 AtomicBlackBoxTSetFunctor(SetMethodPointerType s) :
239 bbtkDebugMessage("data",9,"AtomicBlackBoxTSetFunctor<"<<
240 TypeName<UBB>()<<","<<
241 TypeName<T*>()<<","<<
242 TypeName<TACCESS*>()<<
243 ">::AtomicBlackBoxTSetFunctor()"<<std::endl);
246 /// Concrete application of the Set method of object o
247 void Set(AtomicBlackBox* o, const Data& d)
249 bbtkDebugMessage("data",9,"AtomicBlackBoxTSetfunctor<"<<
250 TypeName<UBB>()<<","<<
251 TypeName<T*>()<<","<<
252 TypeName<TACCESS*>()<<
253 ">::Set()"<<std::endl);
255 (((UBB*)o)->*mSetMethodPointer)(d.unsafe_get<T*>());
260 TypeInfo GetTypeInfo() const { return typeid(T*); }
261 std::string GetTypeName() const { return TypeName<T*>(); }
262 std::string GetHumanTypeName() const { return HumanTypeName<T*>(); }
263 virtual bool IsPointerType() const { return true; }
266 virtual void BruteForceSetPointer(AtomicBlackBox* o, void* p)
268 bbtkDebugMessage("data",9,"AtomicBlackBoxTSetFunctor<"
269 <<TypeName<UBB>()<<","
270 <<TypeName<T*>()<<","
271 <<TypeName<TACCESS*>()
272 <<">::BruteForceSetPointer() (pointer specialization)");
274 (((UBB*)o)->*mSetMethodPointer)((T*)p);
278 /// Pointer on the Set method
279 SetMethodPointerType mSetMethodPointer;
281 //===========================================================================