00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __bbstdMagicBox_h_INCLUDED_H__
00033 #define __bbstdMagicBox_h_INCLUDED_H__
00034
00035 #include "bbtkAtomicBlackBox.h"
00036
00037 namespace bbstd
00038 {
00039
00040 class MagicBox
00041 :
00042 public bbtk::AtomicBlackBox
00043 {
00044 BBTK_BLACK_BOX_INTERFACE(MagicBox,bbtk::AtomicBlackBox);
00045 BBTK_DECLARE_INPUT(In,bbtk::Data);
00046 BBTK_DECLARE_OUTPUT(Out,bbtk::Data);
00047 BBTK_PROCESS(DoProcess);
00048 void DoProcess() { bbSetOutputOut( bbGetInputIn() ); }
00049
00050 protected:
00051
00052
00053 };
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 class MagicBoxSetFunctor : public bbtk::AtomicBlackBoxSetFunctor
00066 {
00067 public:
00069 typedef void (MagicBox::*SetMethodPointerType)(bbtk::Data);
00070
00072 MagicBoxSetFunctor(SetMethodPointerType s) :
00073 mSetMethodPointer(s)
00074 {
00075 }
00076
00078 void Set(bbtk::AtomicBlackBox* o, const bbtk::Data& d)
00079 {
00080 bbtkDebugMessage("Data",9,"MagicBoxSetfunctor::Set()"<<std::endl);
00081 (((MagicBox*)o)->*mSetMethodPointer)(d);
00082 }
00083
00085 bbtk::TypeInfo GetTypeInfo() const { return typeid(bbtk::Data); }
00086 std::string GetTypeName() const { return bbtk::TypeName<bbtk::Data>(); }
00087 std::string GetHumanTypeName() const { return bbtk::HumanTypeName<bbtk::Data>(); }
00088 bool IsPointerType() const { return false; }
00089 void BruteForceSetPointer(bbtk::AtomicBlackBox*, void*) {}
00090 private:
00092 SetMethodPointerType mSetMethodPointer;
00093 };
00094
00095
00096
00097
00098 BBTK_BEGIN_DESCRIBE_BLACK_BOX(MagicBox,bbtk::AtomicBlackBox);
00099 BBTK_NAME("MagicBox");
00100 BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
00101 BBTK_CATEGORY("misc");
00102 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.");
00103 AddInputDescriptor
00104 (new bbtk::AtomicBlackBoxInputDescriptor
00105 (typeid(MagicBoxDescriptor),
00106 "In","Input data","",
00107 new bbtk::AtomicBlackBoxTGetFunctor<MagicBox,bbtk::Data,bbtk::Data>
00108 (&MagicBox::bbGetInputIn),
00109 new MagicBoxSetFunctor (&MagicBox::bbSetInputIn) ) );
00110 AddOutputDescriptor
00111 (new bbtk::AtomicBlackBoxOutputDescriptor
00112 (typeid(MagicBoxDescriptor),
00113 "Out","Output data","",
00114 new bbtk::AtomicBlackBoxTGetFunctor<MagicBox,bbtk::Data,bbtk::Data>
00115 (&MagicBox::bbGetOutputOut),
00116 new MagicBoxSetFunctor (&MagicBox::bbSetOutputOut) ) );
00117 BBTK_END_DESCRIBE_BLACK_BOX(MagicBox);
00118
00119
00120 }
00121
00122
00123 #endif // __bbstdMagicBox_h_INCLUDED_H__