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