]> Creatis software - bbtk.git/blob - kernel/src/bbtkAtomicBlackBoxMacros.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkAtomicBlackBoxMacros.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkAtomicBlackBoxMacros.h,v $
5   Language:  C++
6   Date:      $Date: 2008/05/06 07:36:42 $
7   Version:   $Revision: 1.8 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18
19
20 /**
21  *  \file 
22  *  \brief Defines macros for the creation of new user black boxes
23  */
24 #ifndef __bbtkAtomicBlackBoxMacros_h__
25 #define __bbtkAtomicBlackBoxMacros_h__
26
27 //============================================================================
28 /// Declares the standard interface of a AtomicBlackBox 
29 /// (ctor, New, descriptor related methods)
30 #define BBTK_BLACK_BOX_INTERFACE_INTERNAL(CLASS,PARENT)         \
31   BBTK_OBJECT_MINIMAL_INTERFACE;                                \
32   private:                                                              \
33   protected:                                                            \
34   CLASS(const std::string& name, bool allocate_connectors = true);      \
35   CLASS(Self& from, const std::string& name,                            \
36         bool allocate_connectors = true);                               \
37   ~CLASS();                                                             \
38   public:                                                               \
39   std::string GetObjectName() const                                     \
40   { return std::string(#CLASS)+std::string(" '")                        \
41       +bbGetNameWithParent()+std::string("'"); }                        \
42   inline static Pointer New(const std::string& name)                    \
43   {                                                                     \
44     bbtkDebugMessage("object",1,"##> "<<#CLASS                          \
45                      <<"::New(\""<<name<<"\")"<<std::endl);             \
46     Pointer p = MakeBlackBoxPointer(new Self(name));                    \
47     bbtkDebugMessage("object",1,"<## "<<#CLASS                          \
48                      <<"::New(\""<<name<<"\")"<<std::endl);             \
49     return p;                                                           \
50   }                                                                     \
51   inline bbtk::BlackBox::Pointer bbClone(const std::string& name)       \
52   {                                                                     \
53     bbtkDebugMessage("object",1,"##> "<<#CLASS                          \
54                      <<"::bbClone(\""<<name<<"\")"<<std::endl);         \
55     Pointer p = MakeBlackBoxPointer(new Self(*this,name));              \
56     bbtkDebugMessage("object",1,"<## "<<#CLASS                          \
57                      <<"::bbClone(\""<<name<<"\")"<<std::endl);         \
58     return p;                                                           \
59   }                                                                     \
60   virtual void bbLockDescriptor();                                      \
61   private:                                                              \
62   CLASS() : PARENT("") {}                                               \
63   CLASS(const CLASS&) : PARENT("") {}                                   
64
65 //============================================================================
66
67 //============================================================================
68 #define BBTK_BLACK_BOX_INTERFACE(CLASS,PARENT)  \
69   public : typedef CLASS Self;                          \
70   BBTK_BLACK_BOX_INTERFACE_INTERNAL(CLASS,PARENT);
71 //============================================================================
72
73 //============================================================================
74 /// Defines the bbUserProcess method
75 #define BBTK_PROCESS(CALLBACK)                                          \
76   public:                                                               \
77   inline void bbUserProcess()                                           \
78   {                                                                     \
79     bbtkDebugMessage("process",1,"**> Processing ["<<bbGetFullName()    \
80                      <<"]"<<std::endl);                                 \
81     CALLBACK();                                                         \
82     bbtkDebugMessage("process",2,"<** Processing ["<<bbGetFullName()    \
83                      <<"]"<<std::endl);                                 \
84   }
85 //============================================================================
86
87
88 //============================================================================
89 /// Declares a new AtomicBlackBox input (to be put in the class interface)
90 #define BBTK_DECLARE_INPUT(NAME,TYPE)                                   \
91   protected:                                                            \
92   TYPE bbmInput##NAME;                                                  \
93   public:                                                               \
94   TYPE bbGetInput##NAME ()                                              \
95   { return bbmInput##NAME; }                                            \
96   void bbSetInput##NAME (TYPE d)                                        \
97   { bbmInput##NAME = d;                                                 \
98     /*bbSetModifiedStatus();*/ }                                
99 //============================================================================
100
101 //============================================================================
102 /// Declares a new AtomicBlackBox output (to be put in the class interface)
103 #define BBTK_DECLARE_OUTPUT(NAME,TYPE)                                  \
104   protected:                                                            \
105   TYPE bbmOutput##NAME;                                                 \
106   public:                                                               \
107   TYPE bbGetOutput##NAME ()                                             \
108   { return bbmOutput##NAME; }                                           \
109   void  bbSetOutput##NAME (TYPE d)                                      \
110   { bbmOutput##NAME = d; }                                      
111 //============================================================================
112
113 //============================================================================
114 /// Declares an inherited AtomicBlackBox input (to be put in the class interface)
115 #define BBTK_DECLARE_INHERITED_INPUT(NAME,TYPE,GETMETHOD,SETMETHOD)     \
116   public:                                                               \
117   TYPE bbGetInput##NAME ()                                              \
118   { return GETMETHOD(); }                                               \
119   void bbSetInput##NAME (TYPE d)                                        \
120   { SETMETHOD(d);                                                       \
121     /*bbSetModifiedStatus();*/ }                        
122 //============================================================================
123
124
125 //============================================================================
126 /// Declares an inherited AtomicBlackBox output (to be put in the class interface)
127 #define BBTK_DECLARE_INHERITED_OUTPUT(NAME,TYPE,GETMETHOD,SETMETHOD)    \
128   public:                                                               \
129   TYPE bbGetOutput##NAME () const                                       \
130   { return GETMETHOD(); }                                               \
131   void bbSetOutput##NAME (TYPE d)                                       \
132   { SETMETHOD(d); }                                                     
133 //============================================================================
134
135
136
137 //============================================================================
138 #define BBTK_BEGIN_BLACK_BOX_CONSTRUCTOR(CLASS,ALLOC)                   \
139   bbtkDebugMessage("object",2,"==> "<<#CLASS<<"::"<<#CLASS              \
140                    <<"(\""<<bbGetName()<<"\")"<<std::endl);             \
141   if (ALLOC)                                                            \
142     {                                                                   \
143       bbLockDescriptor();                                               \
144       bbAllocateConnectors();                                           \
145     }
146 //============================================================================
147
148 //============================================================================
149 #define BBTK_END_BLACK_BOX_CONSTRUCTOR(CLASS)                           \
150   bbtkDebugMessage("object",2,"<== "<<#CLASS<<"::"<<#CLASS              \
151                    <<"(\""<<bbGetName()<<"\")"<<std::endl);             
152 //============================================================================
153
154 //============================================================================
155 #define BBTK_BEGIN_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,FROM,ALLOC)         \
156   bbtkDebugMessageInc("object",2,"==> "<<#CLASS<<"::"<<#CLASS           \
157                       <<"("<<FROM.bbGetFullName()<<",\""                \
158                       <<bbGetName()<<"\")"<<std::endl);                 \
159   if (ALLOC)                                                            \
160     {                                                                   \
161       bbLockDescriptor();                                               \
162       bbAllocateConnectors();                                           \
163       bbCopyIOValues(FROM);                                             \
164    }
165 //============================================================================
166
167 //============================================================================
168 #define BBTK_END_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,FROM)                 \
169   bbtkDebugMessage("object",2,"<== "<<#CLASS<<"::"<<#CLASS              \
170                    <<"("<<FROM.bbGetFullName()<<",\""                   \
171                    <<bbGetName()<<"\")"<<std::endl);            
172 //============================================================================
173
174 //============================================================================
175 #define BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS)                          \
176   bbtkDebugMessage("object",2,"==> "<<#CLASS <<"::~"<< #CLASS           \
177                    <<"() ["<<this->bbGetFullName()<<"]"<<std::endl);
178 //============================================================================
179
180 //============================================================================
181 #define BBTK_END_BLACK_BOX_DESTRUCTOR(CLASS)                            \
182   bbtkDebugMessage("object",2,"<== "<<#CLASS <<"::~"<< #CLASS           \
183                    <<"() ["<<this->bbGetFullName()<<"]"<<std::endl);
184
185 //============================================================================
186
187
188 //============================================================================
189 /// AtomicBlackBox std implementation of ctor and dtor
190 #define BBTK_BLACK_BOX_IMPLEMENTATION(CLASS,PARENT)             \
191   CLASS::CLASS(const std::string& name, bool allocate_connectors)       \
192     : PARENT(name,false)                                                \
193   {                                                                     \
194     BBTK_BEGIN_BLACK_BOX_CONSTRUCTOR(CLASS,allocate_connectors);        \
195     CLASS::bbUserConstructor();                                         \
196     BBTK_END_BLACK_BOX_CONSTRUCTOR(CLASS);                              \
197   }                                                                     \
198   CLASS::CLASS(CLASS& from,                                             \
199                const std::string& name, bool allocate_connectors)       \
200     : PARENT(from,name,false)                                           \
201   {                                                                     \
202     BBTK_BEGIN_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from,allocate_connectors); \
203     CLASS::bbUserCopyConstructor();                                     \
204     BBTK_END_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from);                    \
205   }                                                                     \
206   CLASS::~CLASS()                                                       \
207   {                                                                     \
208     BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS);                             \
209     CLASS::bbUserDestructor();                                          \
210     BBTK_END_BLACK_BOX_DESTRUCTOR(CLASS);                               \
211   }                                                                     \
212   void CLASS::bbLockDescriptor()                                        \
213   {                                                                     \
214     bbmDescriptorPointer = CLASS ## Descriptor::Instance();             \
215   }
216 //============================================================================
217
218
219 //============================================================================
220 /// Begins the AtomicBlackBox description block
221 #define BBTK_BEGIN_DESCRIBE_BLACK_BOX(CLASS,PARENT)                     \
222   class /*BBTK_EXPORT*/ CLASS ## Descriptor : public PARENT ## Descriptor \
223   {                                                                     \
224   public: typedef CLASS ## Descriptor Self;                             \
225     BBTK_OBJECT_MINIMAL_INTERFACE;                                      \
226   public:                                                               \
227     std::string GetObjectName() const                                   \
228     {                                                                   \
229       return std::string(BBTK_STRINGIFY(CLASS))                         \
230         +std::string("Descriptor '")+GetFullTypeName()                  \
231         +std::string("'");                                              \
232     }                                                                   \
233     size_t GetObjectSize() const { return sizeof(*this); }              \
234     bbtk::BlackBox::Pointer NewBlackBox(const std::string& name)        \
235     {                                                                   \
236       return CLASS::New(name);                                          \
237     }                                                                   \
238     virtual bbtk::AtomicBlackBoxDescriptor::Pointer GetInstance()       const \
239       {                                                                 \
240         return Instance();                                              \
241       }                                                                 \
242     static bbtk::AtomicBlackBoxDescriptor::Pointer Instance()                   \
243       {                                                                 \
244         static bbtk::AtomicBlackBoxDescriptor::WeakPointer i;                   \
245         bbtk::AtomicBlackBoxDescriptor::Pointer j;                              \
246         if (!i.lock()) { j = Self::New(); i = j; }                      \
247         return i.lock();                                                \
248       }                                                                 \
249     static CLASS ## Descriptor::Pointer New()                           \
250       {                                                                 \
251         bbtkDebugMessage("object",1,"##> "<<BBTK_STRINGIFY(CLASS)       \
252                          <<"Descriptor::New" <<std::endl);              \
253         CLASS ## Descriptor::Pointer p =                                \
254           MakePointer(new CLASS ## Descriptor());                       \
255         bbtkDebugMessage("object",1,"<## "<<BBTK_STRINGIFY(CLASS)       \
256                          <<"Descriptor::New" <<std::endl);              \
257         return p;                                                       \
258       }                                                                 \
259   protected:                                                            \
260     CLASS ## Descriptor()                                               \
261       {                                                                 \
262         bbtkDebugMessage("object",2,"==> "<<#CLASS<<"Descriptor::"      \
263                          <<#CLASS<<"Descriptor()"<<std::endl);          
264 //============================================================================
265
266 //============================================================================
267 /// Ends the AtomicBlackBox description block
268 #define BBTK_END_DESCRIBE_BLACK_BOX(CLASS)                              \
269   bbtkDebugMessage("object",2,"<== "<<#CLASS<<"Descriptor::"            \
270                    <<#CLASS<<"Descriptor()"<<std::endl);                \
271   }                                                                     \
272   };                                                                    \
273   
274 //============================================================================
275
276
277 //============================================================================
278 /// Declares the name of a AtomicBlackBox (to be put inside the UBB description block)
279 #define BBTK_NAME(NAME) SetTypeName(NAME)
280 //============================================================================
281
282 //============================================================================
283 /// Declares the author of a AtomicBlackBox (to be put inside the UBB description block)
284 #define BBTK_AUTHOR(AUTHOR) AddToAuthor(AUTHOR)
285 //============================================================================
286
287 //============================================================================
288 /// Declares the categories of a AtomicBlackBox (to be put inside the UBB description block)
289 #define BBTK_CATEGORY(CATEGORY) AddToCategory(CATEGORY)
290 //============================================================================
291
292 //============================================================================
293 /// Declares the description of a AtomicBlackBox (to be put inside the UBB description block)
294 #define BBTK_DESCRIPTION(DESCR) AddToDescription(DESCR)
295 //============================================================================
296
297 //============================================================================
298 /// Declares the kind of a AtomicBlackBox (to be put inside the UBB description block)
299 //#define BBTK_KIND(KIND) SetKind(KIND)
300 //============================================================================
301
302 //============================================================================
303 /// Declares that the AtomicBlackBox is an adaptor (to be put inside the UBB description block)
304 #define BBTK_ADAPTOR()                        \
305   SetKind(bbtk::BlackBoxDescriptor::ADAPTOR); \
306   AddToCategory("adaptor")
307 //============================================================================
308
309 //============================================================================
310 /// Declares that the AtomicBlackBox is the default adaptor of the package (to be put inside the UBB description block)
311 #define BBTK_DEFAULT_ADAPTOR()                          \
312   SetKind(bbtk::BlackBoxDescriptor::DEFAULT_ADAPTOR);   \
313   AddToCategory("adaptor")
314 //============================================================================
315
316
317 //============================================================================
318 /// Describes a AtomicBlackBox input (to be put inside the UBB description block)
319 #define BBTK_INPUT(CLASS,NAME,DESCR,TYPE,NATURE)                        \
320   AddInputDescriptor(new bbtk::AtomicBlackBoxInputDescriptor            \
321                      (typeid(CLASS ## Descriptor),                      \
322                       #NAME,DESCR,NATURE,                               \
323                       new bbtk::AtomicBlackBoxTGetFunctor<CLASS,TYPE,TYPE > \
324                       (&CLASS::bbGetInput##NAME),                       \
325                       new bbtk::AtomicBlackBoxTSetFunctor<CLASS,TYPE,TYPE > \
326                       (&CLASS::bbSetInput##NAME) ) )
327 //============================================================================
328
329 //============================================================================
330 /// Describes a AtomicBlackBox output (to be put inside the UBB description block)
331 #define BBTK_OUTPUT(CLASS,NAME,DESCR,TYPE,NATURE)                       \
332   AddOutputDescriptor(new bbtk::AtomicBlackBoxOutputDescriptor          \
333                       (typeid(CLASS ## Descriptor),#NAME,DESCR,NATURE,  \
334                        new bbtk::AtomicBlackBoxTGetFunctor<CLASS,TYPE,TYPE > \
335                        (&CLASS::bbGetOutput##NAME),                     \
336                        new bbtk::AtomicBlackBoxTSetFunctor<CLASS,TYPE,TYPE > \
337                        (&CLASS::bbSetOutput##NAME) ) )
338 //============================================================================
339
340
341 //============================================================================
342 /// Describes a AtomicBlackBox input (to be put inside the UBB description block)
343 #define BBTK_INPUT_NOCOPY(CLASS,NAME,DESCR,TYPE,NATURE)                 \
344   AddInputDescriptor(new bbtk::AtomicBlackBoxInputDescriptor            \
345                      (typeid(CLASS ## Descriptor),#NAME,DESCR,NATURE,   \
346                       new bbtk::AtomicBlackBoxTGetFunctor<CLASS,TYPE,TYPE > \
347                       (&CLASS::bbGetInput##NAME),                       \
348                       new bbtk::AtomicBlackBoxTSetFunctor<CLASS,TYPE,TYPE > \
349                       (&CLASS::bbSetInput##NAME),                       \
350                       false) )
351 //============================================================================
352
353 //============================================================================
354 /// Describes a AtomicBlackBox output (to be put inside the UBB description block)
355 #define BBTK_OUTPUT_NOCOPY(CLASS,NAME,DESCR,TYPE,NATURE)                \
356   AddOutputDescriptor(new bbtk::AtomicBlackBoxOutputDescriptor          \
357                       (typeid(CLASS ## Descriptor),#NAME,DESCR,NATURE,  \
358                        new bbtk::AtomicBlackBoxTGetFunctor<CLASS,TYPE,TYPE > \
359                        (&CLASS::bbGetOutput##NAME),                     \
360                        new bbtk::AtomicBlackBoxTSetFunctor<CLASS,TYPE,TYPE > \
361                        (&CLASS::bbSetOutput##NAME),\
362                        false) )
363 //============================================================================
364
365
366
367
368
369
370
371
372
373
374 //============================================================================
375 //============================================================================
376 // Template user black boxes macros
377 //============================================================================
378 //============================================================================
379
380 //============================================================================
381 #define BBTK_TEMPLATE_BLACK_BOX_INTERFACE(CLASS,PARENT,T)       \
382   public : typedef CLASS<T> Self;                               \
383   BBTK_BLACK_BOX_INTERFACE_INTERNAL(CLASS,PARENT);
384 //============================================================================
385
386 //============================================================================
387 /// Begins a template AtomicBlackBox of template param T description block
388 #define BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(CLASS,PARENT)            \
389   template <class T>                                                    \
390   class /*BBTK_EXPORT*/ CLASS ## Descriptor : public PARENT ## Descriptor \
391   {                                                                     \
392   public: typedef CLASS ## Descriptor<T> Self;                          \
393     BBTK_OBJECT_MINIMAL_INTERFACE;                                      \
394   public:                                                               \
395     std::string GetObjectName() const                                   \
396     {                                                                   \
397       return std::string(BBTK_STRINGIFY(CLASS))                         \
398         +std::string("Descriptor<")+bbtk::TypeName<T>()                 \
399         +std::string("> '")+GetFullTypeName()                           \
400         +std::string("'");                                              \
401     }                                                                   \
402     static Pointer New()                                                \
403       {                                                                 \
404         bbtkDebugMessage("object",1,"##> "<<BBTK_STRINGIFY(CLASS)       \
405                          <<"Descriptor<"<<bbtk::TypeName<T>()<<">::New" \
406                          <<std::endl);                                  \
407         Pointer p = MakePointer(new Self());                            \
408         bbtkDebugMessage("object",1,"<## "<<BBTK_STRINGIFY(CLASS)       \
409                          <<"Descriptor<"<<bbtk::TypeName<T>()<<">::New" \
410                          <<std::endl);                                  \
411         return p;                                                       \
412       }                                                                 \
413     virtual bbtk::AtomicBlackBoxDescriptor::Pointer GetInstance()       const \
414       {                                                                 \
415         return Instance();                                              \
416       }                                                                 \
417     static bbtk::AtomicBlackBoxDescriptor::Pointer Instance()           \
418       {                                                                 \
419         static bbtk::AtomicBlackBoxDescriptor::WeakPointer i;           \
420         bbtk::AtomicBlackBoxDescriptor::Pointer j;                      \
421         if (!i.lock()) { j = Self::New(); i = j; }                      \
422         return i.lock();                                                \
423       }                                                                 \
424     bbtk::BlackBox::Pointer NewBlackBox(const std::string& name)        \
425     {                                                                   \
426       return CLASS<T>::New(name);                                       \
427     }                                                                   \
428     CLASS ## Descriptor()                                               \
429       {                                                                 \
430         bbtkDebugMessage("object",2,"==> "<<#CLASS<<"Descriptor<"       \
431                          <<bbtk::TypeName<T>()<<">::"                   \
432                          <<#CLASS<<"Descriptor()"<<std::endl);          
433
434 //============================================================================
435
436 //============================================================================
437 /// Ends a template AtomicBlackBox of template param T description block
438 #define BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(CLASS)                     \
439   bbtkDebugMessage("object",2,"<== "<<#CLASS<<"Descriptor<"             \
440                    <<bbtk::TypeName<T>()<<">::"                         \
441                    <<#CLASS<<"Descriptor()"<<std::endl);                \
442   }                                                                     \
443   };                                                                    
444
445 //============================================================================
446
447 //============================================================================
448 /// Describes a template AtomicBlackBox input (to be put inside the template UBB description block)
449 #define BBTK_TEMPLATE_INPUT(CLASS,NAME,DESCR,TYPE)                      \
450   AddInputDescriptor(new bbtk::AtomicBlackBoxInputDescriptor            \
451                      (typeid(CLASS ## Descriptor),#NAME,DESCR,"",       \
452                       new bbtk::AtomicBlackBoxTGetFunctor<CLASS<T>,TYPE,TYPE > \
453                       (&CLASS<T>::bbGetInput##NAME),                    \
454                       new bbtk::AtomicBlackBoxTSetFunctor<CLASS<T>,TYPE,TYPE > \
455                       (&CLASS<T>::bbSetInput##NAME) ) )
456 //============================================================================
457
458 //============================================================================
459 /// Describes a template AtomicBlackBox output (to be put inside the template UBB description block)
460 #define BBTK_TEMPLATE_OUTPUT(CLASS,NAME,DESCR,TYPE)                     \
461   AddOutputDescriptor(new bbtk::AtomicBlackBoxOutputDescriptor          \
462                       (typeid(CLASS ## Descriptor),#NAME,DESCR,"",      \
463                        new bbtk::AtomicBlackBoxTGetFunctor<CLASS<T>,TYPE,TYPE > \
464                        (&CLASS<T>::bbGetOutput##NAME),                  \
465                        new bbtk::AtomicBlackBoxTSetFunctor<CLASS<T>,TYPE,TYPE > \
466                        (&CLASS<T>::bbSetOutput##NAME) ) )
467 //============================================================================
468
469 //============================================================================
470 /// Template AtomicBlackBox std implementation of ctor and dtor
471 #define BBTK_BLACK_BOX_TEMPLATE_IMPLEMENTATION(CLASS,PARENT)            \
472   template <class T>                                                    \
473   CLASS<T>::CLASS(const std::string& name, bool alloc)                  \
474     : PARENT(name,false)                                                \
475   {                                                                     \
476     BBTK_BEGIN_BLACK_BOX_CONSTRUCTOR(CLASS,alloc);                      \
477     CLASS<T>::bbUserConstructor();                                      \
478     BBTK_END_BLACK_BOX_CONSTRUCTOR(CLASS);                              \
479   }                                                                     \
480   template <class T>                                                    \
481   CLASS<T>::CLASS(CLASS<T>& from,                                       \
482                   const std::string& name, bool allocate_connectors)    \
483     : PARENT(from,name,false)                                           \
484   {                                                                     \
485     BBTK_BEGIN_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from,allocate_connectors); \
486     CLASS<T>::bbUserCopyConstructor();                                  \
487     BBTK_END_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from);                    \
488   }                                                                     \
489   template <class T>                                                    \
490   CLASS<T>::~CLASS()                                                    \
491   {                                                                     \
492     BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS);                             \
493     CLASS<T>::bbUserDestructor();                                       \
494     BBTK_END_BLACK_BOX_DESTRUCTOR(CLASS);                               \
495   }                                                                     \
496   template <class T>                                                    \
497   void CLASS<T>::bbLockDescriptor()                                     \
498   {                                                                     \
499     bbmDescriptorPointer = CLASS ## Descriptor<T>::Instance();          \
500   }
501 //============================================================================
502
503
504
505 //============================================================================
506 // Two template params user black boxes macros
507 //============================================================================
508
509 //============================================================================
510 #define BBTK_TEMPLATE2_BLACK_BOX_INTERFACE(CLASS,PARENT,T1,T2)  \
511   public : typedef CLASS<T1,T2> Self;                                   \
512   BBTK_BLACK_BOX_INTERFACE_INTERNAL(CLASS,PARENT);
513 //===========================================================================
514
515 //============================================================================
516 /// Begins a template AtomicBlackBox description block of template param T1 and T2 
517 #define BBTK_BEGIN_DESCRIBE_TEMPLATE2_BLACK_BOX(CLASS,PARENT)           \
518   template <class T1, class T2>                                         \
519   class /*BBTK_EXPORT*/ CLASS ## Descriptor : public PARENT ## Descriptor \
520   {                                                                     \
521   public: typedef CLASS ## Descriptor<T1,T2> Self;                      \
522     BBTK_OBJECT_MINIMAL_INTERFACE;                                      \
523   public:                                                               \
524     std::string GetObjectName() const                                   \
525     {                                                                   \
526       return std::string(BBTK_STRINGIFY(CLASS))                         \
527         +std::string("Descriptor<")+bbtk::TypeName<T1>()                \
528         +std::string(",")+bbtk::TypeName<T2>()                          \
529         +std::string("> '")+GetFullTypeName()                           \
530         +std::string("'");                                              \
531     }                                                                   \
532     static Pointer New()                                                \
533       {                                                                 \
534         bbtkDebugMessage("object",1,"##> "<<BBTK_STRINGIFY(CLASS)       \
535                          <<"Descriptor<"<<bbtk::TypeName<T1>()<<","     \
536                          <<bbtk::TypeName<T2>()<<">::New"<<std::endl);  \
537         Pointer p = MakePointer(new Self());                            \
538         bbtkDebugMessage("object",1,"<## "<<BBTK_STRINGIFY(CLASS)       \
539                          <<"Descriptor<"<<bbtk::TypeName<T1>()<<","     \
540                          <<bbtk::TypeName<T2>()<<">::New"<<std::endl);  \
541         return p;                                                       \
542       }                                                                 \
543     virtual bbtk::AtomicBlackBoxDescriptor::Pointer GetInstance() const \
544       {                                                                 \
545         return Instance();                                              \
546       }                                                                 \
547     static bbtk::AtomicBlackBoxDescriptor::Pointer Instance()           \
548       {                                                                 \
549         static bbtk::AtomicBlackBoxDescriptor::WeakPointer i;           \
550         bbtk::AtomicBlackBoxDescriptor::Pointer j;                      \
551         if (!i.lock()) { j = Self::New(); i = j; }                      \
552         return i.lock();                                                \
553       }                                                                 \
554     bbtk::BlackBox::Pointer NewBlackBox(const std::string& name)        \
555     {                                                                   \
556       return CLASS<T1,T2>::New(name);                                   \
557     }                                                                   \
558     CLASS ## Descriptor()                                               \
559       {                                                                 \
560         bbtkDebugMessage("object",2,"==> "<<#CLASS<<"Descriptor<"       \
561                          <<bbtk::TypeName<T1>()<<","                    \
562                          <<bbtk::TypeName<T2>()<<">::"                  \
563                          <<#CLASS<<"Descriptor()"<<std::endl);          
564 //============================================================================
565
566 //============================================================================
567 /// Ends a template AtomicBlackBox description block of template param T1 and T2
568 #define BBTK_END_DESCRIBE_TEMPLATE2_BLACK_BOX(CLASS)                    \
569   bbtkDebugMessage("object",2,"<== "<<#CLASS<<"Descriptor<"             \
570                    <<bbtk::TypeName<T1>()<<","                          \
571                    <<bbtk::TypeName<T2>()<<">::"                        \
572                    <<#CLASS<<"Descriptor()"<<std::endl);                \
573   }                                                                     \
574   };                                                                    
575
576 //============================================================================
577
578
579
580 /*
581 //============================================================================
582 // Two template params user black boxes macros
583
584 /// Begins a template AtomicBlackBox description block of template param T1 and T2 
585 #define BBTK_BEGIN_DESCRIBE_TEMPLATE2_WITH_TYPES_BLACK_BOX(CLASS,TYPE1,TYPE2)           \
586   template <TYPE1 T1, TYPE2 T2>                                         \
587   class  CLASS ## Descriptor : public bbtk::BlackBoxDescriptor          \
588   {                                                                     \
589   public:                                                               \
590     virtual bbtk:AtomicBlackBoxDescriptor::Pointer GetInstance()        const   \
591       {                                                                 \
592         return Instance();                                              \
593       }                                                                 \
594     static bbtk:AtomicBlackBoxDescriptor::Pointer Instance()                    \
595       {                                                                 \
596         static bbtk:AtomicBlackBoxDescriptor::WeakPointer i;                    \
597         bbtk:AtomicBlackBoxDescriptor::Pointer j;                               \
598         if (!i.lock()) { j = Self::New(); i = j; }                      \
599         return i.lock();                                                \
600       }                                                                 \
601     bbtk::BlackBox::Pointer NewBlackBox(const std::string& name)        \
602     {                                                                   \
603       return new CLASS<T1,T2>(name);                                    \
604     }                                                                   \
605     CLASS ## Descriptor()                                               \
606       {                                                                 \
607       bbtkDebugMessageInc("Kernel",9,#CLASS<<"Descriptor::"<<#CLASS     \
608                           <<"Descriptor()"<<std::endl)
609 //============================================================================
610
611 //============================================================================
612 /// Ends a template AtomicBlackBox description block of template param T1 and T2
613 #define BBTK_END_DESCRIBE_TEMPLATE2_WITH_TYPES_BLACK_BOX(CLASS,TYPE1,TYPE2)     \
614   bbtkDecTab("Kernel",9);                                                       \
615   }                                                                     \
616   };                                                                    
617
618 //============================================================================
619
620 */
621
622 //============================================================================
623 /// Describes a 2 template params AtomicBlackBox input (to be put inside the UBB description block)
624 #define BBTK_TEMPLATE2_INPUT(CLASS,NAME,DESCR,TYPE)                     \
625   AddInputDescriptor(new bbtk::AtomicBlackBoxInputDescriptor            \
626                      (typeid(CLASS ## Descriptor),#NAME,DESCR,"",       \
627                       new bbtk::AtomicBlackBoxTGetFunctor<CLASS<T1,T2>,TYPE,TYPE >      \
628                       (&CLASS<T1,T2>::bbGetInput##NAME),                \
629                       new bbtk::AtomicBlackBoxTSetFunctor<CLASS<T1,T2>,TYPE,TYPE >      \
630                       (&CLASS<T1,T2>::bbSetInput##NAME) ) )
631 //============================================================================
632
633 //============================================================================
634 /// Describes a 2 template params AtomicBlackBox output (to be put inside the UBB description block)
635 #define BBTK_TEMPLATE2_OUTPUT(CLASS,NAME,DESCR,TYPE)                    \
636   AddOutputDescriptor(new bbtk::AtomicBlackBoxOutputDescriptor          \
637                       (typeid(CLASS ## Descriptor),#NAME,DESCR,"",      \
638                        new bbtk::AtomicBlackBoxTGetFunctor<CLASS<T1,T2>,TYPE,TYPE > \
639                        (&CLASS<T1,T2>::bbGetOutput##NAME),              \
640                        new bbtk::AtomicBlackBoxTSetFunctor<CLASS<T1,T2>,TYPE,TYPE > \
641                        (&CLASS<T1,T2>::bbSetOutput##NAME) ) )
642 //============================================================================
643
644 //============================================================================
645 /// Template AtomicBlackBox std implementation of ctor and dtor
646 #define BBTK_BLACK_BOX_TEMPLATE2_IMPLEMENTATION(CLASS,PARENT)           \
647   template <class T1, class T2>                                         \
648   CLASS<T1,T2>::CLASS(const std::string& name, bool alloc)              \
649     : PARENT(name,false)                                                \
650   {                                                                     \
651     BBTK_BEGIN_BLACK_BOX_CONSTRUCTOR(CLASS,alloc);                      \
652     CLASS<T1,T2>::bbUserConstructor();                                  \
653     BBTK_END_BLACK_BOX_CONSTRUCTOR(CLASS);                              \
654   }                                                                     \
655   template <class T1, class T2>                                         \
656   CLASS<T1,T2>::CLASS(CLASS<T1,T2>& from,                               \
657                       const std::string& name, bool allocate_connectors) \
658     : PARENT(from,name,false)                                           \
659   {                                                                     \
660     BBTK_BEGIN_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from,allocate_connectors); \
661     CLASS<T1,T2>::bbUserCopyConstructor();                              \
662     BBTK_END_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from);                    \
663   }                                                                     \
664   template <class T1, class T2>                                         \
665   CLASS<T1,T2>::~CLASS()                                                \
666   {                                                                     \
667     BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS);                             \
668     CLASS<T1,T2>::bbUserDestructor();                                   \
669     BBTK_END_BLACK_BOX_DESTRUCTOR(CLASS);                               \
670   }                                                                     \
671   template <class T1, class T2>                                         \
672   void CLASS<T1,T2>::bbLockDescriptor()                                 \
673   {                                                                     \
674     bbmDescriptorPointer = CLASS ## Descriptor<T1,T2>::Instance();      \
675   }
676 //============================================================================
677
678
679 /*
680 //============================================================================
681 /// Template AtomicBlackBox std implementation of ctor and dtor
682 #define BBTK_BLACK_BOX_TEMPLATE2_WITH_TYPES_IMPLEMENTATION(CLASS,PARENT,TYPE1,TYPE2) \
683   template <TYPE1 T1, TYPE2 T2>                                         \
684   CLASS<T1,T2>::CLASS(const std::string& name, bool alloc)              \
685     : PARENT(name,false)                                                \
686   {                                                                     \
687     BBTK_BEGIN_BLACK_BOX_CONSTRUCTOR(CLASS,alloc);                      \
688     this->bbUserConstructor();                                          \
689     BBTK_END_BLACK_BOX_CONSTRUCTOR;                                     \
690   }                                                                     \
691   template <TYPE1 T1, TYPE2 T2>                                         \
692   CLASS<T1,T2>::CLASS(CLASS<T1,T2>& from,                               \
693                       const std::string& name, bool allocate_connectors) \
694     : PARENT(from,name,false)                                           \
695   {                                                                     \
696     BBTK_BEGIN_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from,allocate_connectors); \
697     this->bbUserCopyConstructor();                                      \
698     BBTK_END_BLACK_BOX_CONSTRUCTOR;                                     \
699   }                                                                     \
700   template <TYPE1 T1, TYPE2 T2>                                         \
701   CLASS<T1,T2>::~CLASS()                                                \
702   {                                                                     \
703     BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS);                             \
704     this->bbUserDestructor();                                           \
705     BBTK_END_BLACK_BOX_DESTRUCTOR;                                      \
706   }                                                                     \
707   template <class T1, class T2>                                         \
708   void CLASS<T1,T2>::bbLockDescriptor()                                 \
709   {                                                                     \
710     bbmDescriptorPointer = CLASS ## Descriptor<T1,T2>::Instance();      \
711   }
712 //============================================================================
713
714 */
715
716
717
718 //===========================================================================
719 //============================================================================
720 // ITK Specific macros
721 //===========================================================================
722 //===========================================================================
723
724
725 //===========================================================================
726 /// Declares an itk-inherited AtomicBlackBox input 
727 #define BBTK_DECLARE_ITK_INPUT(PARENT,NAME,TYPE)                        \
728   public:                                                               \
729   TYPE bbGetInput##NAME ()                                              \
730   { return PARENT::GetInput(); }                                        \
731   void bbSetInput##NAME (TYPE d)                                        \
732   { PARENT::SetInput(d);                                                \
733     /*bbSetModifiedStatus();*/ }                                                       
734 //===========================================================================
735
736 //===========================================================================
737 #define BBTK_DECLARE_ITK_OUTPUT(PARENT,NAME,TYPE)                       \
738   public:                                                               \
739   TYPE bbGetOutput##NAME ()                                             \
740   { return PARENT::GetOutput(); }                                       \
741   void bbSetOutput##NAME (TYPE d)                                       \
742   { /*PARENT::GetOutput() = d;*/ }                                      
743 //===========================================================================
744
745 //===========================================================================
746 /// Declares an AtomicBlackBox input corresponding to an inherited itk parameter
747 /// which was declared by itkSetMacro/itkGetMacro
748 /// The NAME **MUST** be the same than the itk parameter name
749 #define BBTK_DECLARE_ITK_PARAM(PARENT,NAME,TYPE)                        \
750   public:                                                               \
751   TYPE bbGetInput##NAME ()                                              \
752   { return PARENT::Get##NAME(); }                                       \
753   void bbSetInput##NAME (TYPE d)                                        \
754   { PARENT::Set##NAME(d);                                               \
755     /*bbSetModifiedStatus();*/ }
756 //===========================================================================
757
758
759
760
761 //===========================================================================
762 //============================================================================
763 // VTK Specific macros
764 //===========================================================================
765 //===========================================================================
766
767
768 //===========================================================================
769
770 // EED sept 04                                                  \
771 //  { return GetInput(); /*PARENT::GetInput();*/ }              \
772 //  { PARENT::SetInput( /*(vtkDataObject*)*/ d);                                \
773
774
775
776 /// Declares a vtkImageAlgorithm-inherited AtomicBlackBox input 
777 #define BBTK_DECLARE_VTK_IMAGE_ALGORITHM_INPUT(PARENT,NAME,TYPE)                        \
778   public:                                                               \
779   TYPE bbGetInput##NAME ()                                              \
780   { return GetImageDataInput(0); /*PARENT::GetInput();*/ }              \
781   void bbSetInput##NAME (TYPE d)                                        \
782   { PARENT::SetInput( (vtkDataObject*) d);                              \
783     /*bbSetModifiedStatus();*/ }                                                       
784 //===========================================================================
785 /// Declares a vtkPolyDataAlgorithm-inherited AtomicBlackBox input 
786 #define BBTK_DECLARE_VTK_POLY_DATA_ALGORITHM_INPUT(PARENT,NAME,TYPE)    \
787   public:                                                               \
788   TYPE bbGetInput##NAME ()                                              \
789   { return GetPolyDataInput(0); /*PARENT::GetInput();*/ }               \
790   void bbSetInput##NAME (TYPE d)                                        \
791   { PARENT::SetInput( (vtkDataObject*) d);                              \
792     /*bbSetModifiedStatus();*/ }                                                       
793 //===========================================================================
794
795 //===========================================================================
796 /// Declares a vtkImageAlgorithm-inherited AtomicBlackBox output 
797 #define BBTK_DECLARE_VTK_OUTPUT(PARENT,NAME,TYPE)                       \
798   public:                                                               \
799   TYPE bbGetOutput##NAME ()                                             \
800   { return PARENT::GetOutput(); }                                       \
801   void bbSetOutput##NAME (TYPE d)                                       \
802   { /*PARENT::GetOutput() = d;*/ }                                      
803 //===========================================================================
804
805 //===========================================================================
806 /// Declares a vtkAlgorithm-inherited AtomicBlackBox input 
807 #define BBTK_DECLARE_VTK_INPUT(PARENT,NAME,TYPE)                        \
808   public:                                                               \
809   TYPE bbGetInput##NAME ()                                              \
810   { return dynamic_cast<TYPE>(PARENT::GetInput()); }                    \
811   void bbSetInput##NAME (TYPE d)                                        \
812   { PARENT::SetInput( (vtkDataObject*) d); /*PARENT::GetOutput() = d;*/ }
813
814 //===========================================================================
815
816 //===========================================================================
817 /// Declares an AtomicBlackBox input corresponding to an inherited vtk parameter
818 /// which was declared by vtkSetMacro/vtkGetMacro
819 /// The NAME **MUST** be the same than the vtk parameter name
820 #define BBTK_DECLARE_VTK_PARAM(PARENT,NAME,TYPE)                        \
821   public:                                                               \
822   TYPE bbGetInput##NAME ()                                              \
823   { return PARENT::Get##NAME(); }                                       \
824   void bbSetInput##NAME (TYPE d)                                        \
825   { PARENT::Set##NAME(d);                                               \
826     /*bbSetModifiedStatus();*/ }
827 //===========================================================================
828
829 #define BBTK_VTK_DELETE(VTKPARENT)                      \
830   void bbDelete() { VTKPARENT::Delete(); }
831
832 //===========================================================================
833 /// EOF
834 //===========================================================================
835 #endif