#ifndef __bbstdMagicBox_h_INCLUDED_H__ #define __bbstdMagicBox_h_INCLUDED_H__ #include "bbtkUserBlackBox.h" namespace bbstd { //================================================================== class MagicBox : public bbtk::UserBlackBox { BBTK_USER_BLACK_BOX_INTERFACE(MagicBox,bbtk::UserBlackBox); BBTK_DECLARE_INPUT(In,bbtk::Data); BBTK_DECLARE_OUTPUT(Out,bbtk::Data); BBTK_PROCESS(DoProcess); void DoProcess() { bbSetOutputOut( bbGetInputIn() ); } protected: // virtual void bbUserConstructor(); }; //================================================================== //================================================================== // We have to create a particular SetFunctor for MagicBox because // its input is of type bbtk::Data (i.e. any) and : // 1) an any cannot store an any (construction with an any invokes the copy constr.) // 2) we cannot invoke the Set method with the content of the any because // it expects an any // hence the method Set **MUST NOT** extract the content of the Data // prior to invoking the set method class MagicBoxSetFunctor : public bbtk::UserBlackBoxSetFunctor { public: /// Type of pointer on a UBB::Set method typedef void (MagicBox::*SetMethodPointerType)(bbtk::Data); /// Construction with the pointer on the Set method MagicBoxSetFunctor(SetMethodPointerType s) : mSetMethodPointer(s) {} /// Concrete application of the Set method of object o void Set(bbtk::UserBlackBox* o, const bbtk::Data& d) { bbtkDebugMessage("Data",9,"MagicBoxSetfunctor::Set()"<*mSetMethodPointer)(d); } /// bbtk::TypeInfo GetTypeInfo() const { return typeid(bbtk::Data); } std::string GetTypeName() const { return bbtk::TypeName(); } std::string GetHumanTypeName() const { return bbtk::HumanTypeName(); } bool IsPointerType() const { return false; } void BruteForceSetPointer(bbtk::UserBlackBox*, void*) {} private: /// Pointer on the Set method SetMethodPointerType mSetMethodPointer; }; //=========================================================================== BBTK_BEGIN_DESCRIBE_BLACK_BOX(MagicBox,bbtk::UserBlackBox); BBTK_NAME("MagicBox"); BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr"); BBTK_CATEGORY("adaptor"); BBTK_DESCRIPTION("MagicBox"); AddInputDescriptor(new bbtk::UserBlackBoxInputDescriptor ("In","Input data", new bbtk::UserBlackBoxTGetFunctor (&MagicBox::bbGetInputIn), new MagicBoxSetFunctor (&MagicBox::bbSetInputIn) ) ); AddOutputDescriptor(new bbtk::UserBlackBoxOutputDescriptor ("Out","Output data", new bbtk::UserBlackBoxTGetFunctor (&MagicBox::bbGetOutputOut), new MagicBoxSetFunctor (&MagicBox::bbSetOutputOut) ) ); BBTK_END_DESCRIBE_BLACK_BOX(MagicBox); } // namespace bbstd #endif // __bbstdMagicBox_h_INCLUDED_H__