1 /*=========================================================================
4 Module: $RCSfile: bbtkAtomicBlackBoxGetSetFunctor.h,v $
6 Date: $Date: 2008/04/24 10:11:27 $
7 Version: $Revision: 1.2 $
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() {}
55 /// Abstract method which applies the "Get" function of AtomicBlackBox o
56 virtual Data Get(AtomicBlackBox* o) = 0;
58 virtual TypeInfo GetTypeInfo() const = 0;
60 virtual std::string GetTypeName() const = 0;
62 virtual std::string GetHumanTypeName() const = 0;
64 virtual bool IsPointerType() const = 0;
67 //===========================================================================
70 //===========================================================================
71 class AtomicBlackBoxSetFunctor
74 /// Default constructor
75 AtomicBlackBoxSetFunctor() {}
76 /// Abstract method which applies the "Set" function of AtomicBlackBox o
77 virtual void Set(AtomicBlackBox* o, const Data&) = 0;
79 virtual TypeInfo GetTypeInfo() const = 0;
81 virtual std::string GetTypeName() const = 0;
83 virtual std::string GetHumanTypeName() const = 0;
85 virtual bool IsPointerType() const = 0;
86 /// Abstract method which applies the "Set" function of AtomicBlackBox o
87 /// using brute force cast to the typed pointer required by the "Set" fun.
88 /// Only works if the param type of the "Set" function is a pointer
89 /// (see template specialization below).
90 /// !!! Use with care !!!
91 virtual void BruteForceSetPointer(AtomicBlackBox* o, void* p) = 0;
94 //===========================================================================
98 //===========================================================================
99 template <class UBB, class T, class TRETURN>
100 class AtomicBlackBoxTGetFunctor : public bbtk::AtomicBlackBoxGetFunctor
103 /// Type of pointer on a UBB::Get method
104 typedef TRETURN (UBB::*GetMethodPointerType)(void); //const
106 /// Construction with the pointer on the Get method
107 AtomicBlackBoxTGetFunctor(GetMethodPointerType g) :
110 bbtkDebugMessage("Data",9,"AtomicBlackBoxTGetFunctor<"<<
111 TypeName<UBB>()<<","<<
113 TypeName<TRETURN>()<<
114 ">::AtomicBlackBoxTGetFunctor()"<<std::endl);
117 /// Concrete application of the Get method of object o
118 Data Get(AtomicBlackBox* o)
120 bbtkDebugMessage("Data",9,"AtomicBlackBoxTGetFunctor<"<<
121 TypeName<UBB>()<<","<<
123 TypeName<TRETURN>()<<
124 ">::Get()"<<std::endl);
125 return (((UBB*)o)->*mGetMethodPointer)();
128 TypeInfo GetTypeInfo() const { return typeid(T); }
129 std::string GetTypeName() const { return TypeName<T>(); }
130 std::string GetHumanTypeName() const { return HumanTypeName<T>(); }
132 virtual bool IsPointerType() const
134 return boost::is_pointer<T>::value;
138 /// Pointer on the Get method
139 GetMethodPointerType mGetMethodPointer;
141 //===========================================================================
145 //===========================================================================
146 template <class UBB, class T, class TACCESS>
147 class AtomicBlackBoxTSetFunctor : public AtomicBlackBoxSetFunctor
150 /// Type of pointer on a UBB::Set method
151 typedef void (UBB::*SetMethodPointerType)(TACCESS);
153 /// Construction with the pointer on the Set method
154 AtomicBlackBoxTSetFunctor(SetMethodPointerType s) :
157 bbtkDebugMessage("Data",9,"AtomicBlackBoxTSetFunctor<"<<
158 TypeName<UBB>()<<","<<
160 TypeName<TACCESS>()<<
161 ">::AtomicBlackBoxTSetFunctor()"<<std::endl);
164 /// Concrete application of the Set method of object o
165 void Set(AtomicBlackBox* o, const Data& d)
167 bbtkDebugMessage("Data",9,"AtomicBlackBoxTSetfunctor<"<<
168 TypeName<UBB>()<<","<<
170 TypeName<TACCESS>()<<
171 ">::Set()"<<std::endl);
172 // (((UBB*)o)->*mSetMethodPointer)(*(T*)d);
173 // bbtkAssert( bbtkEqualTypes( d.type(), typeid(T) ) );
174 T t = d.unsafe_get<T>();
175 (((UBB*)o)->*mSetMethodPointer)(t);
176 // bbtkDebugMessage("Kernel",9,"SetOK"<<std::endl);
180 TypeInfo GetTypeInfo() const { return typeid(T); }
181 std::string GetTypeName() const { return TypeName<T>(); }
182 std::string GetHumanTypeName() const { return HumanTypeName<T>(); }
183 virtual bool IsPointerType() const { return false; }
184 virtual void BruteForceSetPointer(AtomicBlackBox* b, void* p)
186 bbtkInternalError("AtomicBlackBoxTSetFunctor<"
187 <<TypeName<UBB>()<<","
189 <<TypeName<TACCESS>()
190 <<">::BruteForceSetPointer("
192 <<" called whereas type '"
194 <<"' is not a pointer type");
197 /// Pointer on the Set method
198 SetMethodPointerType mSetMethodPointer;
200 //===========================================================================
204 //===========================================================================
205 /// Template specialization of AtomicBlackBoxTSetFunctor for pointer types
206 template <class UBB, class T, class TACCESS>
207 class AtomicBlackBoxTSetFunctor<UBB,T*,TACCESS*>
208 : public AtomicBlackBoxSetFunctor
211 /// Type of pointer on a UBB::Set method
212 typedef void (UBB::*SetMethodPointerType)(TACCESS*);
214 /// Construction with the pointer on the Set method
215 AtomicBlackBoxTSetFunctor(SetMethodPointerType s) :
218 bbtkDebugMessage("Data",9,"AtomicBlackBoxTSetFunctor<"<<
219 TypeName<UBB>()<<","<<
220 TypeName<T*>()<<","<<
221 TypeName<TACCESS*>()<<
222 ">::AtomicBlackBoxTSetFunctor()"<<std::endl);
225 /// Concrete application of the Set method of object o
226 void Set(AtomicBlackBox* o, const Data& d)
228 bbtkDebugMessage("Data",9,"AtomicBlackBoxTSetfunctor<"<<
229 TypeName<UBB>()<<","<<
230 TypeName<T*>()<<","<<
231 TypeName<TACCESS*>()<<
232 ">::Set()"<<std::endl);
234 (((UBB*)o)->*mSetMethodPointer)(d.unsafe_get<T*>());
239 TypeInfo GetTypeInfo() const { return typeid(T*); }
240 std::string GetTypeName() const { return TypeName<T*>(); }
241 std::string GetHumanTypeName() const { return HumanTypeName<T*>(); }
242 virtual bool IsPointerType() const { return true; }
245 virtual void BruteForceSetPointer(AtomicBlackBox* o, void* p)
247 bbtkDebugMessage("Data",9,"AtomicBlackBoxTSetFunctor<"
248 <<TypeName<UBB>()<<","
249 <<TypeName<T*>()<<","
250 <<TypeName<TACCESS*>()
251 <<">::BruteForceSetPointer() (pointer specialization)");
253 (((UBB*)o)->*mSetMethodPointer)((T*)p);
257 /// Pointer on the Set method
258 SetMethodPointerType mSetMethodPointer;
260 //===========================================================================