/*========================================================================= Program: bbtk Module: $RCSfile: bbtkAtomicBlackBoxMacros.h,v $ Language: C++ Date: $Date: 2008/05/06 07:36:42 $ Version: $Revision: 1.8 $ 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 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(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 \ <<"() ["<bbGetFullName()<<"]"<bbGetFullName()<<"]"< "< "<<#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) ) ) //============================================================================ //============================================================================ /// 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::bbUserConstructor(); \ 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::bbUserCopyConstructor(); \ BBTK_END_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from); \ } \ template \ CLASS::~CLASS() \ { \ BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS); \ CLASS::bbUserDestructor(); \ 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::bbUserConstructor(); \ 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::bbUserCopyConstructor(); \ BBTK_END_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from); \ } \ template \ CLASS::~CLASS() \ { \ BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS); \ CLASS::bbUserDestructor(); \ BBTK_END_BLACK_BOX_DESTRUCTOR(CLASS); \ } \ template \ void CLASS::bbLockDescriptor() \ { \ bbmDescriptorPointer = CLASS ## Descriptor::Instance(); \ } //============================================================================ /* //============================================================================ /// Template AtomicBlackBox std implementation of ctor and dtor #define BBTK_BLACK_BOX_TEMPLATE2_WITH_TYPES_IMPLEMENTATION(CLASS,PARENT,TYPE1,TYPE2) \ template \ CLASS::CLASS(const std::string& name, bool alloc) \ : PARENT(name,false) \ { \ BBTK_BEGIN_BLACK_BOX_CONSTRUCTOR(CLASS,alloc); \ this->bbUserConstructor(); \ BBTK_END_BLACK_BOX_CONSTRUCTOR; \ } \ 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); \ this->bbUserCopyConstructor(); \ BBTK_END_BLACK_BOX_CONSTRUCTOR; \ } \ template \ CLASS::~CLASS() \ { \ BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS); \ this->bbUserDestructor(); \ BBTK_END_BLACK_BOX_DESTRUCTOR; \ } \ template \ void CLASS::bbLockDescriptor() \ { \ bbmDescriptorPointer = CLASS ## Descriptor::Instance(); \ } //============================================================================ */ //=========================================================================== //============================================================================ // ITK Specific macros //=========================================================================== //=========================================================================== //=========================================================================== /// Declares an itk-inherited AtomicBlackBox input #define BBTK_DECLARE_ITK_INPUT(PARENT,NAME,TYPE) \ public: \ TYPE bbGetInput##NAME () \ { return PARENT::GetInput(); } \ void bbSetInput##NAME (TYPE d) \ { PARENT::SetInput(d); \ /*bbSetModifiedStatus();*/ } //=========================================================================== //=========================================================================== #define BBTK_DECLARE_ITK_OUTPUT(PARENT,NAME,TYPE) \ public: \ TYPE bbGetOutput##NAME () \ { return PARENT::GetOutput(); } \ void bbSetOutput##NAME (TYPE d) \ { /*PARENT::GetOutput() = d;*/ } //=========================================================================== //=========================================================================== /// Declares an AtomicBlackBox input corresponding to an inherited itk parameter /// which was declared by itkSetMacro/itkGetMacro /// The NAME **MUST** be the same than the itk parameter name #define BBTK_DECLARE_ITK_PARAM(PARENT,NAME,TYPE) \ public: \ TYPE bbGetInput##NAME () \ { return PARENT::Get##NAME(); } \ void bbSetInput##NAME (TYPE d) \ { PARENT::Set##NAME(d); \ /*bbSetModifiedStatus();*/ } //=========================================================================== //=========================================================================== //============================================================================ // VTK Specific macros //=========================================================================== //=========================================================================== //=========================================================================== // EED sept 04 \ // { return GetInput(); /*PARENT::GetInput();*/ } \ // { PARENT::SetInput( /*(vtkDataObject*)*/ d); \ /// Declares a vtkImageAlgorithm-inherited AtomicBlackBox input #define BBTK_DECLARE_VTK_IMAGE_ALGORITHM_INPUT(PARENT,NAME,TYPE) \ public: \ TYPE bbGetInput##NAME () \ { return GetImageDataInput(0); /*PARENT::GetInput();*/ } \ void bbSetInput##NAME (TYPE d) \ { PARENT::SetInput( (vtkDataObject*) d); \ /*bbSetModifiedStatus();*/ } //=========================================================================== /// Declares a vtkPolyDataAlgorithm-inherited AtomicBlackBox input #define BBTK_DECLARE_VTK_POLY_DATA_ALGORITHM_INPUT(PARENT,NAME,TYPE) \ public: \ TYPE bbGetInput##NAME () \ { return GetPolyDataInput(0); /*PARENT::GetInput();*/ } \ void bbSetInput##NAME (TYPE d) \ { PARENT::SetInput( (vtkDataObject*) d); \ /*bbSetModifiedStatus();*/ } //=========================================================================== //=========================================================================== /// Declares a vtkImageAlgorithm-inherited AtomicBlackBox output #define BBTK_DECLARE_VTK_OUTPUT(PARENT,NAME,TYPE) \ public: \ TYPE bbGetOutput##NAME () \ { return PARENT::GetOutput(); } \ void bbSetOutput##NAME (TYPE d) \ { /*PARENT::GetOutput() = d;*/ } //=========================================================================== //=========================================================================== /// Declares a vtkAlgorithm-inherited AtomicBlackBox input #define BBTK_DECLARE_VTK_INPUT(PARENT,NAME,TYPE) \ public: \ TYPE bbGetInput##NAME () \ { return dynamic_cast(PARENT::GetInput()); } \ void bbSetInput##NAME (TYPE d) \ { PARENT::SetInput( (vtkDataObject*) d); /*PARENT::GetOutput() = d;*/ } //=========================================================================== //=========================================================================== /// Declares an AtomicBlackBox input corresponding to an inherited vtk parameter /// which was declared by vtkSetMacro/vtkGetMacro /// The NAME **MUST** be the same than the vtk parameter name #define BBTK_DECLARE_VTK_PARAM(PARENT,NAME,TYPE) \ public: \ TYPE bbGetInput##NAME () \ { return PARENT::Get##NAME(); } \ void bbSetInput##NAME (TYPE d) \ { PARENT::Set##NAME(d); \ /*bbSetModifiedStatus();*/ } //=========================================================================== #define BBTK_VTK_DELETE(VTKPARENT) \ void bbDelete() { VTKPARENT::Delete(); } //=========================================================================== /// EOF //=========================================================================== #endif