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