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);
60 BBTK_MB_DECLARE_INPUT(In,bbtk::Data);
61 BBTK_MB_DECLARE_INPUT(In1,bbtk::Data);
62 BBTK_MB_DECLARE_INPUT(In2,bbtk::Data);
63 BBTK_MB_DECLARE_INPUT(In3,bbtk::Data);
64 BBTK_MB_DECLARE_INPUT(In4,bbtk::Data);
65 BBTK_MB_DECLARE_INPUT(In5,bbtk::Data);
66 BBTK_MB_DECLARE_INPUT(In6,bbtk::Data);
67 BBTK_MB_DECLARE_INPUT(In7,bbtk::Data);
68 BBTK_MB_DECLARE_INPUT(In8,bbtk::Data);
69 BBTK_MB_DECLARE_INPUT(In9,bbtk::Data);
70 BBTK_DECLARE_OUTPUT(Out,bbtk::Data);
71 BBTK_PROCESS(DoProcess);
74 // virtual void bbUserConstructor();
75 virtual void bbSetStatusAndPropagate(bbtk::BlackBoxInputConnector* c,
79 //==================================================================
81 #undef BBTK_MB_DECLARE_INPUT
83 //==================================================================
84 // We have to create a particular SetFunctor for SharedMemory because
85 // its input is of type bbtk::Data (i.e. any) and :
86 // 1) an any cannot store an any (construction with an any invokes the copy constr.)
87 // 2) we cannot invoke the Set method with the content of the any because
89 // hence the Set method of the functor **MUST NOT** extract the
90 // content of the Data prior to invoking the set method of the box
91 class SharedMemorySetFunctor : public bbtk::AtomicBlackBoxSetFunctor
94 /// Type of pointer on a UBB::Set method
95 typedef void (SharedMemory::*SetMethodPointerType)(bbtk::Data);
97 /// Construction with the pointer on the Set method
98 SharedMemorySetFunctor(SetMethodPointerType s) :
103 /// Concrete application of the Set method of object o
104 void Set(bbtk::AtomicBlackBox* o, const bbtk::Data& d)
106 bbtkDebugMessage("data",9,"SharedMemorySetfunctor::Set("<<
107 bbtk::HumanTypeName(d.type())<<
109 (((SharedMemory*)o)->*mSetMethodPointer)(d);
113 bbtk::TypeInfo GetTypeInfo() const { return typeid(bbtk::Data); }
114 std::string GetTypeName() const { return bbtk::TypeName<bbtk::Data>(); }
115 std::string GetHumanTypeName() const { return bbtk::HumanTypeName<bbtk::Data>(); }
116 bool IsPointerType() const { return false; }
117 void BruteForceSetPointer(bbtk::AtomicBlackBox*, void*) {}
119 /// Pointer on the Set method
120 SetMethodPointerType mSetMethodPointer;
122 //===========================================================================
124 #define MAGIC_BOX_INPUT(NAME) \
126 (new bbtk::AtomicBlackBoxInputDescriptor \
127 (typeid(SharedMemoryDescriptor), \
128 #NAME,"Input data","", \
129 new bbtk::AtomicBlackBoxTGetFunctor<SharedMemory,bbtk::Data,bbtk::Data> \
130 (&SharedMemory::bbGetInput ## NAME), \
131 new SharedMemorySetFunctor (&SharedMemory::bbSetInput ## NAME) ) );
133 //===========================================================================
134 BBTK_BEGIN_DESCRIBE_BLACK_BOX(SharedMemory,bbtk::AtomicBlackBox);
135 BBTK_NAME("SharedMemory");
136 BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
137 BBTK_CATEGORY("misc");
138 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.");
152 (new bbtk::AtomicBlackBoxInputDescriptor
153 (typeid(SharedMemoryDescriptor),
154 "In","Input data","",
155 new bbtk::AtomicBlackBoxTGetFunctor<SharedMemory,bbtk::Data,bbtk::Data>
156 (&SharedMemory::bbGetInputIn),
157 new SharedMemorySetFunctor (&SharedMemory::bbSetInputIn) ) );
160 (new bbtk::AtomicBlackBoxOutputDescriptor
161 (typeid(SharedMemoryDescriptor),
162 "Out","Output data","",
163 new bbtk::AtomicBlackBoxTGetFunctor<SharedMemory,bbtk::Data,bbtk::Data>
164 (&SharedMemory::bbGetOutputOut),
165 new SharedMemorySetFunctor (&SharedMemory::bbSetOutputOut) ) );
166 BBTK_END_DESCRIBE_BLACK_BOX(SharedMemory);
167 //===========================================================================
172 #endif // __bbstdSharedMemory_h_INCLUDED_H__