2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbstdMagicBox.h,v $
32 Date: $Date: 2012/11/16 08:51:32 $
33 Version: $Revision: 1.14 $
34 =========================================================================*/
37 #ifndef __bbstdMagicBox_h_INCLUDED_H__
38 #define __bbstdMagicBox_h_INCLUDED_H__
40 #include "bbtkAtomicBlackBox.h"
41 #include "bbstd_EXPORT.h"
46 //==================================================================
47 class bbstd_EXPORT MagicBox
49 public bbtk::AtomicBlackBox
51 BBTK_BLACK_BOX_INTERFACE(MagicBox,bbtk::AtomicBlackBox);
52 BBTK_DECLARE_INPUT(In,bbtk::Data);
53 BBTK_DECLARE_OUTPUT(Out,bbtk::Data);
54 BBTK_PROCESS(DoProcess);
57 //==================================================================
60 //==================================================================
61 // We have to create a particular SetFunctor for MagicBox because
62 // its input is of type bbtk::Data (i.e. any) and :
63 // 1) an any cannot store an any (construction with an any invokes the copy constr.)
64 // 2) we cannot invoke the Set method with the content of the any because
66 // hence the Set method of the functor **MUST NOT** extract the
67 // content of the Data prior to invoking the set method of the box
68 class MagicBoxSetFunctor : public bbtk::AtomicBlackBoxSetFunctor
71 /// Type of pointer on a UBB::Set method
72 typedef void (MagicBox::*SetMethodPointerType)(bbtk::Data);
74 /// Construction with the pointer on the Set method
75 MagicBoxSetFunctor(SetMethodPointerType s) :
80 /// Concrete application of the Set method of object o
81 void Set(bbtk::AtomicBlackBox* o, const bbtk::Data& d)
83 bbtkDebugMessage("data",9,"MagicBoxSetfunctor::Set("<<
84 bbtk::HumanTypeName(d.type())<<
86 (((MagicBox*)o)->*mSetMethodPointer)(d);
90 bbtk::TypeInfo GetTypeInfo() const { return typeid(bbtk::Data); }
91 std::string GetTypeName() const { return bbtk::TypeName<bbtk::Data>(); }
92 std::string GetHumanTypeName() const { return bbtk::HumanTypeName<bbtk::Data>(); }
93 bool IsPointerType() const { return false; }
94 void BruteForceSetPointer(bbtk::AtomicBlackBox*, void*) {}
96 /// Pointer on the Set method
97 SetMethodPointerType mSetMethodPointer;
99 //===========================================================================
102 //===========================================================================
103 BBTK_BEGIN_DESCRIBE_BLACK_BOX(MagicBox,bbtk::AtomicBlackBox);
104 BBTK_NAME("MagicBox");
105 BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
106 BBTK_CATEGORY("misc");
107 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.");
110 (new bbtk::AtomicBlackBoxInputDescriptor
111 (typeid(MagicBoxDescriptor),
112 "In","Input data","",
113 new bbtk::AtomicBlackBoxTGetFunctor<MagicBox,bbtk::Data,bbtk::Data>
114 (&MagicBox::bbGetInputIn),
115 new MagicBoxSetFunctor (&MagicBox::bbSetInputIn) ) );
118 (new bbtk::AtomicBlackBoxOutputDescriptor
119 (typeid(MagicBoxDescriptor),
120 "Out","Output data","",
121 new bbtk::AtomicBlackBoxTGetFunctor<MagicBox,bbtk::Data,bbtk::Data>
122 (&MagicBox::bbGetOutputOut),
123 new MagicBoxSetFunctor (&MagicBox::bbSetOutputOut) ) );
124 BBTK_END_DESCRIBE_BLACK_BOX(MagicBox);
125 //===========================================================================
130 #endif // __bbstdMagicBox_h_INCLUDED_H__