/* # --------------------------------------------------------------------- # # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image # pour la SantÈ) # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton # Previous Authors : Laurent Guigues, Jean-Pierre Roux # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil # # This software is governed by the CeCILL-B license under French law and # abiding by the rules of distribution of free software. You can use, # modify and/ or redistribute the software under the terms of the CeCILL-B # license as circulated by CEA, CNRS and INRIA at the following URL # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html # or in the file LICENSE.txt. # # As a counterpart to the access to the source code and rights to copy, # modify and redistribute granted by the license, users are provided only # with a limited warranty and the software's author, the holder of the # economic rights, and the successive licensors have only limited # liability. # # The fact that you are presently reading this means that you have had # knowledge of the CeCILL-B license and that you accept its terms. # ------------------------------------------------------------------------ */ /*========================================================================= Program: bbtk Module: $RCSfile: bbtkAtomicBlackBoxMacros.h,v $ Language: C++ Date: $Date: 2012/11/16 08:49:01 $ Version: $Revision: 1.20 $ =========================================================================*/ /** * \file * \brief Defines macros for the creation of new user black boxes */ #ifndef __bbtkAtomicBlackBoxMacros_h__ #define __bbtkAtomicBlackBoxMacros_h__ //============================================================================ /// Declares the standard interface of a AtomicBlackBox /// (ctor, New, descriptor related methods) #define BBTK_BLACK_BOX_INTERFACE_INTERNAL_WITHOUT_NEW(CLASS,PARENT) \ BBTK_OBJECT_MINIMAL_INTERFACE; \ private: \ protected: \ CLASS(const std::string& name, bool allocate_connectors = true); \ CLASS(Self& from, const std::string& name, \ bool allocate_connectors = true); \ ~CLASS(); \ public: \ std::string GetObjectName() const \ { return std::string(#CLASS)+std::string(" '") \ +bbGetNameWithParent()+std::string("'"); } \ virtual void bbLockDescriptor(); \ virtual void bbUserSetDefaultValues(); \ virtual void bbUserInitializeProcessing(); \ virtual void bbUserFinalizeProcessing(); \ virtual void bbRecursiveInitializeProcessing() \ { \ PARENT::bbRecursiveInitializeProcessing(); \ CLASS::bbUserInitializeProcessing(); \ } \ virtual void bbRecursiveFinalizeProcessing() \ { \ CLASS::bbUserFinalizeProcessing(); \ PARENT::bbRecursiveFinalizeProcessing(); \ } \ private: \ CLASS() : PARENT("") {} \ CLASS(const CLASS&) : PARENT("") {} //============================================================================ //============================================================================ /// Declares the standard interface of a AtomicBlackBox /// (ctor, New, descriptor related methods) #define BBTK_BLACK_BOX_INTERFACE_INTERNAL(CLASS,PARENT) \ BBTK_OBJECT_MINIMAL_INTERFACE; \ private: \ protected: \ CLASS(const std::string& name, bool allocate_connectors = true); \ CLASS(Self& from, const std::string& name, \ bool allocate_connectors = true); \ ~CLASS(); \ public: \ std::string GetObjectName() const \ { return std::string(#CLASS)+std::string(" '") \ +bbGetNameWithParent()+std::string("'"); } \ inline static Pointer New(const std::string& name) \ { \ bbtkDebugMessage("object",1,"##> "<<#CLASS \ <<"::New(\""< "<<#CLASS \ <<"::bbClone(\""< Processing..." \ < "<<#CLASS<<"::"<<#CLASS \ <<"()"< "<<#CLASS<<"::"<<#CLASS \ <<"("< "<<#CLASS <<"::~"<< #CLASS \ <<"()"< "< "<<#CLASS<<"Descriptor::" \ <<#CLASS<<"Descriptor()"< \ (&CLASS::bbGetInput##NAME), \ new bbtk::AtomicBlackBoxTSetFunctor \ (&CLASS::bbSetInput##NAME) ) ) //============================================================================ //============================================================================ /// Describes a AtomicBlackBox output (to be put inside the UBB description block) #define BBTK_OUTPUT(CLASS,NAME,DESCR,TYPE,NATURE) \ AddOutputDescriptor(new bbtk::AtomicBlackBoxOutputDescriptor \ (typeid(CLASS ## Descriptor),#NAME,DESCR,NATURE, \ new bbtk::AtomicBlackBoxTGetFunctor \ (&CLASS::bbGetOutput##NAME), \ new bbtk::AtomicBlackBoxTSetFunctor \ (&CLASS::bbSetOutput##NAME) ) ) //============================================================================ //============================================================================ /// Describes a AtomicBlackBox input (to be put inside the UBB description block) #define BBTK_INPUT_NOCOPY(CLASS,NAME,DESCR,TYPE,NATURE) \ AddInputDescriptor(new bbtk::AtomicBlackBoxInputDescriptor \ (typeid(CLASS ## Descriptor),#NAME,DESCR,NATURE, \ new bbtk::AtomicBlackBoxTGetFunctor \ (&CLASS::bbGetInput##NAME), \ new bbtk::AtomicBlackBoxTSetFunctor \ (&CLASS::bbSetInput##NAME), \ false) ) //============================================================================ //============================================================================ /// Describes a AtomicBlackBox output (to be put inside the UBB description block) #define BBTK_OUTPUT_NOCOPY(CLASS,NAME,DESCR,TYPE,NATURE) \ AddOutputDescriptor(new bbtk::AtomicBlackBoxOutputDescriptor \ (typeid(CLASS ## Descriptor),#NAME,DESCR,NATURE, \ new bbtk::AtomicBlackBoxTGetFunctor \ (&CLASS::bbGetOutput##NAME), \ new bbtk::AtomicBlackBoxTSetFunctor \ (&CLASS::bbSetOutput##NAME),\ false) ) //============================================================================ //============================================================================ //============================================================================ // Template user black boxes macros //============================================================================ //============================================================================ //============================================================================ #define BBTK_TEMPLATE_BLACK_BOX_INTERFACE(CLASS,PARENT,T) \ public : typedef CLASS Self; \ BBTK_BLACK_BOX_INTERFACE_INTERNAL(CLASS,PARENT); //============================================================================ //============================================================================ /// Begins a template AtomicBlackBox of template param T description block #define BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(CLASS,PARENT) \ template \ class /*BBTK_EXPORT*/ CLASS ## Descriptor : public PARENT ## Descriptor \ { \ public: typedef CLASS ## Descriptor Self; \ BBTK_OBJECT_MINIMAL_INTERFACE; \ public: \ std::string GetObjectName() const \ { \ return std::string(BBTK_STRINGIFY(CLASS)) \ +std::string("Descriptor<")+bbtk::TypeName() \ +std::string("> '")+GetFullTypeName() \ +std::string("'"); \ } \ static Pointer New() \ { \ bbtkDebugMessage("object",1,"##> "<()<<">::New" \ <()<<">::New" \ <::New(name); \ } \ CLASS ## Descriptor() \ { \ bbtkDebugMessage("object",2,"==> "<<#CLASS<<"Descriptor<" \ <()<<">::" \ <<#CLASS<<"Descriptor()"<()<<">::" \ <<#CLASS<<"Descriptor()"<,TYPE,TYPE > \ (&CLASS::bbGetInput##NAME), \ new bbtk::AtomicBlackBoxTSetFunctor,TYPE,TYPE > \ (&CLASS::bbSetInput##NAME) ) ) //============================================================================ //============================================================================ /// Describes a template AtomicBlackBox output (to be put inside the template UBB description block) #define BBTK_TEMPLATE_OUTPUT(CLASS,NAME,DESCR,TYPE) \ AddOutputDescriptor(new bbtk::AtomicBlackBoxOutputDescriptor \ (typeid(CLASS ## Descriptor),#NAME,DESCR,"", \ new bbtk::AtomicBlackBoxTGetFunctor,TYPE,TYPE > \ (&CLASS::bbGetOutput##NAME), \ new bbtk::AtomicBlackBoxTSetFunctor,TYPE,TYPE > \ (&CLASS::bbSetOutput##NAME) ) ) //============================================================================ //JCP 09JUIN2009 BBTK_EXPORT //============================================================================ /// Template AtomicBlackBox std implementation of ctor and dtor #define BBTK_BLACK_BOX_TEMPLATE_IMPLEMENTATION(CLASS,PARENT) \ template \ CLASS::CLASS(const std::string& name, bool alloc) \ : PARENT(name,false) \ { \ BBTK_BEGIN_BLACK_BOX_CONSTRUCTOR(CLASS,alloc); \ CLASS::bbUserSetDefaultValues(); \ BBTK_END_BLACK_BOX_CONSTRUCTOR(CLASS); \ } \ template \ CLASS::CLASS(CLASS& from, \ const std::string& name, bool allocate_connectors) \ : PARENT(from,name,false) \ { \ BBTK_BEGIN_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from,allocate_connectors); \ CLASS::bbUserSetDefaultValues(); \ BBTK_END_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from,allocate_connectors); \ } \ template \ CLASS::~CLASS() \ { \ BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS); \ BBTK_END_BLACK_BOX_DESTRUCTOR(CLASS); \ } \ template \ void CLASS::bbLockDescriptor() \ { \ bbmDescriptorPointer = CLASS ## Descriptor::Instance(); \ } //============================================================================ //============================================================================ // Two template params user black boxes macros //============================================================================ //============================================================================ #define BBTK_TEMPLATE2_BLACK_BOX_INTERFACE(CLASS,PARENT,T1,T2) \ public : typedef CLASS Self; \ BBTK_BLACK_BOX_INTERFACE_INTERNAL(CLASS,PARENT); //=========================================================================== //============================================================================ /// Begins a template AtomicBlackBox description block of template param T1 and T2 #define BBTK_BEGIN_DESCRIBE_TEMPLATE2_BLACK_BOX(CLASS,PARENT) \ template \ class /*BBTK_EXPORT*/ CLASS ## Descriptor : public PARENT ## Descriptor \ { \ public: typedef CLASS ## Descriptor Self; \ BBTK_OBJECT_MINIMAL_INTERFACE; \ public: \ std::string GetObjectName() const \ { \ return std::string(BBTK_STRINGIFY(CLASS)) \ +std::string("Descriptor<")+bbtk::TypeName() \ +std::string(",")+bbtk::TypeName() \ +std::string("> '")+GetFullTypeName() \ +std::string("'"); \ } \ static Pointer New() \ { \ bbtkDebugMessage("object",1,"##> "<()<<"," \ <()<<">::New"<()<<"," \ <()<<">::New"<::New(name); \ } \ CLASS ## Descriptor() \ { \ bbtkDebugMessage("object",2,"==> "<<#CLASS<<"Descriptor<" \ <()<<"," \ <()<<">::" \ <<#CLASS<<"Descriptor()"<()<<"," \ <()<<">::" \ <<#CLASS<<"Descriptor()"< \ class CLASS ## Descriptor : public bbtk::BlackBoxDescriptor \ { \ public: \ virtual bbtk:AtomicBlackBoxDescriptor::Pointer GetInstance() const \ { \ return Instance(); \ } \ static bbtk:AtomicBlackBoxDescriptor::Pointer Instance() \ { \ static bbtk:AtomicBlackBoxDescriptor::WeakPointer i; \ bbtk:AtomicBlackBoxDescriptor::Pointer j; \ if (!i.lock()) { j = Self::New(); i = j; } \ return i.lock(); \ } \ bbtk::BlackBox::Pointer NewBlackBox(const std::string& name) \ { \ return new CLASS(name); \ } \ CLASS ## Descriptor() \ { \ bbtkDebugMessageInc("Kernel",9,#CLASS<<"Descriptor::"<<#CLASS \ <<"Descriptor()"<,TYPE,TYPE > \ (&CLASS::bbGetInput##NAME), \ new bbtk::AtomicBlackBoxTSetFunctor,TYPE,TYPE > \ (&CLASS::bbSetInput##NAME) ) ) //============================================================================ //============================================================================ /// Describes a 2 template params AtomicBlackBox output (to be put inside the UBB description block) #define BBTK_TEMPLATE2_OUTPUT(CLASS,NAME,DESCR,TYPE) \ AddOutputDescriptor(new bbtk::AtomicBlackBoxOutputDescriptor \ (typeid(CLASS ## Descriptor),#NAME,DESCR,"", \ new bbtk::AtomicBlackBoxTGetFunctor,TYPE,TYPE > \ (&CLASS::bbGetOutput##NAME), \ new bbtk::AtomicBlackBoxTSetFunctor,TYPE,TYPE > \ (&CLASS::bbSetOutput##NAME) ) ) //============================================================================ //============================================================================ /// Template AtomicBlackBox std implementation of ctor and dtor #define BBTK_BLACK_BOX_TEMPLATE2_IMPLEMENTATION(CLASS,PARENT) \ template \ CLASS::CLASS(const std::string& name, bool alloc) \ : PARENT(name,false) \ { \ BBTK_BEGIN_BLACK_BOX_CONSTRUCTOR(CLASS,alloc); \ CLASS::bbUserSetDefaultValues(); \ BBTK_END_BLACK_BOX_CONSTRUCTOR(CLASS); \ } \ template \ CLASS::CLASS(CLASS& from, \ const std::string& name, bool allocate_connectors) \ : PARENT(from,name,false) \ { \ BBTK_BEGIN_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from,allocate_connectors); \ CLASS::bbUserSetDefaultValues(); \ BBTK_END_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from,allocate_connectors); \ } \ template \ CLASS::~CLASS() \ { \ BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS); \ BBTK_END_BLACK_BOX_DESTRUCTOR(CLASS); \ } \ template \ void CLASS::bbLockDescriptor() \ { \ bbmDescriptorPointer = CLASS ## Descriptor::Instance(); \ } //============================================================================ //=========================================================================== /// EOF //=========================================================================== #endif