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