X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkAtomicBlackBoxMacros.h;h=7ff6640249c0f4c5baddb15655bf704a77581c37;hb=4ad5b5ee44357ad873bc8c43230defb6d0a79879;hp=ed05e79981dca978b3b07c2991ef93f8f92ebb3c;hpb=c2a4b1893412e50a3d9abff221938a2d16c4a7cb;p=bbtk.git diff --git a/kernel/src/bbtkAtomicBlackBoxMacros.h b/kernel/src/bbtkAtomicBlackBoxMacros.h index ed05e79..7ff6640 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/09 11:16:56 $ - Version: $Revision: 1.4 $ + Date: $Date: 2008/04/18 12:59:15 $ + Version: $Revision: 1.5 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -27,51 +27,48 @@ //============================================================================ /// 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(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(\""<bbGetDescriptor()->Reference(); \ - bbtkDebugDecTab("Kernel",9); \ - return c; \ - } \ - inline bbtk::BlackBox* bbClone(const std::string& name) \ - { \ - bbtkDebugMessageInc("Kernel",9,#CLASS<<"::bbClone(\""<Reference(); \ - bbtkDebugDecTab("Kernel",9); \ - return c; \ - } \ - bbtk::BlackBoxDescriptor* bbGetDescriptor() const \ + public: \ + std::string GetObjectName() const \ + { return std::string(#CLASS)+std::string(" '") \ + +bbGetNameWithParent()+std::string("'"); } \ + inline static Pointer New(const std::string& name) \ { \ - return (bbtk::BlackBoxDescriptor*)bbDescriptor(); \ + bbtkDebugMessage("object",1,"##> "<<#CLASS \ + <<"::New(\""< "<<#CLASS \ + <<"::bbClone(\""< "<<#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; \ - } + }; + //============================================================================ //============================================================================ @@ -392,76 +468,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); \ } \ @@ -476,16 +613,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) @@ -511,37 +643,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) \ @@ -565,10 +703,15 @@ BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS); \ this->bbUserDestructor(); \ BBTK_END_BLACK_BOX_DESTRUCTOR; \ - } + } \ + template \ + void CLASS::bbLockDescriptor() \ + { \ + bbmDescriptorPointer = CLASS ## Descriptor::Instance(); \ + } //============================================================================ - +*/