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: bbstdSharedMemory.h,v $
32 Date: $Date: 2012/11/16 08:51:32 $
33 Version: $Revision: 1.2 $
34 =========================================================================*/
36 #ifndef __bbstdSharedMemory_h_INCLUDED_H__
37 #define __bbstdSharedMemory_h_INCLUDED_H__
39 #include "bbtkAtomicBlackBox.h"
40 #include "bbstd_EXPORT.h"
44 #define BBTK_MB_DECLARE_INPUT(NAME,TYPE) \
46 TYPE bbmInput##NAME; \
48 TYPE bbGetInput##NAME () \
49 { return bbmInput##NAME; } \
50 void bbSetInput##NAME (TYPE d) \
51 { bbmInput##NAME = d; \
52 if (mCanSet) { bbSetOutputOut(d); mCanSet = false; } }
54 //==================================================================
55 class bbstd_EXPORT SharedMemory
57 public bbtk::AtomicBlackBox
59 BBTK_BLACK_BOX_INTERFACE(SharedMemory,bbtk::AtomicBlackBox);
61 // BBTK_DECLARE_INPUT(In,bbtk::Data);
62 BBTK_MB_DECLARE_INPUT(In,bbtk::Data);
64 BBTK_MB_DECLARE_INPUT(In1,bbtk::Data);
65 BBTK_MB_DECLARE_INPUT(In2,bbtk::Data);
66 BBTK_MB_DECLARE_INPUT(In3,bbtk::Data);
67 BBTK_MB_DECLARE_INPUT(In4,bbtk::Data);
68 BBTK_MB_DECLARE_INPUT(In5,bbtk::Data);
69 BBTK_MB_DECLARE_INPUT(In6,bbtk::Data);
70 BBTK_MB_DECLARE_INPUT(In7,bbtk::Data);
71 BBTK_MB_DECLARE_INPUT(In8,bbtk::Data);
72 BBTK_MB_DECLARE_INPUT(In9,bbtk::Data);
73 BBTK_DECLARE_OUTPUT(Out,bbtk::Data);
74 BBTK_PROCESS(DoProcess);
77 // virtual void bbUserConstructor();
78 virtual void bbSetStatusAndPropagate(bbtk::BlackBoxInputConnector* c,
83 //==================================================================
85 #undef BBTK_MB_DECLARE_INPUT
87 //==================================================================
88 // We have to create a particular SetFunctor for SharedMemory because
89 // its input is of type bbtk::Data (i.e. any) and :
90 // 1) an any cannot store an any (construction with an any invokes the copy constr.)
91 // 2) we cannot invoke the Set method with the content of the any because
93 // hence the Set method of the functor **MUST NOT** extract the
94 // content of the Data prior to invoking the set method of the box
95 class SharedMemorySetFunctor : public bbtk::AtomicBlackBoxSetFunctor
98 /// Type of pointer on a UBB::Set method
99 typedef void (SharedMemory::*SetMethodPointerType)(bbtk::Data);
101 /// Construction with the pointer on the Set method
102 SharedMemorySetFunctor(SetMethodPointerType s) :
107 /// Concrete application of the Set method of object o
108 void Set(bbtk::AtomicBlackBox* o, const bbtk::Data& d)
110 bbtkDebugMessage("data",9,"SharedMemorySetfunctor::Set("<<
111 bbtk::HumanTypeName(d.type())<<
113 (((SharedMemory*)o)->*mSetMethodPointer)(d);
117 bbtk::TypeInfo GetTypeInfo() const { return typeid(bbtk::Data); }
118 std::string GetTypeName() const { return bbtk::TypeName<bbtk::Data>(); }
119 std::string GetHumanTypeName() const { return bbtk::HumanTypeName<bbtk::Data>(); }
120 bool IsPointerType() const { return false; }
121 void BruteForceSetPointer(bbtk::AtomicBlackBox*, void*) {}
123 /// Pointer on the Set method
124 SetMethodPointerType mSetMethodPointer;
126 //===========================================================================
128 #define MAGIC_BOX_INPUT(NAME) \
130 (new bbtk::AtomicBlackBoxInputDescriptor \
131 (typeid(SharedMemoryDescriptor), \
132 #NAME,"Input data","", \
133 new bbtk::AtomicBlackBoxTGetFunctor<SharedMemory,bbtk::Data,bbtk::Data> \
134 (&SharedMemory::bbGetInput ## NAME), \
135 new SharedMemorySetFunctor (&SharedMemory::bbSetInput ## NAME) ) );
137 //===========================================================================
138 BBTK_BEGIN_DESCRIBE_BLACK_BOX(SharedMemory,bbtk::AtomicBlackBox);
139 BBTK_NAME("SharedMemory");
140 BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
141 BBTK_CATEGORY("misc");
142 BBTK_DESCRIPTION("Implements a memory which can be shared by different boxes. The value of the output is the value of the lower index input which has changed. It is used for example for synchronization issues between boxes.");
156 (new bbtk::AtomicBlackBoxInputDescriptor
157 (typeid(SharedMemoryDescriptor),
158 "In","Input data","",
159 new bbtk::AtomicBlackBoxTGetFunctor<SharedMemory,bbtk::Data,bbtk::Data>
160 (&SharedMemory::bbGetInputIn),
161 new SharedMemorySetFunctor (&SharedMemory::bbSetInputIn) ) );
164 (new bbtk::AtomicBlackBoxOutputDescriptor
165 (typeid(SharedMemoryDescriptor),
166 "Out","Output data","",
167 new bbtk::AtomicBlackBoxTGetFunctor<SharedMemory,bbtk::Data,bbtk::Data>
168 (&SharedMemory::bbGetOutputOut),
169 new SharedMemorySetFunctor (&SharedMemory::bbSetOutputOut) ) );
170 BBTK_END_DESCRIBE_BLACK_BOX(SharedMemory);
171 //===========================================================================
176 #endif // __bbstdSharedMemory_h_INCLUDED_H__