]> Creatis software - bbtk.git/blob - packages/std/src/bbstdMagicBox.h
5c70c64e896dbbcaac34c8e4b76b30e6f451637d
[bbtk.git] / packages / std / src / bbstdMagicBox.h
1 #ifndef __bbstdMagicBox_h_INCLUDED_H__
2 #define __bbstdMagicBox_h_INCLUDED_H__
3
4 #include "bbtkUserBlackBox.h"
5
6 namespace bbstd
7 {
8   
9   //==================================================================
10   class /*BBTK_EXPORT*/ MagicBox
11     : 
12     public bbtk::UserBlackBox
13   {
14     BBTK_USER_BLACK_BOX_INTERFACE(MagicBox,bbtk::UserBlackBox);
15     BBTK_DECLARE_INPUT(In,bbtk::Data);
16     BBTK_DECLARE_OUTPUT(Out,bbtk::Data);
17     BBTK_PROCESS(DoProcess);
18     void DoProcess() { bbSetOutputOut( bbGetInputIn() ); }
19     
20   protected:
21     //    virtual void bbUserConstructor();
22     
23   };
24   //==================================================================
25   
26   
27   //==================================================================
28   // We have to create a particular SetFunctor for MagicBox because
29   // its input is of type bbtk::Data (i.e. any) and :
30   // 1) an any cannot store an any (construction with an any invokes the copy constr.)
31   // 2) we cannot invoke the Set method with the content of the any because 
32   //   it expects an any 
33   // hence the method Set **MUST NOT** extract the content of the Data 
34   // prior to invoking the set method
35   class MagicBoxSetFunctor : public bbtk::UserBlackBoxSetFunctor
36   {
37   public:
38     /// Type of pointer on a UBB::Set method  
39     typedef void (MagicBox::*SetMethodPointerType)(bbtk::Data);
40     
41     /// Construction with the pointer on the Set method
42     MagicBoxSetFunctor(SetMethodPointerType s) :
43       mSetMethodPointer(s) 
44     {}
45     
46     /// Concrete application of the Set method of object o
47     void Set(bbtk::UserBlackBox* o, const bbtk::Data& d)
48     { 
49       bbtkDebugMessage("Data",9,"MagicBoxSetfunctor::Set()"<<std::endl);
50       (((MagicBox*)o)->*mSetMethodPointer)(d);
51     }
52     
53     /// 
54     bbtk::TypeInfo GetTypeInfo() const { return typeid(bbtk::Data); }
55     std::string GetTypeName() const { return bbtk::TypeName<bbtk::Data>(); }
56     std::string GetHumanTypeName() const { return bbtk::HumanTypeName<bbtk::Data>(); }
57     bool IsPointerType() const { return false; }
58     void BruteForceSetPointer(bbtk::UserBlackBox*, void*) {}
59   private:
60     ///  Pointer on the Set method  
61     SetMethodPointerType mSetMethodPointer;
62   };
63   //===========================================================================
64
65
66
67   BBTK_BEGIN_DESCRIBE_BLACK_BOX(MagicBox,bbtk::UserBlackBox);
68   BBTK_NAME("MagicBox");
69   BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
70   BBTK_DESCRIPTION("MagicBox");
71   AddInputDescriptor(new bbtk::UserBlackBoxInputDescriptor              
72                      ("In","Input data",
73                       new bbtk::UserBlackBoxTGetFunctor<MagicBox,bbtk::Data,bbtk::Data>
74                       (&MagicBox::bbGetInputIn),
75                       new MagicBoxSetFunctor (&MagicBox::bbSetInputIn) ) );
76   AddOutputDescriptor(new bbtk::UserBlackBoxOutputDescriptor            
77                       ("Out","Output data",
78                        new bbtk::UserBlackBoxTGetFunctor<MagicBox,bbtk::Data,bbtk::Data>
79                        (&MagicBox::bbGetOutputOut),
80                        new MagicBoxSetFunctor (&MagicBox::bbSetOutputOut) ) );
81   BBTK_END_DESCRIBE_BLACK_BOX(MagicBox);
82 }
83 // namespace bbstd
84
85 #endif // __bbstdMagicBox_h_INCLUDED_H__