+/*
+ # ---------------------------------------------------------------------
+ #
+ # 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: 2008/04/09 11:16:56 $
- Version: $Revision: 1.4 $
-
- 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.
-
+ Date: $Date: 2012/11/16 08:49:01 $
+ Version: $Revision: 1.20 $
=========================================================================*/
+
+
+
/**
* \file
* \brief Defines macros for the creation of new user black boxes
//============================================================================
/// 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: \
+ 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: \
- 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) \
+ public: \
+ std::string GetObjectName() const \
+ { return std::string(#CLASS)+std::string(" '") \
+ +bbGetNameWithParent()+std::string("'"); } \
+ inline static Pointer New(const std::string& name) \
{ \
- bbtkDebugMessageInc("Kernel",9,#CLASS<<"::bbNew(\""<<name<<"\")"<<std::endl); \
- bbCreateDescriptorIfNeeded(); \
- CLASS* c = new CLASS(name); \
- c->bbGetDescriptor()->Reference(); \
- bbtkDebugDecTab("Kernel",9); \
- return c; \
+ bbtkDebugMessage("object",1,"##> "<<#CLASS \
+ <<"::New(\""<<name<<"\")"<<std::endl); \
+ Pointer p = MakeBlackBoxPointer(new Self(name)); \
+ bbtkDebugMessage("object",1,"<## "<<#CLASS \
+ <<"::New(\""<<name<<"\")"<<std::endl); \
+ return p; \
} \
- inline bbtk::BlackBox* bbClone(const std::string& name) \
+ inline bbtk::BlackBox::Pointer bbClone(const std::string& name) \
{ \
- bbtkDebugMessageInc("Kernel",9,#CLASS<<"::bbClone(\""<<name<<"\")"<<std::endl); \
- bbCreateDescriptorIfNeeded(); \
- CLASS* c = new CLASS(*this,name); \
- bbGetDescriptor()->Reference(); \
- bbtkDebugDecTab("Kernel",9); \
- return c; \
+ bbtkBlackBoxDebugMessage("object",1,"##> "<<#CLASS \
+ <<"::bbClone(\""<<name<<"\")"<<std::endl); \
+ Pointer p = MakeBlackBoxPointer(new Self(*this,name)); \
+ bbtkBlackBoxDebugMessage("object",1,"<## "<<#CLASS \
+ <<"::bbClone(\""<<name<<"\")"<<std::endl); \
+ return p; \
} \
- bbtk::BlackBoxDescriptor* bbGetDescriptor() const \
+ virtual void bbLockDescriptor(); \
+ virtual void bbUserSetDefaultValues(); \
+ virtual void bbUserInitializeProcessing(); \
+ virtual void bbUserFinalizeProcessing(); \
+ virtual void bbRecursiveInitializeProcessing() \
{ \
- return (bbtk::BlackBoxDescriptor*)bbDescriptor(); \
+ PARENT::bbRecursiveInitializeProcessing(); \
+ CLASS::bbUserInitializeProcessing(); \
} \
- static bbtk::BlackBoxDescriptor* bbDescriptor() \
+ virtual void bbRecursiveFinalizeProcessing() \
{ \
- bbCreateDescriptorIfNeeded(); \
- return bbDescriptorPointer(); \
+ CLASS::bbUserFinalizeProcessing(); \
+ PARENT::bbRecursiveFinalizeProcessing(); \
} \
private: \
CLASS() : PARENT("") {} \
- static bbtk::BlackBoxDescriptor*& bbDescriptorPointer() \
- { \
- static bbtk::BlackBoxDescriptor* d = 0; \
- return d; \
- }
+ CLASS(const CLASS&) : PARENT("") {}
+
//============================================================================
+//============================================================================
+#define BBTK_BLACK_BOX_INTERFACE(CLASS,PARENT) \
+ public : typedef CLASS Self; \
+ BBTK_BLACK_BOX_INTERFACE_INTERNAL(CLASS,PARENT);
+//============================================================================
+
+//============================================================================
+#define BBTK_BLACK_BOX_INTERFACE_WITHOUT_NEW(CLASS,PARENT) \
+ public : typedef CLASS Self; \
+ BBTK_BLACK_BOX_INTERFACE_INTERNAL_WITHOUT_NEW(CLASS,PARENT);
+//============================================================================
//============================================================================
/// Defines the bbUserProcess method
public: \
inline void bbUserProcess() \
{ \
- bbtkDebugMessageInc("Process",1,"=> "<<bbGetTypeName()<<"::bbUserProcess() [" \
- <<bbGetFullName()<<"]"<<std::endl); \
+ bbtkBlackBoxDebugMessage("process",1,"**> Processing..." \
+ <<std::endl); \
CALLBACK(); \
- bbtkDebugMessageDec("Process",1,"<= "<<bbGetTypeName()<<"::bbUserProcess() [" \
- <<bbGetFullName()<<"]"<<std::endl); \
+ bbtkBlackBoxDebugMessage("process",1,"<** Processing" \
+ <<std::endl); \
}
//============================================================================
//============================================================================
#define BBTK_BEGIN_BLACK_BOX_CONSTRUCTOR(CLASS,ALLOC) \
- bbtkDebugMessageInc("Kernel",7,#CLASS<<"::"<<#CLASS \
- <<"(\""<<bbGetName()<<"\")"<<std::endl); \
- if (ALLOC) bbAllocateConnectors();
+ bbtkBlackBoxDebugMessage("object",2,"==> "<<#CLASS<<"::"<<#CLASS \
+ <<"()"<<std::endl); \
+ if (ALLOC) \
+ { \
+ bbLockDescriptor(); \
+ bbAllocateConnectors(); \
+ }
+
+//============================================================================
+
+//============================================================================
+#define BBTK_END_BLACK_BOX_CONSTRUCTOR(CLASS) \
+ bbtkBlackBoxDebugMessage("object",2,"<== "<<#CLASS<<"::"<<#CLASS \
+ <<"()"<<std::endl);
//============================================================================
//============================================================================
#define BBTK_BEGIN_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,FROM,ALLOC) \
- bbtkDebugMessageInc("Kernel",7,#CLASS<<"::"<<#CLASS \
- <<"("<<FROM.bbGetFullName()<<",\"" \
- <<bbGetName()<<"\")"<<std::endl); \
+ bbtkBlackBoxDebugMessage("object",2,"==> "<<#CLASS<<"::"<<#CLASS \
+ <<"("<<FROM.bbGetFullName() \
+ <<")"<<std::endl); \
if (ALLOC) \
{ \
+ bbLockDescriptor(); \
bbAllocateConnectors(); \
- bbCopyIOValues(FROM); \
- }
+ }
//============================================================================
-
//============================================================================
-#define BBTK_END_BLACK_BOX_CONSTRUCTOR \
- bbtkDebugDecTab("Kernel",7)
+#define BBTK_END_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,FROM,ALLOC) \
+ bbtkBlackBoxDebugMessage("object",2,"<== "<<#CLASS<<"::"<<#CLASS \
+ <<"("<<FROM.bbGetFullName() \
+ <<")"<<std::endl); \
+ if (ALLOC) \
+ { \
+ bbCopyIOValues(FROM); \
+ }
//============================================================================
//============================================================================
#define BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS) \
- bbtkDebugMessageInc("Kernel",7,#CLASS <<"::~"<< #CLASS \
- <<"() ["<<this->bbGetFullName()<<"]"<<std::endl);
-//============================================================================
-
+ bbtkBlackBoxDebugMessage("object",2,"==> "<<#CLASS <<"::~"<< #CLASS \
+ <<"()"<<std::endl); \
+ bbFinalizeProcessing();
+//============================================================================
//============================================================================
-#define BBTK_END_BLACK_BOX_DESTRUCTOR \
- bbtkDebugDecTab("Kernel",7)
+#define BBTK_END_BLACK_BOX_DESTRUCTOR(CLASS) \
+ bbtkBlackBoxDebugMessage("object",2,"<== "<<#CLASS <<"::~"<< #CLASS \
+ <<"()"<<std::endl);
+
//============================================================================
//============================================================================
/// AtomicBlackBox std implementation of ctor and dtor
-#define BBTK_USER_BLACK_BOX_IMPLEMENTATION(CLASS,PARENT) \
+#define BBTK_BLACK_BOX_IMPLEMENTATION(CLASS,PARENT) \
CLASS::CLASS(const std::string& name, bool allocate_connectors) \
: PARENT(name,false) \
{ \
BBTK_BEGIN_BLACK_BOX_CONSTRUCTOR(CLASS,allocate_connectors); \
- CLASS::bbUserConstructor(); \
- BBTK_END_BLACK_BOX_CONSTRUCTOR; \
+ CLASS::bbUserSetDefaultValues(); \
+ BBTK_END_BLACK_BOX_CONSTRUCTOR(CLASS); \
} \
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; \
+ CLASS::bbUserSetDefaultValues(); \
+ BBTK_END_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from,allocate_connectors); \
} \
CLASS::~CLASS() \
{ \
BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS); \
- CLASS::bbUserDestructor(); \
- BBTK_END_BLACK_BOX_DESTRUCTOR; \
- }
+ BBTK_END_BLACK_BOX_DESTRUCTOR(CLASS); \
+ } \
+ void CLASS::bbLockDescriptor() \
+ { \
+ bbmDescriptorPointer = CLASS ## Descriptor::Instance(); \
+ }
//============================================================================
//============================================================================
/// Begins the AtomicBlackBox description block
-#define BBTK_BEGIN_DESCRIBE_BLACK_BOX(CLASS,PARENT) \
- class /*BBTK_EXPORT*/ CLASS ## Descriptor : public PARENT ## Descriptor \
+#define BBTK_BEGIN_DESCRIBE_BLACK_BOX_BODY(CLASS) \
{ \
+ 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 '")+GetFullTypeName() \
+ +std::string("'"); \
+ } \
+ size_t GetObjectSize() const { return sizeof(*this); } \
+ bbtk::BlackBox::Pointer NewBlackBox(const std::string& name) \
{ \
- return CLASS::bbNew(name); \
+ return CLASS::New(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(); \
+ } \
+ static CLASS ## Descriptor::Pointer New() \
+ { \
+ bbtkDebugMessage("object",1,"##> "<<BBTK_STRINGIFY(CLASS) \
+ <<"Descriptor::New" <<std::endl); \
+ CLASS ## Descriptor::Pointer p = \
+ MakePointer(new CLASS ## Descriptor()); \
+ bbtkDebugMessage("object",1,"<## "<<BBTK_STRINGIFY(CLASS) \
+ <<"Descriptor::New" <<std::endl); \
+ return p; \
+ } \
+ protected: \
CLASS ## Descriptor() \
{ \
- bbtkDebugMessageInc("Kernel",9,#CLASS<<"Descriptor::"<<#CLASS \
- <<"Descriptor()"<<std::endl)
+ bbtkDebugMessage("object",2,"==> "<<#CLASS<<"Descriptor::" \
+ <<#CLASS<<"Descriptor()"<<std::endl);
+//============================================================================
+
//============================================================================
+/// Begins the AtomicBlackBox description block
+#define BBTK_BEGIN_DESCRIBE_BLACK_BOX(CLASS,PARENT) \
+ class /*BBTK_EXPORT*/ CLASS ## Descriptor : public PARENT ## Descriptor \
+ BBTK_BEGIN_DESCRIBE_BLACK_BOX_BODY(CLASS);
//============================================================================
/// Ends the AtomicBlackBox description block
#define BBTK_END_DESCRIBE_BLACK_BOX(CLASS) \
- bbtkDecTab("Kernel",9); \
+ bbtkDebugMessage("object",2,"<== "<<#CLASS<<"Descriptor::" \
+ <<#CLASS<<"Descriptor()"<<std::endl); \
} \
}; \
- void CLASS::bbCreateDescriptorIfNeeded() \
- { \
- if ( !bbDescriptorPointer() ) \
- bbDescriptorPointer() = new CLASS ## Descriptor; \
- }
+
//============================================================================
//============================================================================
/// Describes a AtomicBlackBox input (to be put inside the UBB description block)
-#define BBTK_INPUT(CLASS,NAME,DESCR,TYPE,NATURE) \
+#define BBTK_INPUT(CLASS,NAME,DESCR,TYPE,NATURE) \
AddInputDescriptor(new bbtk::AtomicBlackBoxInputDescriptor \
(typeid(CLASS ## Descriptor), \
#NAME,DESCR,NATURE, \
//============================================================================
//============================================================================
+//============================================================================
+#define BBTK_TEMPLATE_BLACK_BOX_INTERFACE(CLASS,PARENT,T) \
+ public : typedef CLASS<T> 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 T> \
- class /*BBTK_EXPORT*/ CLASS ## Descriptor : public bbtk::BlackBoxDescriptor \
+#define BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(CLASS,PARENT) \
+ template <class T> \
+ class /*BBTK_EXPORT*/ CLASS ## Descriptor : public PARENT ## Descriptor \
{ \
+ public: typedef CLASS ## Descriptor<T> Self; \
+ BBTK_OBJECT_MINIMAL_INTERFACE; \
public: \
- bbtk::BlackBox::Pointer CreateInstance(const std::string& name) \
+ std::string GetObjectName() const \
{ \
- return CLASS<T>::bbNew(name); \
+ return std::string(BBTK_STRINGIFY(CLASS)) \
+ +std::string("Descriptor<")+bbtk::TypeName<T>() \
+ +std::string("> '")+GetFullTypeName() \
+ +std::string("'"); \
+ } \
+ static Pointer New() \
+ { \
+ bbtkDebugMessage("object",1,"##> "<<BBTK_STRINGIFY(CLASS) \
+ <<"Descriptor<"<<bbtk::TypeName<T>()<<">::New" \
+ <<std::endl); \
+ Pointer p = MakePointer(new Self()); \
+ bbtkDebugMessage("object",1,"<## "<<BBTK_STRINGIFY(CLASS) \
+ <<"Descriptor<"<<bbtk::TypeName<T>()<<">::New" \
+ <<std::endl); \
+ return p; \
+ } \
+ 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 CLASS<T>::New(name); \
} \
CLASS ## Descriptor() \
{ \
- bbtkDebugMessageInc("Kernel",9,#CLASS<<"Descriptor::"<<#CLASS \
- <<"Descriptor()"<<std::endl)
+ bbtkDebugMessage("object",2,"==> "<<#CLASS<<"Descriptor<" \
+ <<bbtk::TypeName<T>()<<">::" \
+ <<#CLASS<<"Descriptor()"<<std::endl);
+
//============================================================================
//============================================================================
/// Ends a template AtomicBlackBox of template param T description block
-#define BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(CLASS) \
- bbtkDecTab("Kernel",9); \
+#define BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(CLASS) \
+ bbtkDebugMessage("object",2,"<== "<<#CLASS<<"Descriptor<" \
+ <<bbtk::TypeName<T>()<<">::" \
+ <<#CLASS<<"Descriptor()"<<std::endl); \
} \
- }; \
- template <class T> \
- void CLASS<T>::bbCreateDescriptorIfNeeded() \
- { \
- if ( !bbDescriptorPointer() ) \
- bbDescriptorPointer() = new CLASS ## Descriptor<T>; \
- }
+ };
+
//============================================================================
//============================================================================
(&CLASS<T>::bbSetOutput##NAME) ) )
//============================================================================
+
+//JCP 09JUIN2009 BBTK_EXPORT
+
//============================================================================
/// 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 T> \
CLASS<T>::CLASS(const std::string& name, bool alloc) \
: PARENT(name,false) \
{ \
- BBTK_BEGIN_BLACK_BOX_CONSTRUCTOR(CLASS<T>,alloc); \
- CLASS<T>::bbUserConstructor(); \
- BBTK_END_BLACK_BOX_CONSTRUCTOR; \
- } \
+ BBTK_BEGIN_BLACK_BOX_CONSTRUCTOR(CLASS,alloc); \
+ CLASS<T>::bbUserSetDefaultValues(); \
+ BBTK_END_BLACK_BOX_CONSTRUCTOR(CLASS); \
+ } \
template <class T> \
- CLASS<T>::CLASS(CLASS<T>& from, \
- const std::string& name, bool allocate_connectors) \
+ CLASS<T>::CLASS(CLASS<T>& from, \
+ const std::string& name, bool allocate_connectors) \
: PARENT(from,name,false) \
{ \
- BBTK_BEGIN_BLACK_BOX_COPY_CONSTRUCTOR(CLASS<T>,from,allocate_connectors); \
- CLASS<T>::bbUserCopyConstructor(); \
- BBTK_END_BLACK_BOX_CONSTRUCTOR; \
- } \
+ BBTK_BEGIN_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from,allocate_connectors); \
+ CLASS<T>::bbUserSetDefaultValues(); \
+ BBTK_END_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from,allocate_connectors); \
+ } \
template <class T> \
CLASS<T>::~CLASS() \
{ \
- BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS<T>); \
- CLASS<T>::bbUserDestructor(); \
- BBTK_END_BLACK_BOX_DESTRUCTOR; \
- }
+ BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS); \
+ BBTK_END_BLACK_BOX_DESTRUCTOR(CLASS); \
+ } \
+ template <class T> \
+ void CLASS<T>::bbLockDescriptor() \
+ { \
+ bbmDescriptorPointer = CLASS ## Descriptor<T>::Instance(); \
+ }
//============================================================================
+
+
//============================================================================
// Two template params user black boxes macros
+//============================================================================
+//============================================================================
+#define BBTK_TEMPLATE2_BLACK_BOX_INTERFACE(CLASS,PARENT,T1,T2) \
+ public : typedef CLASS<T1,T2> 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 T1, class T2> \
- class /*BBTK_EXPORT*/ CLASS ## Descriptor : public bbtk::BlackBoxDescriptor \
+ class /*BBTK_EXPORT*/ CLASS ## Descriptor : public PARENT ## Descriptor \
{ \
+ public: typedef CLASS ## Descriptor<T1,T2> Self; \
+ BBTK_OBJECT_MINIMAL_INTERFACE; \
public: \
- bbtk::BlackBox::Pointer CreateInstance(const std::string& name) \
+ std::string GetObjectName() const \
{ \
- return CLASS<T1,T2>::bbNew(name); \
+ return std::string(BBTK_STRINGIFY(CLASS)) \
+ +std::string("Descriptor<")+bbtk::TypeName<T1>() \
+ +std::string(",")+bbtk::TypeName<T2>() \
+ +std::string("> '")+GetFullTypeName() \
+ +std::string("'"); \
+ } \
+ static Pointer New() \
+ { \
+ bbtkDebugMessage("object",1,"##> "<<BBTK_STRINGIFY(CLASS) \
+ <<"Descriptor<"<<bbtk::TypeName<T1>()<<"," \
+ <<bbtk::TypeName<T2>()<<">::New"<<std::endl); \
+ Pointer p = MakePointer(new Self()); \
+ bbtkDebugMessage("object",1,"<## "<<BBTK_STRINGIFY(CLASS) \
+ <<"Descriptor<"<<bbtk::TypeName<T1>()<<"," \
+ <<bbtk::TypeName<T2>()<<">::New"<<std::endl); \
+ return p; \
+ } \
+ 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 CLASS<T1,T2>::New(name); \
} \
CLASS ## Descriptor() \
{ \
- bbtkDebugMessageInc("Kernel",9,#CLASS<<"Descriptor::"<<#CLASS \
- <<"Descriptor()"<<std::endl)
+ bbtkDebugMessage("object",2,"==> "<<#CLASS<<"Descriptor<" \
+ <<bbtk::TypeName<T1>()<<"," \
+ <<bbtk::TypeName<T2>()<<">::" \
+ <<#CLASS<<"Descriptor()"<<std::endl);
//============================================================================
//============================================================================
/// Ends a template AtomicBlackBox description block of template param T1 and T2
-#define BBTK_END_DESCRIBE_TEMPLATE2_BLACK_BOX(CLASS) \
- bbtkDecTab("Kernel",9); \
+#define BBTK_END_DESCRIBE_TEMPLATE2_BLACK_BOX(CLASS) \
+ bbtkDebugMessage("object",2,"<== "<<#CLASS<<"Descriptor<" \
+ <<bbtk::TypeName<T1>()<<"," \
+ <<bbtk::TypeName<T2>()<<">::" \
+ <<#CLASS<<"Descriptor()"<<std::endl); \
} \
- }; \
- template <class T1, class T2> \
- void CLASS<T1,T2>::bbCreateDescriptorIfNeeded() \
- { \
- if ( !bbDescriptorPointer() ) \
- bbDescriptorPointer() = new CLASS ## Descriptor<T1,T2>; \
- }
+ };
+
//============================================================================
+
+
+/*
//============================================================================
// 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 <TYPE1 T1, TYPE2 T2> \
- 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<T1,T2>(name); \
} \
#define BBTK_END_DESCRIBE_TEMPLATE2_WITH_TYPES_BLACK_BOX(CLASS,TYPE1,TYPE2) \
bbtkDecTab("Kernel",9); \
} \
- }; \
- template <TYPE1 T1, TYPE2 T2> \
- void CLASS<T1,T2>::bbCreateDescriptorIfNeeded() \
- { \
- if ( !bbDescriptorPointer() ) \
- bbDescriptorPointer() = new CLASS ## Descriptor<T1,T2>; \
- }
-//============================================================================
+ };
+//============================================================================
+*/
//============================================================================
/// Describes a 2 template params AtomicBlackBox input (to be put inside the UBB description block)
//============================================================================
/// 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 T1, class T2> \
CLASS<T1,T2>::CLASS(const std::string& name, bool alloc) \
: PARENT(name,false) \
{ \
BBTK_BEGIN_BLACK_BOX_CONSTRUCTOR(CLASS,alloc); \
- CLASS<T1,T2>::bbUserConstructor(); \
- BBTK_END_BLACK_BOX_CONSTRUCTOR; \
- } \
- template <class T1, class T2> \
- CLASS<T1,T2>::CLASS(CLASS<T1,T2>& from, \
- const std::string& name, bool allocate_connectors) \
- : PARENT(from,name,false) \
- { \
- BBTK_BEGIN_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from,allocate_connectors); \
- CLASS<T1,T2>::bbUserCopyConstructor(); \
- BBTK_END_BLACK_BOX_CONSTRUCTOR; \
+ CLASS<T1,T2>::bbUserSetDefaultValues(); \
+ BBTK_END_BLACK_BOX_CONSTRUCTOR(CLASS); \
} \
template <class T1, class T2> \
- CLASS<T1,T2>::~CLASS() \
- { \
- BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS); \
- CLASS<T1,T2>::bbUserDestructor(); \
- BBTK_END_BLACK_BOX_DESTRUCTOR; \
- }
-//============================================================================
-
-
-//============================================================================
-/// Template AtomicBlackBox std implementation of ctor and dtor
-#define BBTK_USER_BLACK_BOX_TEMPLATE2_WITH_TYPES_IMPLEMENTATION(CLASS,PARENT,TYPE1,TYPE2) \
- template <TYPE1 T1, TYPE2 T2> \
- CLASS<T1,T2>::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 <TYPE1 T1, TYPE2 T2> \
CLASS<T1,T2>::CLASS(CLASS<T1,T2>& 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; \
+ CLASS<T1,T2>::bbUserSetDefaultValues(); \
+ BBTK_END_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from,allocate_connectors); \
} \
- template <TYPE1 T1, TYPE2 T2> \
+ template <class T1, class T2> \
CLASS<T1,T2>::~CLASS() \
{ \
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();*/ }
-//===========================================================================
-
-
-
-
-//===========================================================================
+ BBTK_END_BLACK_BOX_DESTRUCTOR(CLASS); \
+ } \
+ template <class T1, class T2> \
+ void CLASS<T1,T2>::bbLockDescriptor() \
+ { \
+ bbmDescriptorPointer = CLASS ## Descriptor<T1,T2>::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<TYPE>(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();*/ }
-//===========================================================================