]> Creatis software - bbtk.git/blob - kernel/src/bbtkConnection.h
Changes under win32
[bbtk.git] / kernel / src / bbtkConnection.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkConnection.h,v $
4   Language:  C++
5   Date:      $Date: 2009/04/21 14:36:51 $
6   Version:   $Revision: 1.13 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
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.
20 *
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
25 *  liability. 
26 *
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 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32  *\file
33  *\brief Class bbtk::Connection
34  */
35 /**
36  *\class bbtk::Connection
37  *\brief DDD
38  *
39  */
40
41 #ifndef __bbtkConnection_h__
42 #define __bbtkConnection_h__
43
44 #include "bbtkSystem.h"
45 #include "bbtkObject.h"
46
47 #include <string>
48
49 namespace bbtk
50 {
51
52   class Factory;
53   BBTK_FORWARD_DECLARE_POINTER(Factory);
54   class BlackBox;
55   BBTK_FORWARD_DECLARE_POINTER(BlackBox);
56   class BlackBoxInputConnector;
57   class BlackBoxOutputConnector;
58
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;
67
68   BBTK_EXPORT const std::string& GetIOStatusString( IOStatus );
69
70
71   class BBTK_EXPORT Connection : public Object
72   {
73      BBTK_OBJECT_INTERFACE(Connection);
74     typedef Object Superclass;
75   public:
76
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);
82     /// Dtor
83     //    ~Connection();
84
85     // void Delete();
86     
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();
94     
95     /// Change callback
96     void OnOutputChange(BlackBoxPointer, const std::string&, 
97                         IOStatus);
98
99     std::string GetFullName() const; 
100
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; }
109     
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; }
118
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; }
127
128     /// Checks that the connection is ok (throws error if not)
129     void Check() const;
130     
131   protected:
132     /// Black box origin of the connection
133     BlackBoxPointer mFrom;
134     BlackBoxWeakPointer mOriginalFrom;
135     /// Output of mFrom which is connected
136     std::string mOutput;
137     std::string mOriginalOutput;
138     /// Output connector of mFrom which is connected
139     //  BlackBoxOutputConnector* mOutputConnector;
140     /// Black box destination of the connection
141     BlackBoxPointer mTo;
142     BlackBoxWeakPointer mOriginalTo;
143     /// Input of mTo which is connected
144     std::string mInput;
145     std::string mOriginalInput;
146     /// Input connector of mTo which is connected
147     //  BlackBoxInputConnector* mInputConnector;
148     /// Adaptor black box if needed
149     BlackBoxPointer mAdaptor;
150
151     /// The factory used to create adaptors
152     const FactoryWeakPointer mFactory;
153
154     /// Is the connection input type is any<thing> ?
155     bool mFromAny;
156
157     /// Is the connection output type is any<thing> ?
158     bool mToAny;
159
160
161     /// Have to do dynamic_cast ?
162     bool mDoDynamicCast;
163
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   );
169   public:   
170     void TransferData(); 
171
172   private:
173     /// Ctor 
174     Connection(BlackBoxPointer from, const std::string& output,
175                BlackBoxPointer to, const std::string& input,
176                const FactoryPointer f);
177     /// Ctor 
178     Connection(BlackBoxPointer from, const std::string& output,
179                BlackBoxPointer to, const std::string& input);
180
181   };
182
183 }// namespace bbtk
184
185 #endif
186