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