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