]> Creatis software - bbtk.git/blob - kernel/src/bbtkAtomicBlackBoxMacros.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkAtomicBlackBoxMacros.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkAtomicBlackBoxMacros.h,v $
4   Language:  C++
5   Date:      $Date: 2009/04/08 07:56:11 $
6   Version:   $Revision: 1.14 $
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(from.GetThisPointer<bbtk::BlackBox>()); \
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_BODY(CLASS)                       \
263   {                                                                     \
264   public: typedef CLASS ## Descriptor Self;                             \
265     BBTK_OBJECT_MINIMAL_INTERFACE;                                      \
266   public:                                                               \
267     std::string GetObjectName() const                                   \
268     {                                                                   \
269       return std::string(BBTK_STRINGIFY(CLASS))                         \
270         +std::string("Descriptor '")+GetFullTypeName()                  \
271         +std::string("'");                                              \
272     }                                                                   \
273     size_t GetObjectSize() const { return sizeof(*this); }              \
274     bbtk::BlackBox::Pointer NewBlackBox(const std::string& name)        \
275     {                                                                   \
276       return CLASS::New(name);                                          \
277     }                                                                   \
278     virtual bbtk::AtomicBlackBoxDescriptor::Pointer GetInstance()       const \
279       {                                                                 \
280         return Instance();                                              \
281       }                                                                 \
282     static bbtk::AtomicBlackBoxDescriptor::Pointer Instance()                   \
283       {                                                                 \
284         static bbtk::AtomicBlackBoxDescriptor::WeakPointer i;                   \
285         bbtk::AtomicBlackBoxDescriptor::Pointer j;                              \
286         if (!i.lock()) { j = Self::New(); i = j; }                      \
287         return i.lock();                                                \
288       }                                                                 \
289     static CLASS ## Descriptor::Pointer New()                           \
290       {                                                                 \
291         bbtkDebugMessage("object",1,"##> "<<BBTK_STRINGIFY(CLASS)       \
292                          <<"Descriptor::New" <<std::endl);              \
293         CLASS ## Descriptor::Pointer p =                                \
294           MakePointer(new CLASS ## Descriptor());                       \
295         bbtkDebugMessage("object",1,"<## "<<BBTK_STRINGIFY(CLASS)       \
296                          <<"Descriptor::New" <<std::endl);              \
297         return p;                                                       \
298       }                                                                 \
299   protected:                                                            \
300     CLASS ## Descriptor()                                               \
301       {                                                                 \
302         bbtkDebugMessage("object",2,"==> "<<#CLASS<<"Descriptor::"      \
303                          <<#CLASS<<"Descriptor()"<<std::endl);          
304 //============================================================================
305
306 //============================================================================
307 /// Begins the AtomicBlackBox description block
308 #define BBTK_BEGIN_DESCRIBE_BLACK_BOX(CLASS,PARENT)                     \
309   class /*BBTK_EXPORT*/ CLASS ## Descriptor : public PARENT ## Descriptor \
310   BBTK_BEGIN_DESCRIBE_BLACK_BOX_BODY(CLASS);
311
312 //============================================================================
313 /// Ends the AtomicBlackBox description block
314 #define BBTK_END_DESCRIBE_BLACK_BOX(CLASS)                              \
315   bbtkDebugMessage("object",2,"<== "<<#CLASS<<"Descriptor::"            \
316                    <<#CLASS<<"Descriptor()"<<std::endl);                \
317   }                                                                     \
318   };                                                                    \
319   
320 //============================================================================
321
322
323 //============================================================================
324 /// Declares the name of a AtomicBlackBox (to be put inside the UBB description block)
325 #define BBTK_NAME(NAME) SetTypeName(NAME)
326 //============================================================================
327
328 //============================================================================
329 /// Declares the author of a AtomicBlackBox (to be put inside the UBB description block)
330 #define BBTK_AUTHOR(AUTHOR) AddToAuthor(AUTHOR)
331 //============================================================================
332
333 //============================================================================
334 /// Declares the categories of a AtomicBlackBox (to be put inside the UBB description block)
335 #define BBTK_CATEGORY(CATEGORY) AddToCategory(CATEGORY)
336 //============================================================================
337
338 //============================================================================
339 /// Declares the description of a AtomicBlackBox (to be put inside the UBB description block)
340 #define BBTK_DESCRIPTION(DESCR) AddToDescription(DESCR)
341 //============================================================================
342
343 //============================================================================
344 /// Declares the kind of a AtomicBlackBox (to be put inside the UBB description block)
345 //#define BBTK_KIND(KIND) SetKind(KIND)
346 //============================================================================
347
348 //============================================================================
349 /// Declares that the AtomicBlackBox is an adaptor (to be put inside the UBB description block)
350 #define BBTK_ADAPTOR()                        \
351   SetKind(bbtk::BlackBoxDescriptor::ADAPTOR); \
352   AddToCategory("adaptor")
353 //============================================================================
354
355 //============================================================================
356 /// Declares that the AtomicBlackBox is the default adaptor of the package (to be put inside the UBB description block)
357 #define BBTK_DEFAULT_ADAPTOR()                          \
358   SetKind(bbtk::BlackBoxDescriptor::DEFAULT_ADAPTOR);   \
359   AddToCategory("adaptor")
360 //============================================================================
361
362
363 //============================================================================
364 /// Describes a AtomicBlackBox input (to be put inside the UBB description block)
365 #define BBTK_INPUT(CLASS,NAME,DESCR,TYPE,NATURE)                        \
366   AddInputDescriptor(new bbtk::AtomicBlackBoxInputDescriptor            \
367                      (typeid(CLASS ## Descriptor),                      \
368                       #NAME,DESCR,NATURE,                               \
369                       new bbtk::AtomicBlackBoxTGetFunctor<CLASS,TYPE,TYPE > \
370                       (&CLASS::bbGetInput##NAME),                       \
371                       new bbtk::AtomicBlackBoxTSetFunctor<CLASS,TYPE,TYPE > \
372                       (&CLASS::bbSetInput##NAME) ) )
373 //============================================================================
374
375 //============================================================================
376 /// Describes a AtomicBlackBox output (to be put inside the UBB description block)
377 #define BBTK_OUTPUT(CLASS,NAME,DESCR,TYPE,NATURE)                       \
378   AddOutputDescriptor(new bbtk::AtomicBlackBoxOutputDescriptor          \
379                       (typeid(CLASS ## Descriptor),#NAME,DESCR,NATURE,  \
380                        new bbtk::AtomicBlackBoxTGetFunctor<CLASS,TYPE,TYPE > \
381                        (&CLASS::bbGetOutput##NAME),                     \
382                        new bbtk::AtomicBlackBoxTSetFunctor<CLASS,TYPE,TYPE > \
383                        (&CLASS::bbSetOutput##NAME) ) )
384 //============================================================================
385
386
387 //============================================================================
388 /// Describes a AtomicBlackBox input (to be put inside the UBB description block)
389 #define BBTK_INPUT_NOCOPY(CLASS,NAME,DESCR,TYPE,NATURE)                 \
390   AddInputDescriptor(new bbtk::AtomicBlackBoxInputDescriptor            \
391                      (typeid(CLASS ## Descriptor),#NAME,DESCR,NATURE,   \
392                       new bbtk::AtomicBlackBoxTGetFunctor<CLASS,TYPE,TYPE > \
393                       (&CLASS::bbGetInput##NAME),                       \
394                       new bbtk::AtomicBlackBoxTSetFunctor<CLASS,TYPE,TYPE > \
395                       (&CLASS::bbSetInput##NAME),                       \
396                       false) )
397 //============================================================================
398
399 //============================================================================
400 /// Describes a AtomicBlackBox output (to be put inside the UBB description block)
401 #define BBTK_OUTPUT_NOCOPY(CLASS,NAME,DESCR,TYPE,NATURE)                \
402   AddOutputDescriptor(new bbtk::AtomicBlackBoxOutputDescriptor          \
403                       (typeid(CLASS ## Descriptor),#NAME,DESCR,NATURE,  \
404                        new bbtk::AtomicBlackBoxTGetFunctor<CLASS,TYPE,TYPE > \
405                        (&CLASS::bbGetOutput##NAME),                     \
406                        new bbtk::AtomicBlackBoxTSetFunctor<CLASS,TYPE,TYPE > \
407                        (&CLASS::bbSetOutput##NAME),\
408                        false) )
409 //============================================================================
410
411
412
413
414
415
416
417
418
419
420 //============================================================================
421 //============================================================================
422 // Template user black boxes macros
423 //============================================================================
424 //============================================================================
425
426 //============================================================================
427 #define BBTK_TEMPLATE_BLACK_BOX_INTERFACE(CLASS,PARENT,T)       \
428   public : typedef CLASS<T> Self;                               \
429   BBTK_BLACK_BOX_INTERFACE_INTERNAL(CLASS,PARENT);
430 //============================================================================
431
432 //============================================================================
433 /// Begins a template AtomicBlackBox of template param T description block
434 #define BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(CLASS,PARENT)            \
435   template <class T>                                                    \
436   class /*BBTK_EXPORT*/ CLASS ## Descriptor : public PARENT ## Descriptor \
437   {                                                                     \
438   public: typedef CLASS ## Descriptor<T> Self;                          \
439     BBTK_OBJECT_MINIMAL_INTERFACE;                                      \
440   public:                                                               \
441     std::string GetObjectName() const                                   \
442     {                                                                   \
443       return std::string(BBTK_STRINGIFY(CLASS))                         \
444         +std::string("Descriptor<")+bbtk::TypeName<T>()                 \
445         +std::string("> '")+GetFullTypeName()                           \
446         +std::string("'");                                              \
447     }                                                                   \
448     static Pointer New()                                                \
449       {                                                                 \
450         bbtkDebugMessage("object",1,"##> "<<BBTK_STRINGIFY(CLASS)       \
451                          <<"Descriptor<"<<bbtk::TypeName<T>()<<">::New" \
452                          <<std::endl);                                  \
453         Pointer p = MakePointer(new Self());                            \
454         bbtkDebugMessage("object",1,"<## "<<BBTK_STRINGIFY(CLASS)       \
455                          <<"Descriptor<"<<bbtk::TypeName<T>()<<">::New" \
456                          <<std::endl);                                  \
457         return p;                                                       \
458       }                                                                 \
459     virtual bbtk::AtomicBlackBoxDescriptor::Pointer GetInstance()       const \
460       {                                                                 \
461         return Instance();                                              \
462       }                                                                 \
463     static bbtk::AtomicBlackBoxDescriptor::Pointer Instance()           \
464       {                                                                 \
465         static bbtk::AtomicBlackBoxDescriptor::WeakPointer i;           \
466         bbtk::AtomicBlackBoxDescriptor::Pointer j;                      \
467         if (!i.lock()) { j = Self::New(); i = j; }                      \
468         return i.lock();                                                \
469       }                                                                 \
470     bbtk::BlackBox::Pointer NewBlackBox(const std::string& name)        \
471     {                                                                   \
472       return CLASS<T>::New(name);                                       \
473     }                                                                   \
474     CLASS ## Descriptor()                                               \
475       {                                                                 \
476         bbtkDebugMessage("object",2,"==> "<<#CLASS<<"Descriptor<"       \
477                          <<bbtk::TypeName<T>()<<">::"                   \
478                          <<#CLASS<<"Descriptor()"<<std::endl);          
479
480 //============================================================================
481
482 //============================================================================
483 /// Ends a template AtomicBlackBox of template param T description block
484 #define BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(CLASS)                     \
485   bbtkDebugMessage("object",2,"<== "<<#CLASS<<"Descriptor<"             \
486                    <<bbtk::TypeName<T>()<<">::"                         \
487                    <<#CLASS<<"Descriptor()"<<std::endl);                \
488   }                                                                     \
489   };                                                                    
490
491 //============================================================================
492
493 //============================================================================
494 /// Describes a template AtomicBlackBox input (to be put inside the template UBB description block)
495 #define BBTK_TEMPLATE_INPUT(CLASS,NAME,DESCR,TYPE)                      \
496   AddInputDescriptor(new bbtk::AtomicBlackBoxInputDescriptor            \
497                      (typeid(CLASS ## Descriptor),#NAME,DESCR,"",       \
498                       new bbtk::AtomicBlackBoxTGetFunctor<CLASS<T>,TYPE,TYPE > \
499                       (&CLASS<T>::bbGetInput##NAME),                    \
500                       new bbtk::AtomicBlackBoxTSetFunctor<CLASS<T>,TYPE,TYPE > \
501                       (&CLASS<T>::bbSetInput##NAME) ) )
502 //============================================================================
503
504 //============================================================================
505 /// Describes a template AtomicBlackBox output (to be put inside the template UBB description block)
506 #define BBTK_TEMPLATE_OUTPUT(CLASS,NAME,DESCR,TYPE)                     \
507   AddOutputDescriptor(new bbtk::AtomicBlackBoxOutputDescriptor          \
508                       (typeid(CLASS ## Descriptor),#NAME,DESCR,"",      \
509                        new bbtk::AtomicBlackBoxTGetFunctor<CLASS<T>,TYPE,TYPE > \
510                        (&CLASS<T>::bbGetOutput##NAME),                  \
511                        new bbtk::AtomicBlackBoxTSetFunctor<CLASS<T>,TYPE,TYPE > \
512                        (&CLASS<T>::bbSetOutput##NAME) ) )
513 //============================================================================
514
515 //============================================================================
516 /// Template AtomicBlackBox std implementation of ctor and dtor
517 #define BBTK_BLACK_BOX_TEMPLATE_IMPLEMENTATION(CLASS,PARENT)            \
518   template <class T>                                                    \
519   CLASS<T>::CLASS(const std::string& name, bool alloc)                  \
520     : PARENT(name,false)                                                \
521   {                                                                     \
522     BBTK_BEGIN_BLACK_BOX_CONSTRUCTOR(CLASS,alloc);                      \
523     CLASS<T>::bbUserConstructor();                                      \
524     BBTK_END_BLACK_BOX_CONSTRUCTOR(CLASS);                              \
525   }                                                                     \
526   template <class T>                                                    \
527   CLASS<T>::CLASS(CLASS<T>& from,                                       \
528                   const std::string& name, bool allocate_connectors)    \
529     : PARENT(from,name,false)                                           \
530   {                                                                     \
531     BBTK_BEGIN_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from,allocate_connectors); \
532     CLASS<T>::bbUserCopyConstructor(from.GetThisPointer<bbtk::BlackBox>()); \
533     BBTK_END_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from);                    \
534   }                                                                     \
535   template <class T>                                                    \
536   CLASS<T>::~CLASS()                                                    \
537   {                                                                     \
538     BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS);                             \
539     CLASS<T>::bbUserDestructor();                                       \
540     BBTK_END_BLACK_BOX_DESTRUCTOR(CLASS);                               \
541   }                                                                     \
542   template <class T>                                                    \
543   void CLASS<T>::bbLockDescriptor()                                     \
544   {                                                                     \
545     bbmDescriptorPointer = CLASS ## Descriptor<T>::Instance();          \
546   }
547 //============================================================================
548
549
550
551 //============================================================================
552 // Two template params user black boxes macros
553 //============================================================================
554
555 //============================================================================
556 #define BBTK_TEMPLATE2_BLACK_BOX_INTERFACE(CLASS,PARENT,T1,T2)  \
557   public : typedef CLASS<T1,T2> Self;                                   \
558   BBTK_BLACK_BOX_INTERFACE_INTERNAL(CLASS,PARENT);
559 //===========================================================================
560
561 //============================================================================
562 /// Begins a template AtomicBlackBox description block of template param T1 and T2 
563 #define BBTK_BEGIN_DESCRIBE_TEMPLATE2_BLACK_BOX(CLASS,PARENT)           \
564   template <class T1, class T2>                                         \
565   class /*BBTK_EXPORT*/ CLASS ## Descriptor : public PARENT ## Descriptor \
566   {                                                                     \
567   public: typedef CLASS ## Descriptor<T1,T2> Self;                      \
568     BBTK_OBJECT_MINIMAL_INTERFACE;                                      \
569   public:                                                               \
570     std::string GetObjectName() const                                   \
571     {                                                                   \
572       return std::string(BBTK_STRINGIFY(CLASS))                         \
573         +std::string("Descriptor<")+bbtk::TypeName<T1>()                \
574         +std::string(",")+bbtk::TypeName<T2>()                          \
575         +std::string("> '")+GetFullTypeName()                           \
576         +std::string("'");                                              \
577     }                                                                   \
578     static Pointer New()                                                \
579       {                                                                 \
580         bbtkDebugMessage("object",1,"##> "<<BBTK_STRINGIFY(CLASS)       \
581                          <<"Descriptor<"<<bbtk::TypeName<T1>()<<","     \
582                          <<bbtk::TypeName<T2>()<<">::New"<<std::endl);  \
583         Pointer p = MakePointer(new Self());                            \
584         bbtkDebugMessage("object",1,"<## "<<BBTK_STRINGIFY(CLASS)       \
585                          <<"Descriptor<"<<bbtk::TypeName<T1>()<<","     \
586                          <<bbtk::TypeName<T2>()<<">::New"<<std::endl);  \
587         return p;                                                       \
588       }                                                                 \
589     virtual bbtk::AtomicBlackBoxDescriptor::Pointer GetInstance() const \
590       {                                                                 \
591         return Instance();                                              \
592       }                                                                 \
593     static bbtk::AtomicBlackBoxDescriptor::Pointer Instance()           \
594       {                                                                 \
595         static bbtk::AtomicBlackBoxDescriptor::WeakPointer i;           \
596         bbtk::AtomicBlackBoxDescriptor::Pointer j;                      \
597         if (!i.lock()) { j = Self::New(); i = j; }                      \
598         return i.lock();                                                \
599       }                                                                 \
600     bbtk::BlackBox::Pointer NewBlackBox(const std::string& name)        \
601     {                                                                   \
602       return CLASS<T1,T2>::New(name);                                   \
603     }                                                                   \
604     CLASS ## Descriptor()                                               \
605       {                                                                 \
606         bbtkDebugMessage("object",2,"==> "<<#CLASS<<"Descriptor<"       \
607                          <<bbtk::TypeName<T1>()<<","                    \
608                          <<bbtk::TypeName<T2>()<<">::"                  \
609                          <<#CLASS<<"Descriptor()"<<std::endl);          
610 //============================================================================
611
612 //============================================================================
613 /// Ends a template AtomicBlackBox description block of template param T1 and T2
614 #define BBTK_END_DESCRIBE_TEMPLATE2_BLACK_BOX(CLASS)                    \
615   bbtkDebugMessage("object",2,"<== "<<#CLASS<<"Descriptor<"             \
616                    <<bbtk::TypeName<T1>()<<","                          \
617                    <<bbtk::TypeName<T2>()<<">::"                        \
618                    <<#CLASS<<"Descriptor()"<<std::endl);                \
619   }                                                                     \
620   };                                                                    
621
622 //============================================================================
623
624
625
626 /*
627 //============================================================================
628 // Two template params user black boxes macros
629
630 /// Begins a template AtomicBlackBox description block of template param T1 and T2 
631 #define BBTK_BEGIN_DESCRIBE_TEMPLATE2_WITH_TYPES_BLACK_BOX(CLASS,TYPE1,TYPE2)           \
632   template <TYPE1 T1, TYPE2 T2>                                         \
633   class  CLASS ## Descriptor : public bbtk::BlackBoxDescriptor          \
634   {                                                                     \
635   public:                                                               \
636     virtual bbtk:AtomicBlackBoxDescriptor::Pointer GetInstance()        const   \
637       {                                                                 \
638         return Instance();                                              \
639       }                                                                 \
640     static bbtk:AtomicBlackBoxDescriptor::Pointer Instance()                    \
641       {                                                                 \
642         static bbtk:AtomicBlackBoxDescriptor::WeakPointer i;                    \
643         bbtk:AtomicBlackBoxDescriptor::Pointer j;                               \
644         if (!i.lock()) { j = Self::New(); i = j; }                      \
645         return i.lock();                                                \
646       }                                                                 \
647     bbtk::BlackBox::Pointer NewBlackBox(const std::string& name)        \
648     {                                                                   \
649       return new CLASS<T1,T2>(name);                                    \
650     }                                                                   \
651     CLASS ## Descriptor()                                               \
652       {                                                                 \
653       bbtkDebugMessageInc("Kernel",9,#CLASS<<"Descriptor::"<<#CLASS     \
654                           <<"Descriptor()"<<std::endl)
655 //============================================================================
656
657 //============================================================================
658 /// Ends a template AtomicBlackBox description block of template param T1 and T2
659 #define BBTK_END_DESCRIBE_TEMPLATE2_WITH_TYPES_BLACK_BOX(CLASS,TYPE1,TYPE2)     \
660   bbtkDecTab("Kernel",9);                                                       \
661   }                                                                     \
662   };                                                                    
663
664 //============================================================================
665
666 */
667
668 //============================================================================
669 /// Describes a 2 template params AtomicBlackBox input (to be put inside the UBB description block)
670 #define BBTK_TEMPLATE2_INPUT(CLASS,NAME,DESCR,TYPE)                     \
671   AddInputDescriptor(new bbtk::AtomicBlackBoxInputDescriptor            \
672                      (typeid(CLASS ## Descriptor),#NAME,DESCR,"",       \
673                       new bbtk::AtomicBlackBoxTGetFunctor<CLASS<T1,T2>,TYPE,TYPE >      \
674                       (&CLASS<T1,T2>::bbGetInput##NAME),                \
675                       new bbtk::AtomicBlackBoxTSetFunctor<CLASS<T1,T2>,TYPE,TYPE >      \
676                       (&CLASS<T1,T2>::bbSetInput##NAME) ) )
677 //============================================================================
678
679 //============================================================================
680 /// Describes a 2 template params AtomicBlackBox output (to be put inside the UBB description block)
681 #define BBTK_TEMPLATE2_OUTPUT(CLASS,NAME,DESCR,TYPE)                    \
682   AddOutputDescriptor(new bbtk::AtomicBlackBoxOutputDescriptor          \
683                       (typeid(CLASS ## Descriptor),#NAME,DESCR,"",      \
684                        new bbtk::AtomicBlackBoxTGetFunctor<CLASS<T1,T2>,TYPE,TYPE > \
685                        (&CLASS<T1,T2>::bbGetOutput##NAME),              \
686                        new bbtk::AtomicBlackBoxTSetFunctor<CLASS<T1,T2>,TYPE,TYPE > \
687                        (&CLASS<T1,T2>::bbSetOutput##NAME) ) )
688 //============================================================================
689
690 //============================================================================
691 /// Template AtomicBlackBox std implementation of ctor and dtor
692 #define BBTK_BLACK_BOX_TEMPLATE2_IMPLEMENTATION(CLASS,PARENT)           \
693   template <class T1, class T2>                                         \
694   CLASS<T1,T2>::CLASS(const std::string& name, bool alloc)              \
695     : PARENT(name,false)                                                \
696   {                                                                     \
697     BBTK_BEGIN_BLACK_BOX_CONSTRUCTOR(CLASS,alloc);                      \
698     CLASS<T1,T2>::bbUserConstructor();                                  \
699     BBTK_END_BLACK_BOX_CONSTRUCTOR(CLASS);                              \
700   }                                                                     \
701   template <class T1, class T2>                                         \
702   CLASS<T1,T2>::CLASS(CLASS<T1,T2>& from,                               \
703                       const std::string& name, bool allocate_connectors) \
704     : PARENT(from,name,false)                                           \
705   {                                                                     \
706     BBTK_BEGIN_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from,allocate_connectors); \
707     CLASS<T1,T2>::bbUserCopyConstructor(from.GetThisPointer<bbtk::BlackBox>()); \
708     BBTK_END_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from);                    \
709   }                                                                     \
710   template <class T1, class T2>                                         \
711   CLASS<T1,T2>::~CLASS()                                                \
712   {                                                                     \
713     BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS);                             \
714     CLASS<T1,T2>::bbUserDestructor();                                   \
715     BBTK_END_BLACK_BOX_DESTRUCTOR(CLASS);                               \
716   }                                                                     \
717   template <class T1, class T2>                                         \
718   void CLASS<T1,T2>::bbLockDescriptor()                                 \
719   {                                                                     \
720     bbmDescriptorPointer = CLASS ## Descriptor<T1,T2>::Instance();      \
721   }
722 //============================================================================
723
724
725 /*
726 //============================================================================
727 /// Template AtomicBlackBox std implementation of ctor and dtor
728 #define BBTK_BLACK_BOX_TEMPLATE2_WITH_TYPES_IMPLEMENTATION(CLASS,PARENT,TYPE1,TYPE2) \
729   template <TYPE1 T1, TYPE2 T2>                                         \
730   CLASS<T1,T2>::CLASS(const std::string& name, bool alloc)              \
731     : PARENT(name,false)                                                \
732   {                                                                     \
733     BBTK_BEGIN_BLACK_BOX_CONSTRUCTOR(CLASS,alloc);                      \
734     this->bbUserConstructor();                                          \
735     BBTK_END_BLACK_BOX_CONSTRUCTOR;                                     \
736   }                                                                     \
737   template <TYPE1 T1, TYPE2 T2>                                         \
738   CLASS<T1,T2>::CLASS(CLASS<T1,T2>& from,                               \
739                       const std::string& name, bool allocate_connectors) \
740     : PARENT(from,name,false)                                           \
741   {                                                                     \
742     BBTK_BEGIN_BLACK_BOX_COPY_CONSTRUCTOR(CLASS,from,allocate_connectors); \
743     this->bbUserCopyConstructor();                                      \
744     BBTK_END_BLACK_BOX_CONSTRUCTOR;                                     \
745   }                                                                     \
746   template <TYPE1 T1, TYPE2 T2>                                         \
747   CLASS<T1,T2>::~CLASS()                                                \
748   {                                                                     \
749     BBTK_BEGIN_BLACK_BOX_DESTRUCTOR(CLASS);                             \
750     this->bbUserDestructor();                                           \
751     BBTK_END_BLACK_BOX_DESTRUCTOR;                                      \
752   }                                                                     \
753   template <class T1, class T2>                                         \
754   void CLASS<T1,T2>::bbLockDescriptor()                                 \
755   {                                                                     \
756     bbmDescriptorPointer = CLASS ## Descriptor<T1,T2>::Instance();      \
757   }
758 //============================================================================
759
760 */
761
762
763
764
765
766
767
768 //===========================================================================
769 /// EOF
770 //===========================================================================
771 #endif