1 /*=========================================================================
3 Module: $RCSfile: bbstdSharedMemory.h,v $
5 Date: $Date: 2009/06/08 14:50:06 $
6 Version: $Revision: 1.1 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
32 #ifndef __bbstdSharedMemory_h_INCLUDED_H__
33 #define __bbstdSharedMemory_h_INCLUDED_H__
35 #include "bbtkAtomicBlackBox.h"
36 #include "bbstd_EXPORT.h"
40 #define BBTK_MB_DECLARE_INPUT(NAME,TYPE) \
42 TYPE bbmInput##NAME; \
44 TYPE bbGetInput##NAME () \
45 { return bbmInput##NAME; } \
46 void bbSetInput##NAME (TYPE d) \
47 { bbmInput##NAME = d; \
48 if (mCanSet) { bbSetOutputOut(d); mCanSet = false; } }
50 //==================================================================
51 class bbstd_EXPORT SharedMemory
53 public bbtk::AtomicBlackBox
55 BBTK_BLACK_BOX_INTERFACE(SharedMemory,bbtk::AtomicBlackBox);
56 BBTK_MB_DECLARE_INPUT(In,bbtk::Data);
57 BBTK_MB_DECLARE_INPUT(In1,bbtk::Data);
58 BBTK_MB_DECLARE_INPUT(In2,bbtk::Data);
59 BBTK_MB_DECLARE_INPUT(In3,bbtk::Data);
60 BBTK_MB_DECLARE_INPUT(In4,bbtk::Data);
61 BBTK_MB_DECLARE_INPUT(In5,bbtk::Data);
62 BBTK_MB_DECLARE_INPUT(In6,bbtk::Data);
63 BBTK_MB_DECLARE_INPUT(In7,bbtk::Data);
64 BBTK_MB_DECLARE_INPUT(In8,bbtk::Data);
65 BBTK_MB_DECLARE_INPUT(In9,bbtk::Data);
66 BBTK_DECLARE_OUTPUT(Out,bbtk::Data);
67 BBTK_PROCESS(DoProcess);
70 // virtual void bbUserConstructor();
71 virtual void bbSetStatusAndPropagate(bbtk::BlackBoxInputConnector* c,
75 //==================================================================
77 #undef BBTK_MB_DECLARE_INPUT
79 //==================================================================
80 // We have to create a particular SetFunctor for SharedMemory because
81 // its input is of type bbtk::Data (i.e. any) and :
82 // 1) an any cannot store an any (construction with an any invokes the copy constr.)
83 // 2) we cannot invoke the Set method with the content of the any because
85 // hence the Set method of the functor **MUST NOT** extract the
86 // content of the Data prior to invoking the set method of the box
87 class SharedMemorySetFunctor : public bbtk::AtomicBlackBoxSetFunctor
90 /// Type of pointer on a UBB::Set method
91 typedef void (SharedMemory::*SetMethodPointerType)(bbtk::Data);
93 /// Construction with the pointer on the Set method
94 SharedMemorySetFunctor(SetMethodPointerType s) :
99 /// Concrete application of the Set method of object o
100 void Set(bbtk::AtomicBlackBox* o, const bbtk::Data& d)
102 bbtkDebugMessage("data",9,"SharedMemorySetfunctor::Set("<<
103 bbtk::HumanTypeName(d.type())<<
105 (((SharedMemory*)o)->*mSetMethodPointer)(d);
109 bbtk::TypeInfo GetTypeInfo() const { return typeid(bbtk::Data); }
110 std::string GetTypeName() const { return bbtk::TypeName<bbtk::Data>(); }
111 std::string GetHumanTypeName() const { return bbtk::HumanTypeName<bbtk::Data>(); }
112 bool IsPointerType() const { return false; }
113 void BruteForceSetPointer(bbtk::AtomicBlackBox*, void*) {}
115 /// Pointer on the Set method
116 SetMethodPointerType mSetMethodPointer;
118 //===========================================================================
120 #define MAGIC_BOX_INPUT(NAME) \
122 (new bbtk::AtomicBlackBoxInputDescriptor \
123 (typeid(SharedMemoryDescriptor), \
124 #NAME,"Input data","", \
125 new bbtk::AtomicBlackBoxTGetFunctor<SharedMemory,bbtk::Data,bbtk::Data> \
126 (&SharedMemory::bbGetInput ## NAME), \
127 new SharedMemorySetFunctor (&SharedMemory::bbSetInput ## NAME) ) );
129 //===========================================================================
130 BBTK_BEGIN_DESCRIBE_BLACK_BOX(SharedMemory,bbtk::AtomicBlackBox);
131 BBTK_NAME("SharedMemory");
132 BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
133 BBTK_CATEGORY("misc");
134 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.");
148 (new bbtk::AtomicBlackBoxInputDescriptor
149 (typeid(SharedMemoryDescriptor),
150 "In","Input data","",
151 new bbtk::AtomicBlackBoxTGetFunctor<SharedMemory,bbtk::Data,bbtk::Data>
152 (&SharedMemory::bbGetInputIn),
153 new SharedMemorySetFunctor (&SharedMemory::bbSetInputIn) ) );
156 (new bbtk::AtomicBlackBoxOutputDescriptor
157 (typeid(SharedMemoryDescriptor),
158 "Out","Output data","",
159 new bbtk::AtomicBlackBoxTGetFunctor<SharedMemory,bbtk::Data,bbtk::Data>
160 (&SharedMemory::bbGetOutputOut),
161 new SharedMemorySetFunctor (&SharedMemory::bbSetOutputOut) ) );
162 BBTK_END_DESCRIBE_BLACK_BOX(SharedMemory);
163 //===========================================================================
168 #endif // __bbstdSharedMemory_h_INCLUDED_H__