1 /*=========================================================================
3 Module: $RCSfile: bbtkConnection.h,v $
5 Date: $Date: 2009/04/21 14:36:51 $
6 Version: $Revision: 1.13 $
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 * ------------------------------------------------------------------------ */
33 *\brief Class bbtk::Connection
36 *\class bbtk::Connection
41 #ifndef __bbtkConnection_h__
42 #define __bbtkConnection_h__
44 #include "bbtkSystem.h"
45 #include "bbtkObject.h"
53 BBTK_FORWARD_DECLARE_POINTER(Factory);
55 BBTK_FORWARD_DECLARE_POINTER(BlackBox);
56 class BlackBoxInputConnector;
57 class BlackBoxOutputConnector;
59 /// The type of input / output status
60 typedef unsigned char IOStatus;
61 /// Up-to-date status value
62 const IOStatus UPTODATE = 0;
63 /// Modified status value
64 const IOStatus MODIFIED = 1;
65 /// Out-of-date status value
66 const IOStatus OUTOFDATE = 2;
68 BBTK_EXPORT const std::string& GetIOStatusString( IOStatus );
71 class BBTK_EXPORT Connection : public Object
73 BBTK_OBJECT_INTERFACE(Connection);
74 typedef Object Superclass;
77 static Pointer New(BlackBoxPointer from, const std::string& output,
78 BlackBoxPointer to, const std::string& input,
79 const FactoryPointer f);
80 static Pointer New(BlackBoxPointer from, const std::string& output,
81 BlackBoxPointer to, const std::string& input);
87 /// Pipeline processing method
88 /// 1) call bbRecursiveExecute(this) on the from box
89 /// 2) copies the from box output to the to box input
90 /// adapting it if needed
91 /// 3) sets the new IOStatus of the to box input to the
92 /// status of the from box output
93 void RecursiveExecute();
96 void OnOutputChange(BlackBoxPointer, const std::string&,
99 std::string GetFullName() const;
101 /// Returns the original initial black box of the connection
102 BlackBoxPointer GetOriginalBlackBoxFrom() const { return mOriginalFrom.lock(); }
103 /// Returns the origianl final black box of the connection
104 BlackBoxPointer GetOriginalBlackBoxTo() const { return mOriginalTo.lock(); }
105 /// Returns the original output of the initial black box of the connection
106 const std::string& GetOriginalBlackBoxFromOutput() const { return mOriginalOutput; }
107 /// Returns the original input of the final black box of the connection
108 const std::string& GetOriginalBlackBoxToInput() const { return mOriginalInput; }
110 /// Returns the initial black box of the connection
111 BlackBoxPointer GetBlackBoxFrom() const { return mFrom; }
112 /// Returns the final black box of the connection
113 BlackBoxPointer GetBlackBoxTo() const { return mTo; }
114 /// Returns the output of the initial black box of the connection
115 const std::string& GetBlackBoxFromOutput() const { return mOutput; }
116 /// Returns the input of the final black box of the connection
117 const std::string& GetBlackBoxToInput() const { return mInput; }
119 /// Sets the initial black box of the connection
120 void SetBlackBoxFrom(BlackBoxPointer b) { mFrom = b; }
121 /// Sets the final black box of the connection
122 void SetBlackBoxTo(BlackBoxPointer b) { mTo = b; }
123 /// Sets the output of the initial black box of the connection
124 void SetBlackBoxFromOutput(const std::string& o) { mOutput = o; }
125 /// Sets the input of the final black box of the connection
126 void SetBlackBoxToInput(const std::string& o) { mInput = o; }
128 /// Checks that the connection is ok (throws error if not)
132 /// Black box origin of the connection
133 BlackBoxPointer mFrom;
134 BlackBoxWeakPointer mOriginalFrom;
135 /// Output of mFrom which is connected
137 std::string mOriginalOutput;
138 /// Output connector of mFrom which is connected
139 // BlackBoxOutputConnector* mOutputConnector;
140 /// Black box destination of the connection
142 BlackBoxWeakPointer mOriginalTo;
143 /// Input of mTo which is connected
145 std::string mOriginalInput;
146 /// Input connector of mTo which is connected
147 // BlackBoxInputConnector* mInputConnector;
148 /// Adaptor black box if needed
149 BlackBoxPointer mAdaptor;
151 /// The factory used to create adaptors
152 const FactoryWeakPointer mFactory;
154 /// Is the connection input type is any<thing> ?
157 /// Is the connection output type is any<thing> ?
161 /// Have to do dynamic_cast ?
164 /// Ctor with the black box from and to and their input and output
165 /// and a dummy int to differentiate from the public constructor.
166 /// Sets the members but does not test compatibility (used by bbtk::AdaptiveConnection)
167 // Connection(BlackBox* from, const std::string& output,
168 // BlackBox* to, const std::string& input, int );
174 Connection(BlackBoxPointer from, const std::string& output,
175 BlackBoxPointer to, const std::string& input,
176 const FactoryPointer f);
178 Connection(BlackBoxPointer from, const std::string& output,
179 BlackBoxPointer to, const std::string& input);