/*========================================================================= Program: bbtk Module: $RCSfile: bbtkUserBlackBoxGetSetFunctor.h,v $ Language: C++ Date: $Date: 2008/01/22 15:02:00 $ Version: $Revision: 1.1.1.1 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ /** * \file * \brief Class bbtk::UserBlackBoxGetFunctor / Class bbtk::UserBlackBoxSetFunctor : abstract functors of the Get and Set accessors of the inputs and outputs of a UserBlackBox ; Concrete derivatives. */ /** * \class bbtk::UserBlackBoxGetFunctor * \brief Abstract functor of the Get accessors of the inputs and outputs of a UserBlackBox * \class bbtk::UserBlackBoxSetFunctor * \brief Abstract functor of the Set accessors of the inputs and outputs of a UserBlackBox * \class bbtk::UserBlackBoxTGetFunctor * \brief Template for concrete functors of the Get accessors of the inputs and outputs of a UserBlackBox (inherits from bbtk::UserBlackBoxGetFunctor). * \class bbtk::UserBlackBoxTSetFunctor * \brief Template for concrete functors of the Set accessors of the inputs and outputs of a UserBlackBox (inherits from bbtk::UserBlackBoxSetFunctor). */ #ifndef __bbtkUserBlackBoxGetSetFunctor_h__ #define __bbtkUserBlackBoxGetSetFunctor_h__ #include "bbtkData.h" #include "bbtkMessageManager.h" namespace bbtk { // Forward declaration class UserBlackBox; //=========================================================================== class BBTK_EXPORT UserBlackBoxGetFunctor { public: /// Default constructor UserBlackBoxGetFunctor() {} /// Abstract method which applies the "Get" function of UserBlackBox o virtual Data Get(UserBlackBox* o) = 0; /// virtual TypeInfo GetTypeInfo() const = 0; /// virtual std::string GetTypeName() const = 0; /// virtual std::string GetHumanTypeName() const = 0; /// virtual bool IsPointerType() const = 0; }; //=========================================================================== //=========================================================================== class UserBlackBoxSetFunctor { public: /// Default constructor UserBlackBoxSetFunctor() {} /// Abstract method which applies the "Set" function of UserBlackBox o virtual void Set(UserBlackBox* o, const Data&) = 0; /// virtual TypeInfo GetTypeInfo() const = 0; /// virtual std::string GetTypeName() const = 0; /// virtual std::string GetHumanTypeName() const = 0; /// virtual bool IsPointerType() const = 0; /// Abstract method which applies the "Set" function of UserBlackBox o /// using brute force cast to the typed pointer required by the "Set" fun. /// Only works if the param type of the "Set" function is a pointer /// (see template specialization below). /// !!! Use with care !!! virtual void BruteForceSetPointer(UserBlackBox* o, void* p) = 0; }; //=========================================================================== //=========================================================================== template class UserBlackBoxTGetFunctor : public bbtk::UserBlackBoxGetFunctor { public: /// Type of pointer on a UBB::Get method typedef TRETURN (UBB::*GetMethodPointerType)(void); //const /// Construction with the pointer on the Get method UserBlackBoxTGetFunctor(GetMethodPointerType g) : mGetMethodPointer(g) { bbtkDebugMessage("Data",9,"UserBlackBoxTGetFunctor<"<< TypeName()<<","<< TypeName()<<","<< TypeName()<< ">::UserBlackBoxTGetFunctor()"<()<<","<< TypeName()<<","<< TypeName()<< ">::Get()"<*mGetMethodPointer)(); } /// TypeInfo GetTypeInfo() const { return typeid(T); } std::string GetTypeName() const { return TypeName(); } std::string GetHumanTypeName() const { return HumanTypeName(); } /// virtual bool IsPointerType() const { #ifdef _USE_BOOST_ return boost::is_pointer::value; #else return false; #endif } private: /// Pointer on the Get method GetMethodPointerType mGetMethodPointer; }; //=========================================================================== //=========================================================================== template class UserBlackBoxTSetFunctor : public UserBlackBoxSetFunctor { public: /// Type of pointer on a UBB::Set method typedef void (UBB::*SetMethodPointerType)(TACCESS); /// Construction with the pointer on the Set method UserBlackBoxTSetFunctor(SetMethodPointerType s) : mSetMethodPointer(s) { bbtkDebugMessage("Data",9,"UserBlackBoxTSetFunctor<"<< TypeName()<<","<< TypeName()<<","<< TypeName()<< ">::UserBlackBoxTSetFunctor()"<()<<","<< TypeName()<<","<< TypeName()<< ">::Set()"<*mSetMethodPointer)(*(T*)d); // bbtkAssert( bbtkEqualTypes( d.type(), typeid(T) ) ); T t = d.unsafe_get(); (((UBB*)o)->*mSetMethodPointer)(t); // bbtkDebugMessage("Core",9,"SetOK"<(); } std::string GetHumanTypeName() const { return HumanTypeName(); } virtual bool IsPointerType() const { return false; } virtual void BruteForceSetPointer(UserBlackBox* b, void* p) { bbtkInternalError("UserBlackBoxTSetFunctor<" <()<<"," <()<<"," <() <<">::BruteForceSetPointer(" <() <<"' is not a pointer type"); } private: /// Pointer on the Set method SetMethodPointerType mSetMethodPointer; }; //=========================================================================== //=========================================================================== /// Template specialization of UserBlackBoxTSetFunctor for pointer types template class UserBlackBoxTSetFunctor : public UserBlackBoxSetFunctor { public: /// Type of pointer on a UBB::Set method typedef void (UBB::*SetMethodPointerType)(TACCESS*); /// Construction with the pointer on the Set method UserBlackBoxTSetFunctor(SetMethodPointerType s) : mSetMethodPointer(s) { bbtkDebugMessage("Data",9,"UserBlackBoxTSetFunctor<"<< TypeName()<<","<< TypeName()<<","<< TypeName()<< ">::UserBlackBoxTSetFunctor()"<()<<","<< TypeName()<<","<< TypeName()<< ">::Set()"<*mSetMethodPointer)(d.unsafe_get()); } /// TypeInfo GetTypeInfo() const { return typeid(T*); } std::string GetTypeName() const { return TypeName(); } std::string GetHumanTypeName() const { return HumanTypeName(); } virtual bool IsPointerType() const { return true; } virtual void BruteForceSetPointer(UserBlackBox* o, void* p) { bbtkDebugMessage("Data",9,"UserBlackBoxTSetFunctor<" <()<<"," <()<<"," <() <<">::BruteForceSetPointer() (pointer specialization)"); (((UBB*)o)->*mSetMethodPointer)((T*)p); } private: /// Pointer on the Set method SetMethodPointerType mSetMethodPointer; }; //=========================================================================== } // namespace bbtk #endif