1 /*=========================================================================
3 Module: $RCSfile: bbtkAtomicBlackBoxGetSetFunctor.h,v $
5 Date: $Date: 2008/11/25 11:17:13 $
6 Version: $Revision: 1.5 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
34 * \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.
38 * \class bbtk::AtomicBlackBoxGetFunctor
39 * \brief Abstract functor of the Get accessors of the inputs and outputs of a AtomicBlackBox
40 * \class bbtk::AtomicBlackBoxSetFunctor
41 * \brief Abstract functor of the Set accessors of the inputs and outputs of a AtomicBlackBox
42 * \class bbtk::AtomicBlackBoxTGetFunctor
43 * \brief Template for concrete functors of the Get accessors of the inputs and outputs of a AtomicBlackBox (inherits from bbtk::AtomicBlackBoxGetFunctor).
44 * \class bbtk::AtomicBlackBoxTSetFunctor
45 * \brief Template for concrete functors of the Set accessors of the inputs and outputs of a AtomicBlackBox (inherits from bbtk::AtomicBlackBoxSetFunctor).
48 #ifndef __bbtkAtomicBlackBoxGetSetFunctor_h__
49 #define __bbtkAtomicBlackBoxGetSetFunctor_h__
52 #include "bbtkMessageManager.h"
57 // Forward declaration
61 //===========================================================================
62 class BBTK_EXPORT AtomicBlackBoxGetFunctor
65 /// Default constructor
66 AtomicBlackBoxGetFunctor() {}
68 virtual ~AtomicBlackBoxGetFunctor() {}
69 /// Abstract method which applies the "Get" function of AtomicBlackBox o
70 virtual Data Get(AtomicBlackBox* o) = 0;
72 virtual TypeInfo GetTypeInfo() const = 0;
74 virtual std::string GetTypeName() const = 0;
76 virtual std::string GetHumanTypeName() const = 0;
78 virtual bool IsPointerType() const = 0;
81 //===========================================================================
84 //===========================================================================
85 class AtomicBlackBoxSetFunctor
88 /// Default constructor
89 AtomicBlackBoxSetFunctor() {}
91 virtual ~AtomicBlackBoxSetFunctor() {}
92 /// Abstract method which applies the "Set" function of AtomicBlackBox o
93 virtual void Set(AtomicBlackBox* o, const Data&) = 0;
95 virtual TypeInfo GetTypeInfo() const = 0;
97 virtual std::string GetTypeName() const = 0;
99 virtual std::string GetHumanTypeName() const = 0;
101 virtual bool IsPointerType() const = 0;
102 /// Abstract method which applies the "Set" function of AtomicBlackBox o
103 /// using brute force cast to the typed pointer required by the "Set" fun.
104 /// Only works if the param type of the "Set" function is a pointer
105 /// (see template specialization below).
106 /// !!! Use with care !!!
107 virtual void BruteForceSetPointer(AtomicBlackBox* o, void* p) = 0;
110 //===========================================================================
114 //===========================================================================
115 template <class UBB, class T, class TRETURN>
116 class AtomicBlackBoxTGetFunctor : public bbtk::AtomicBlackBoxGetFunctor
119 /// Type of pointer on a UBB::Get method
120 typedef TRETURN (UBB::*GetMethodPointerType)(void); //const
122 /// Construction with the pointer on the Get method
123 AtomicBlackBoxTGetFunctor(GetMethodPointerType g) :
126 bbtkDebugMessage("data",9,"AtomicBlackBoxTGetFunctor<"<<
127 TypeName<UBB>()<<","<<
129 TypeName<TRETURN>()<<
130 ">::AtomicBlackBoxTGetFunctor()"<<std::endl);
133 /// Concrete application of the Get method of object o
134 Data Get(AtomicBlackBox* o)
136 bbtkDebugMessage("data",9,"AtomicBlackBoxTGetFunctor<"<<
137 TypeName<UBB>()<<","<<
139 TypeName<TRETURN>()<<
140 ">::Get()"<<std::endl);
141 return (((UBB*)o)->*mGetMethodPointer)();
144 TypeInfo GetTypeInfo() const { return typeid(T); }
145 std::string GetTypeName() const { return TypeName<T>(); }
146 std::string GetHumanTypeName() const { return HumanTypeName<T>(); }
148 virtual bool IsPointerType() const
150 return boost::is_pointer<T>::value;
154 /// Pointer on the Get method
155 GetMethodPointerType mGetMethodPointer;
157 //===========================================================================
161 //===========================================================================
162 template <class UBB, class T, class TACCESS>
163 class AtomicBlackBoxTSetFunctor : public AtomicBlackBoxSetFunctor
166 /// Type of pointer on a UBB::Set method
167 typedef void (UBB::*SetMethodPointerType)(TACCESS);
169 /// Construction with the pointer on the Set method
170 AtomicBlackBoxTSetFunctor(SetMethodPointerType s) :
173 bbtkDebugMessage("data",9,"AtomicBlackBoxTSetFunctor<"<<
174 TypeName<UBB>()<<","<<
176 TypeName<TACCESS>()<<
177 ">::AtomicBlackBoxTSetFunctor()"<<std::endl);
180 /// Concrete application of the Set method of object o
181 void Set(AtomicBlackBox* o, const Data& d)
183 bbtkDebugMessage("data",9,"AtomicBlackBoxTSetfunctor<"<<
184 TypeName<UBB>()<<","<<
186 TypeName<TACCESS>()<<
187 ">::Set()"<<std::endl);
188 // (((UBB*)o)->*mSetMethodPointer)(*(T*)d);
189 // bbtkAssert( bbtkEqualTypes( d.type(), typeid(T) ) );
190 T t = d.unsafe_get<T>();
191 (((UBB*)o)->*mSetMethodPointer)(t);
192 // bbtkDebugMessage("Kernel",9,"SetOK"<<std::endl);
196 TypeInfo GetTypeInfo() const { return typeid(T); }
197 std::string GetTypeName() const { return TypeName<T>(); }
198 std::string GetHumanTypeName() const { return HumanTypeName<T>(); }
199 virtual bool IsPointerType() const { return false; }
200 virtual void BruteForceSetPointer(AtomicBlackBox* b, void* p)
202 bbtkInternalError("AtomicBlackBoxTSetFunctor<"
203 <<TypeName<UBB>()<<","
205 <<TypeName<TACCESS>()
206 <<">::BruteForceSetPointer("
208 <<" called whereas type '"
210 <<"' is not a pointer type");
213 /// Pointer on the Set method
214 SetMethodPointerType mSetMethodPointer;
216 //===========================================================================
220 //===========================================================================
221 /// Template specialization of AtomicBlackBoxTSetFunctor for pointer types
222 template <class UBB, class T, class TACCESS>
223 class AtomicBlackBoxTSetFunctor<UBB,T*,TACCESS*>
224 : public AtomicBlackBoxSetFunctor
227 /// Type of pointer on a UBB::Set method
228 typedef void (UBB::*SetMethodPointerType)(TACCESS*);
230 /// Construction with the pointer on the Set method
231 AtomicBlackBoxTSetFunctor(SetMethodPointerType s) :
234 bbtkDebugMessage("data",9,"AtomicBlackBoxTSetFunctor<"<<
235 TypeName<UBB>()<<","<<
236 TypeName<T*>()<<","<<
237 TypeName<TACCESS*>()<<
238 ">::AtomicBlackBoxTSetFunctor()"<<std::endl);
241 /// Concrete application of the Set method of object o
242 void Set(AtomicBlackBox* o, const Data& d)
244 bbtkDebugMessage("data",9,"AtomicBlackBoxTSetfunctor<"<<
245 TypeName<UBB>()<<","<<
246 TypeName<T*>()<<","<<
247 TypeName<TACCESS*>()<<
248 ">::Set()"<<std::endl);
250 (((UBB*)o)->*mSetMethodPointer)(d.unsafe_get<T*>());
255 TypeInfo GetTypeInfo() const { return typeid(T*); }
256 std::string GetTypeName() const { return TypeName<T*>(); }
257 std::string GetHumanTypeName() const { return HumanTypeName<T*>(); }
258 virtual bool IsPointerType() const { return true; }
261 virtual void BruteForceSetPointer(AtomicBlackBox* o, void* p)
263 bbtkDebugMessage("data",9,"AtomicBlackBoxTSetFunctor<"
264 <<TypeName<UBB>()<<","
265 <<TypeName<T*>()<<","
266 <<TypeName<TACCESS*>()
267 <<">::BruteForceSetPointer() (pointer specialization)");
269 (((UBB*)o)->*mSetMethodPointer)((T*)p);
273 /// Pointer on the Set method
274 SetMethodPointerType mSetMethodPointer;
276 //===========================================================================