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