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