1 /*=========================================================================
4 Module: $RCSfile: bbtkAtomicBlackBoxGetSetFunctor.h,v $
6 Date: $Date: 2008/07/23 11:46:10 $
7 Version: $Revision: 1.3 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
22 * \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.
26 * \class bbtk::AtomicBlackBoxGetFunctor
27 * \brief Abstract functor of the Get accessors of the inputs and outputs of a AtomicBlackBox
28 * \class bbtk::AtomicBlackBoxSetFunctor
29 * \brief Abstract functor of the Set accessors of the inputs and outputs of a AtomicBlackBox
30 * \class bbtk::AtomicBlackBoxTGetFunctor
31 * \brief Template for concrete functors of the Get accessors of the inputs and outputs of a AtomicBlackBox (inherits from bbtk::AtomicBlackBoxGetFunctor).
32 * \class bbtk::AtomicBlackBoxTSetFunctor
33 * \brief Template for concrete functors of the Set accessors of the inputs and outputs of a AtomicBlackBox (inherits from bbtk::AtomicBlackBoxSetFunctor).
36 #ifndef __bbtkAtomicBlackBoxGetSetFunctor_h__
37 #define __bbtkAtomicBlackBoxGetSetFunctor_h__
40 #include "bbtkMessageManager.h"
45 // Forward declaration
49 //===========================================================================
50 class BBTK_EXPORT AtomicBlackBoxGetFunctor
53 /// Default constructor
54 AtomicBlackBoxGetFunctor() {}
56 virtual ~AtomicBlackBoxGetFunctor() {}
57 /// Abstract method which applies the "Get" function of AtomicBlackBox o
58 virtual Data Get(AtomicBlackBox* o) = 0;
60 virtual TypeInfo GetTypeInfo() const = 0;
62 virtual std::string GetTypeName() const = 0;
64 virtual std::string GetHumanTypeName() const = 0;
66 virtual bool IsPointerType() const = 0;
69 //===========================================================================
72 //===========================================================================
73 class AtomicBlackBoxSetFunctor
76 /// Default constructor
77 AtomicBlackBoxSetFunctor() {}
79 virtual ~AtomicBlackBoxSetFunctor() {}
80 /// Abstract method which applies the "Set" function of AtomicBlackBox o
81 virtual void Set(AtomicBlackBox* o, const Data&) = 0;
83 virtual TypeInfo GetTypeInfo() const = 0;
85 virtual std::string GetTypeName() const = 0;
87 virtual std::string GetHumanTypeName() const = 0;
89 virtual bool IsPointerType() const = 0;
90 /// Abstract method which applies the "Set" function of AtomicBlackBox o
91 /// using brute force cast to the typed pointer required by the "Set" fun.
92 /// Only works if the param type of the "Set" function is a pointer
93 /// (see template specialization below).
94 /// !!! Use with care !!!
95 virtual void BruteForceSetPointer(AtomicBlackBox* o, void* p) = 0;
98 //===========================================================================
102 //===========================================================================
103 template <class UBB, class T, class TRETURN>
104 class AtomicBlackBoxTGetFunctor : public bbtk::AtomicBlackBoxGetFunctor
107 /// Type of pointer on a UBB::Get method
108 typedef TRETURN (UBB::*GetMethodPointerType)(void); //const
110 /// Construction with the pointer on the Get method
111 AtomicBlackBoxTGetFunctor(GetMethodPointerType g) :
114 bbtkDebugMessage("Data",9,"AtomicBlackBoxTGetFunctor<"<<
115 TypeName<UBB>()<<","<<
117 TypeName<TRETURN>()<<
118 ">::AtomicBlackBoxTGetFunctor()"<<std::endl);
121 /// Concrete application of the Get method of object o
122 Data Get(AtomicBlackBox* o)
124 bbtkDebugMessage("Data",9,"AtomicBlackBoxTGetFunctor<"<<
125 TypeName<UBB>()<<","<<
127 TypeName<TRETURN>()<<
128 ">::Get()"<<std::endl);
129 return (((UBB*)o)->*mGetMethodPointer)();
132 TypeInfo GetTypeInfo() const { return typeid(T); }
133 std::string GetTypeName() const { return TypeName<T>(); }
134 std::string GetHumanTypeName() const { return HumanTypeName<T>(); }
136 virtual bool IsPointerType() const
138 return boost::is_pointer<T>::value;
142 /// Pointer on the Get method
143 GetMethodPointerType mGetMethodPointer;
145 //===========================================================================
149 //===========================================================================
150 template <class UBB, class T, class TACCESS>
151 class AtomicBlackBoxTSetFunctor : public AtomicBlackBoxSetFunctor
154 /// Type of pointer on a UBB::Set method
155 typedef void (UBB::*SetMethodPointerType)(TACCESS);
157 /// Construction with the pointer on the Set method
158 AtomicBlackBoxTSetFunctor(SetMethodPointerType s) :
161 bbtkDebugMessage("Data",9,"AtomicBlackBoxTSetFunctor<"<<
162 TypeName<UBB>()<<","<<
164 TypeName<TACCESS>()<<
165 ">::AtomicBlackBoxTSetFunctor()"<<std::endl);
168 /// Concrete application of the Set method of object o
169 void Set(AtomicBlackBox* o, const Data& d)
171 bbtkDebugMessage("Data",9,"AtomicBlackBoxTSetfunctor<"<<
172 TypeName<UBB>()<<","<<
174 TypeName<TACCESS>()<<
175 ">::Set()"<<std::endl);
176 // (((UBB*)o)->*mSetMethodPointer)(*(T*)d);
177 // bbtkAssert( bbtkEqualTypes( d.type(), typeid(T) ) );
178 T t = d.unsafe_get<T>();
179 (((UBB*)o)->*mSetMethodPointer)(t);
180 // bbtkDebugMessage("Kernel",9,"SetOK"<<std::endl);
184 TypeInfo GetTypeInfo() const { return typeid(T); }
185 std::string GetTypeName() const { return TypeName<T>(); }
186 std::string GetHumanTypeName() const { return HumanTypeName<T>(); }
187 virtual bool IsPointerType() const { return false; }
188 virtual void BruteForceSetPointer(AtomicBlackBox* b, void* p)
190 bbtkInternalError("AtomicBlackBoxTSetFunctor<"
191 <<TypeName<UBB>()<<","
193 <<TypeName<TACCESS>()
194 <<">::BruteForceSetPointer("
196 <<" called whereas type '"
198 <<"' is not a pointer type");
201 /// Pointer on the Set method
202 SetMethodPointerType mSetMethodPointer;
204 //===========================================================================
208 //===========================================================================
209 /// Template specialization of AtomicBlackBoxTSetFunctor for pointer types
210 template <class UBB, class T, class TACCESS>
211 class AtomicBlackBoxTSetFunctor<UBB,T*,TACCESS*>
212 : public AtomicBlackBoxSetFunctor
215 /// Type of pointer on a UBB::Set method
216 typedef void (UBB::*SetMethodPointerType)(TACCESS*);
218 /// Construction with the pointer on the Set method
219 AtomicBlackBoxTSetFunctor(SetMethodPointerType s) :
222 bbtkDebugMessage("Data",9,"AtomicBlackBoxTSetFunctor<"<<
223 TypeName<UBB>()<<","<<
224 TypeName<T*>()<<","<<
225 TypeName<TACCESS*>()<<
226 ">::AtomicBlackBoxTSetFunctor()"<<std::endl);
229 /// Concrete application of the Set method of object o
230 void Set(AtomicBlackBox* o, const Data& d)
232 bbtkDebugMessage("Data",9,"AtomicBlackBoxTSetfunctor<"<<
233 TypeName<UBB>()<<","<<
234 TypeName<T*>()<<","<<
235 TypeName<TACCESS*>()<<
236 ">::Set()"<<std::endl);
238 (((UBB*)o)->*mSetMethodPointer)(d.unsafe_get<T*>());
243 TypeInfo GetTypeInfo() const { return typeid(T*); }
244 std::string GetTypeName() const { return TypeName<T*>(); }
245 std::string GetHumanTypeName() const { return HumanTypeName<T*>(); }
246 virtual bool IsPointerType() const { return true; }
249 virtual void BruteForceSetPointer(AtomicBlackBox* o, void* p)
251 bbtkDebugMessage("Data",9,"AtomicBlackBoxTSetFunctor<"
252 <<TypeName<UBB>()<<","
253 <<TypeName<T*>()<<","
254 <<TypeName<TACCESS*>()
255 <<">::BruteForceSetPointer() (pointer specialization)");
257 (((UBB*)o)->*mSetMethodPointer)((T*)p);
261 /// Pointer on the Set method
262 SetMethodPointerType mSetMethodPointer;
264 //===========================================================================