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