1 #ifndef __bbstdMagicBox_h_INCLUDED_H__
2 #define __bbstdMagicBox_h_INCLUDED_H__
4 #include "bbtkAtomicBlackBox.h"
8 //==================================================================
11 public bbtk::AtomicBlackBox
13 BBTK_USER_BLACK_BOX_INTERFACE(MagicBox,bbtk::AtomicBlackBox);
14 BBTK_DECLARE_INPUT(In,bbtk::Data);
15 BBTK_DECLARE_OUTPUT(Out,bbtk::Data);
16 BBTK_PROCESS(DoProcess);
17 void DoProcess() { bbSetOutputOut( bbGetInputIn() ); }
20 // virtual void bbUserConstructor();
23 //==================================================================
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
32 // hence the Set method of the functor **MUST NOT** extract the
33 // content of the Data prior to invoking the set method of the box
34 class MagicBoxSetFunctor : public bbtk::AtomicBlackBoxSetFunctor
37 /// Type of pointer on a UBB::Set method
38 typedef void (MagicBox::*SetMethodPointerType)(bbtk::Data);
40 /// Construction with the pointer on the Set method
41 MagicBoxSetFunctor(SetMethodPointerType s) :
45 /// Concrete application of the Set method of object o
46 void Set(bbtk::AtomicBlackBox* o, const bbtk::Data& d)
48 bbtkDebugMessage("Data",9,"MagicBoxSetfunctor::Set()"<<std::endl);
49 (((MagicBox*)o)->*mSetMethodPointer)(d);
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::AtomicBlackBox*, void*) {}
59 /// Pointer on the Set method
60 SetMethodPointerType mSetMethodPointer;
62 //===========================================================================
65 //===========================================================================
66 BBTK_BEGIN_DESCRIBE_BLACK_BOX(MagicBox,bbtk::AtomicBlackBox);
67 BBTK_NAME("MagicBox");
68 BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
69 BBTK_CATEGORY("misc");
70 BBTK_DESCRIPTION("Takes *any kind* of data and copies it to its output. Is a magic box as any box output can be plugged into it and its output can be plugged into any other box input (dynamic type checking, see below), hence it can be put between **any** two boxes. Type matching between its output and the input of the box(es) to which it is connected is made at *run-time*. The pipeline will be executed if the data types : i) match exactly ii) can be transformed by an adaptor iii) are related pointers, i.e. if the output pointer can be upcasted (static_cast) or downcasted (dynamic_cast) to an input type pointer (see the bbtk::any output connection rule in the guide for details). Important uses of the MagicBox are : 1) performing run-time pointer cast, either upward or backward an object hierarchy 2) perform data adaptation (adaptor creation) at run-time vs. pipeline creation time.");
72 (new bbtk::AtomicBlackBoxInputDescriptor
73 (typeid(MagicBoxDescriptor),
75 new bbtk::AtomicBlackBoxTGetFunctor<MagicBox,bbtk::Data,bbtk::Data>
76 (&MagicBox::bbGetInputIn),
77 new MagicBoxSetFunctor (&MagicBox::bbSetInputIn) ) );
79 (new bbtk::AtomicBlackBoxOutputDescriptor
80 (typeid(MagicBoxDescriptor),
82 new bbtk::AtomicBlackBoxTGetFunctor<MagicBox,bbtk::Data,bbtk::Data>
83 (&MagicBox::bbGetOutputOut),
84 new MagicBoxSetFunctor (&MagicBox::bbSetOutputOut) ) );
85 BBTK_END_DESCRIBE_BLACK_BOX(MagicBox);
86 //===========================================================================
91 #endif // __bbstdMagicBox_h_INCLUDED_H__