bbtkAtomicBlackBoxGetSetFunctor.h

Go to the documentation of this file.
00001 /*=========================================================================                                                                               
00002   Program:   bbtk
00003   Module:    $RCSfile: bbtkAtomicBlackBoxGetSetFunctor.h,v $
00004   Language:  C++
00005   Date:      $Date: 2008/11/25 11:17:13 $
00006   Version:   $Revision: 1.5 $
00007 =========================================================================*/
00008 
00009 /* ---------------------------------------------------------------------
00010 
00011 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
00012 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
00013 *
00014 *  This software is governed by the CeCILL-B license under French law and 
00015 *  abiding by the rules of distribution of free software. You can  use, 
00016 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
00017 *  license as circulated by CEA, CNRS and INRIA at the following URL 
00018 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
00019 *  or in the file LICENSE.txt.
00020 *
00021 *  As a counterpart to the access to the source code and  rights to copy,
00022 *  modify and redistribute granted by the license, users are provided only
00023 *  with a limited warranty  and the software's author,  the holder of the
00024 *  economic rights,  and the successive licensors  have only  limited
00025 *  liability. 
00026 *
00027 *  The fact that you are presently reading this means that you have had
00028 *  knowledge of the CeCILL-B license and that you accept its terms.
00029 * ------------------------------------------------------------------------ */                                                                         
00030 
00031 
00048 #ifndef __bbtkAtomicBlackBoxGetSetFunctor_h__
00049 #define __bbtkAtomicBlackBoxGetSetFunctor_h__
00050 
00051 #include "bbtkData.h"
00052 #include "bbtkMessageManager.h"
00053 
00054 namespace bbtk
00055 {
00056 
00057    // Forward declaration
00058   class AtomicBlackBox;
00059 
00060 
00061   //===========================================================================
00062   class BBTK_EXPORT AtomicBlackBoxGetFunctor
00063   {
00064   public:
00066     AtomicBlackBoxGetFunctor() {}
00068     virtual ~AtomicBlackBoxGetFunctor() {}
00070     virtual Data Get(AtomicBlackBox* o) = 0;
00072     virtual TypeInfo GetTypeInfo() const = 0;
00074     virtual std::string GetTypeName() const = 0;
00076     virtual std::string GetHumanTypeName() const = 0;
00078     virtual bool IsPointerType() const = 0;
00079 
00080   };
00081   //===========================================================================
00082 
00083 
00084   //===========================================================================
00085   class AtomicBlackBoxSetFunctor
00086   {
00087   public:
00089     AtomicBlackBoxSetFunctor() {}
00091     virtual ~AtomicBlackBoxSetFunctor() {}
00093     virtual void Set(AtomicBlackBox* o, const Data&) = 0;
00095     virtual TypeInfo GetTypeInfo() const = 0;
00097     virtual std::string GetTypeName() const = 0;
00099     virtual std::string GetHumanTypeName() const = 0;
00101     virtual bool IsPointerType() const = 0;
00107     virtual void BruteForceSetPointer(AtomicBlackBox* o, void* p) = 0;
00108 
00109   };
00110   //===========================================================================
00111 
00112 
00113 
00114   //===========================================================================
00115   template <class UBB, class T, class TRETURN> 
00116   class AtomicBlackBoxTGetFunctor : public bbtk::AtomicBlackBoxGetFunctor
00117   {
00118   public:
00120     typedef TRETURN (UBB::*GetMethodPointerType)(void); //const
00121 
00123     AtomicBlackBoxTGetFunctor(GetMethodPointerType g) :
00124       mGetMethodPointer(g)
00125       {
00126         bbtkDebugMessage("data",9,"AtomicBlackBoxTGetFunctor<"<<
00127                          TypeName<UBB>()<<","<<
00128                          TypeName<T>()<<","<<
00129                          TypeName<TRETURN>()<<
00130                          ">::AtomicBlackBoxTGetFunctor()"<<std::endl);
00131       }
00132       
00134     Data Get(AtomicBlackBox* o) 
00135     {
00136       bbtkDebugMessage("data",9,"AtomicBlackBoxTGetFunctor<"<<
00137                        TypeName<UBB>()<<","<<
00138                        TypeName<T>()<<","<<
00139                        TypeName<TRETURN>()<<
00140                        ">::Get()"<<std::endl);
00141       return (((UBB*)o)->*mGetMethodPointer)();
00142     }
00144     TypeInfo GetTypeInfo() const { return typeid(T); }
00145     std::string GetTypeName() const { return TypeName<T>(); }
00146     std::string GetHumanTypeName() const { return HumanTypeName<T>(); }
00148     virtual bool IsPointerType() const 
00149     {
00150       return boost::is_pointer<T>::value;
00151     }
00152 
00153   private:
00155     GetMethodPointerType mGetMethodPointer;
00156   };
00157   //===========================================================================
00158 
00159 
00160 
00161   //===========================================================================
00162   template <class UBB, class T, class TACCESS> 
00163   class AtomicBlackBoxTSetFunctor : public AtomicBlackBoxSetFunctor
00164   {
00165   public:
00167     typedef void (UBB::*SetMethodPointerType)(TACCESS);
00168 
00170     AtomicBlackBoxTSetFunctor(SetMethodPointerType s) :
00171       mSetMethodPointer(s) 
00172       {
00173         bbtkDebugMessage("data",9,"AtomicBlackBoxTSetFunctor<"<<
00174                         TypeName<UBB>()<<","<<
00175                         TypeName<T>()<<","<<
00176                         TypeName<TACCESS>()<<
00177                          ">::AtomicBlackBoxTSetFunctor()"<<std::endl);
00178       }
00179       
00181     void Set(AtomicBlackBox* o, const Data& d)
00182     { 
00183       bbtkDebugMessage("data",9,"AtomicBlackBoxTSetfunctor<"<<
00184                         TypeName<UBB>()<<","<<
00185                         TypeName<T>()<<","<<
00186                         TypeName<TACCESS>()<<
00187                        ">::Set()"<<std::endl);
00188       //      (((UBB*)o)->*mSetMethodPointer)(*(T*)d);
00189       //      bbtkAssert( bbtkEqualTypes( d.type(), typeid(T) ) );
00190       T t = d.unsafe_get<T>();
00191       (((UBB*)o)->*mSetMethodPointer)(t);
00192       //      bbtkDebugMessage("Kernel",9,"SetOK"<<std::endl);
00193     }
00194 
00196     TypeInfo GetTypeInfo() const { return typeid(T); }
00197     std::string GetTypeName() const { return TypeName<T>(); }
00198     std::string GetHumanTypeName() const { return HumanTypeName<T>(); }
00199     virtual bool IsPointerType() const { return false; }
00200     virtual void BruteForceSetPointer(AtomicBlackBox* b, void* p) 
00201     {
00202       bbtkInternalError("AtomicBlackBoxTSetFunctor<"
00203                         <<TypeName<UBB>()<<","
00204                         <<TypeName<T>()<<","
00205                         <<TypeName<TACCESS>()
00206                         <<">::BruteForceSetPointer("
00207                         <<b<<","<<p<<")"
00208                         <<" called whereas type '"
00209                         <<TypeName<T>()
00210                         <<"' is not a pointer type"); 
00211     }
00212   private:
00214     SetMethodPointerType mSetMethodPointer;
00215   };
00216   //===========================================================================
00217 
00218 
00219 
00220   //===========================================================================
00222   template <class UBB, class T, class TACCESS> 
00223   class AtomicBlackBoxTSetFunctor<UBB,T*,TACCESS*> 
00224     : public AtomicBlackBoxSetFunctor
00225   {
00226   public:
00228     typedef void (UBB::*SetMethodPointerType)(TACCESS*);
00229 
00231     AtomicBlackBoxTSetFunctor(SetMethodPointerType s) :
00232       mSetMethodPointer(s) 
00233     {
00234       bbtkDebugMessage("data",9,"AtomicBlackBoxTSetFunctor<"<<
00235                        TypeName<UBB>()<<","<<
00236                        TypeName<T*>()<<","<<
00237                        TypeName<TACCESS*>()<<
00238                        ">::AtomicBlackBoxTSetFunctor()"<<std::endl);
00239     }
00240     
00242     void Set(AtomicBlackBox* o, const Data& d)
00243     { 
00244       bbtkDebugMessage("data",9,"AtomicBlackBoxTSetfunctor<"<<
00245                        TypeName<UBB>()<<","<<
00246                        TypeName<T*>()<<","<<
00247                        TypeName<TACCESS*>()<<
00248                        ">::Set()"<<std::endl);
00249       
00250       (((UBB*)o)->*mSetMethodPointer)(d.unsafe_get<T*>());
00251 
00252     }
00253 
00255     TypeInfo GetTypeInfo() const { return typeid(T*); }
00256     std::string GetTypeName() const { return TypeName<T*>(); }
00257     std::string GetHumanTypeName() const { return HumanTypeName<T*>(); }
00258     virtual bool IsPointerType() const { return true; }
00259 
00260  
00261     virtual void BruteForceSetPointer(AtomicBlackBox* o, void* p) 
00262     {  
00263       bbtkDebugMessage("data",9,"AtomicBlackBoxTSetFunctor<"
00264                        <<TypeName<UBB>()<<","
00265                        <<TypeName<T*>()<<","
00266                        <<TypeName<TACCESS*>()
00267                        <<">::BruteForceSetPointer() (pointer specialization)");
00268 
00269       (((UBB*)o)->*mSetMethodPointer)((T*)p);
00270 
00271     }
00272   private:
00274     SetMethodPointerType mSetMethodPointer;
00275   };
00276   //===========================================================================
00277 
00278 }
00279 // namespace bbtk
00280 #endif

Generated on Thu May 31 14:12:03 2012 for BBTK by  doxygen 1.5.7.1