1 #ifndef __bbstdMagicBox_h_INCLUDED_H__
2 #define __bbstdMagicBox_h_INCLUDED_H__
4 #include "bbtkUserBlackBox.h"
9 //==================================================================
10 class /*BBTK_EXPORT*/ MagicBox
12 public bbtk::UserBlackBox
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() ); }
21 // virtual void bbUserConstructor();
24 //==================================================================
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
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
38 /// Type of pointer on a UBB::Set method
39 typedef void (MagicBox::*SetMethodPointerType)(bbtk::Data);
41 /// Construction with the pointer on the Set method
42 MagicBoxSetFunctor(SetMethodPointerType s) :
46 /// Concrete application of the Set method of object o
47 void Set(bbtk::UserBlackBox* o, const bbtk::Data& d)
49 bbtkDebugMessage("Data",9,"MagicBoxSetfunctor::Set()"<<std::endl);
50 (((MagicBox*)o)->*mSetMethodPointer)(d);
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*) {}
60 /// Pointer on the Set method
61 SetMethodPointerType mSetMethodPointer;
63 //===========================================================================
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
73 new bbtk::UserBlackBoxTGetFunctor<MagicBox,bbtk::Data,bbtk::Data>
74 (&MagicBox::bbGetInputIn),
75 new MagicBoxSetFunctor (&MagicBox::bbSetInputIn) ) );
76 AddOutputDescriptor(new bbtk::UserBlackBoxOutputDescriptor
78 new bbtk::UserBlackBoxTGetFunctor<MagicBox,bbtk::Data,bbtk::Data>
79 (&MagicBox::bbGetOutputOut),
80 new MagicBoxSetFunctor (&MagicBox::bbSetOutputOut) ) );
81 BBTK_END_DESCRIBE_BLACK_BOX(MagicBox);
85 #endif // __bbstdMagicBox_h_INCLUDED_H__