X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=kernel%2Fsrc%2FbbtkAtomicBlackBoxMacros.h;h=ef5042aae19e35de69223c1d438d14119975f312;hb=db2adec4da5413691b7430ee1fa2354b9e53d312;hp=605c10d0d7255ffc4b09f443c2967017db8f848e;hpb=6c5d7746e8e4cb0b5d6e164b917008a7137910fb;p=bbtk.git diff --git a/kernel/src/bbtkAtomicBlackBoxMacros.h b/kernel/src/bbtkAtomicBlackBoxMacros.h index 605c10d..ef5042a 100644 --- a/kernel/src/bbtkAtomicBlackBoxMacros.h +++ b/kernel/src/bbtkAtomicBlackBoxMacros.h @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkAtomicBlackBoxMacros.h,v $ Language: C++ - Date: $Date: 2008/04/08 06:59:29 $ - Version: $Revision: 1.3 $ + Date: $Date: 2008/07/29 07:31:13 $ + Version: $Revision: 1.10 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -27,49 +27,76 @@ //============================================================================ /// Declares the standard interface of a AtomicBlackBox /// (ctor, New, descriptor related methods) -#define BBTK_USER_BLACK_BOX_INTERFACE(CLASS,PARENT) \ +#define BBTK_BLACK_BOX_INTERFACE_INTERNAL_WITHOUT_NEW(CLASS,PARENT) \ + BBTK_OBJECT_MINIMAL_INTERFACE; \ private: \ - inline static void bbCreateDescriptorIfNeeded(); \ protected: \ CLASS(const std::string& name, bool allocate_connectors = true); \ - CLASS(CLASS& from, const std::string& name, \ + CLASS(Self& from, const std::string& name, \ bool allocate_connectors = true); \ ~CLASS(); \ - public: \ - inline static CLASS* bbNew(const std::string& name) \ - { \ - bbtkDebugMessageInc("Kernel",9,#CLASS<<"::bbNew(\""< "<<#CLASS \ + <<"::New(\""< "<<#CLASS \ + <<"::bbClone(\""< "< Processing ["< "<<#CLASS<<"::"<<#CLASS \ + <<"(\""< "<<#CLASS<<"::"<<#CLASS \ <<"("<bbGetFullName()<<"]"< "<<#CLASS <<"::~"<< #CLASS \ + <<"() ["<bbGetFullName()<<"]"<bbGetFullName()<<"]"< "< "<<#CLASS<<"Descriptor::" \ + <<#CLASS<<"Descriptor()"< 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) \ - template \ - class /*BBTK_EXPORT*/ CLASS ## Descriptor : public bbtk::BlackBoxDescriptor \ +#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: \ - bbtk::BlackBox::Pointer CreateInstance(const std::string& name) \ + 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" \ + <::bbNew(name); \ + return CLASS::New(name); \ } \ CLASS ## Descriptor() \ { \ - bbtkDebugMessageInc("Kernel",9,#CLASS<<"Descriptor::"<<#CLASS \ - <<"Descriptor()"< "<<#CLASS<<"Descriptor<" \ + <()<<">::" \ + <<#CLASS<<"Descriptor()"<()<<">::" \ + <<#CLASS<<"Descriptor()"< \ - void CLASS::bbCreateDescriptorIfNeeded() \ - { \ - if ( !bbDescriptorPointer() ) \ - bbDescriptorPointer() = new CLASS ## Descriptor; \ - } + }; + //============================================================================ //============================================================================ @@ -390,76 +496,137 @@ //============================================================================ /// Template AtomicBlackBox std implementation of ctor and dtor -#define BBTK_USER_BLACK_BOX_TEMPLATE_IMPLEMENTATION(CLASS,PARENT) \ +#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; \ - } \ + 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) \ + 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); \ + BBTK_BEGIN_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from,allocate_connectors); \ CLASS::bbUserCopyConstructor(); \ - BBTK_END_BLACK_BOX_CONSTRUCTOR; \ - } \ + BBTK_END_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from); \ + } \ template \ CLASS::~CLASS() \ { \ - BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS); \ + BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS); \ CLASS::bbUserDestructor(); \ - BBTK_END_BLACK_BOX_DESTRUCTOR; \ - } + 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) \ +#define BBTK_BEGIN_DESCRIBE_TEMPLATE2_BLACK_BOX(CLASS,PARENT) \ template \ - class /*BBTK_EXPORT*/ CLASS ## Descriptor : public bbtk::BlackBoxDescriptor \ + class /*BBTK_EXPORT*/ CLASS ## Descriptor : public PARENT ## Descriptor \ { \ + public: typedef CLASS ## Descriptor Self; \ + BBTK_OBJECT_MINIMAL_INTERFACE; \ public: \ - bbtk::BlackBox::Pointer CreateInstance(const std::string& name) \ + 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"<::bbNew(name); \ + return CLASS::New(name); \ } \ CLASS ## Descriptor() \ { \ - bbtkDebugMessageInc("Kernel",9,#CLASS<<"Descriptor::"<<#CLASS \ - <<"Descriptor()"< "<<#CLASS<<"Descriptor<" \ + <()<<"," \ + <()<<">::" \ + <<#CLASS<<"Descriptor()"<()<<"," \ + <()<<">::" \ + <<#CLASS<<"Descriptor()"< \ - void CLASS::bbCreateDescriptorIfNeeded() \ - { \ - if ( !bbDescriptorPointer() ) \ - bbDescriptorPointer() = new CLASS ## Descriptor; \ - } + }; + //============================================================================ + + +/* //============================================================================ // Two template params user black boxes macros /// Begins a template AtomicBlackBox description block of template param T1 and T2 #define BBTK_BEGIN_DESCRIBE_TEMPLATE2_WITH_TYPES_BLACK_BOX(CLASS,TYPE1,TYPE2) \ template \ - class /*BBTK_EXPORT*/ CLASS ## Descriptor : public bbtk::BlackBoxDescriptor \ + class CLASS ## Descriptor : public bbtk::BlackBoxDescriptor \ { \ public: \ - bbtk::BlackBox::Pointer CreateInstance(const std::string& name) \ + 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); \ } \ @@ -474,16 +641,11 @@ #define BBTK_END_DESCRIBE_TEMPLATE2_WITH_TYPES_BLACK_BOX(CLASS,TYPE1,TYPE2) \ bbtkDecTab("Kernel",9); \ } \ - }; \ - template \ - void CLASS::bbCreateDescriptorIfNeeded() \ - { \ - if ( !bbDescriptorPointer() ) \ - bbDescriptorPointer() = new CLASS ## Descriptor; \ - } -//============================================================================ + }; +//============================================================================ +*/ //============================================================================ /// Describes a 2 template params AtomicBlackBox input (to be put inside the UBB description block) @@ -509,37 +671,43 @@ //============================================================================ /// Template AtomicBlackBox std implementation of ctor and dtor -#define BBTK_USER_BLACK_BOX_TEMPLATE2_IMPLEMENTATION(CLASS,PARENT) \ +#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; \ + BBTK_END_BLACK_BOX_CONSTRUCTOR(CLASS); \ } \ - template \ - CLASS::CLASS(CLASS& from, \ - const std::string& name, bool allocate_connectors) \ + 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_CONSTRUCTOR; \ + BBTK_END_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from); \ } \ template \ CLASS::~CLASS() \ { \ BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS); \ CLASS::bbUserDestructor(); \ - BBTK_END_BLACK_BOX_DESTRUCTOR; \ - } + BBTK_END_BLACK_BOX_DESTRUCTOR(CLASS); \ + } \ + template \ + void CLASS::bbLockDescriptor() \ + { \ + bbmDescriptorPointer = CLASS ## Descriptor::Instance(); \ + } //============================================================================ +/* //============================================================================ /// Template AtomicBlackBox std implementation of ctor and dtor -#define BBTK_USER_BLACK_BOX_TEMPLATE2_WITH_TYPES_IMPLEMENTATION(CLASS,PARENT,TYPE1,TYPE2) \ +#define BBTK_BLACK_BOX_TEMPLATE2_WITH_TYPES_IMPLEMENTATION(CLASS,PARENT,TYPE1,TYPE2) \ template \ CLASS::CLASS(const std::string& name, bool alloc) \ : PARENT(name,false) \ @@ -563,123 +731,19 @@ BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS); \ this->bbUserDestructor(); \ BBTK_END_BLACK_BOX_DESTRUCTOR; \ - } -//============================================================================ - - - - - -//=========================================================================== -//============================================================================ -// 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();*/ } -//=========================================================================== - - - - -//=========================================================================== + } \ + template \ + void CLASS::bbLockDescriptor() \ + { \ + bbmDescriptorPointer = CLASS ## Descriptor::Instance(); \ + } //============================================================================ -// 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();*/ } -//===========================================================================