]> Creatis software - bbtk.git/blob - kernel/src/bbtkConnection.h
754004144c12a6fda619495507dfb3a10614406d
[bbtk.git] / kernel / src / bbtkConnection.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkConnection.h,v $
4   Language:  C++
5   Date:      $Date: 2008/10/17 08:18:13 $
6   Version:   $Revision: 1.8 $
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   /// 
60   typedef int IOStatus;
61   /// 
62   const int MODIFIED = 0;
63   /// 
64   const int UPTODATE = 1;
65   /// 
66   const int UPDATING = 2;
67
68
69   class BBTK_EXPORT Connection : public Object
70   {
71      BBTK_OBJECT_INTERFACE(Connection);
72     typedef Object Superclass;
73   public:
74
75     static Pointer New(BlackBoxPointer from, const std::string& output,
76                        BlackBoxPointer to, const std::string& input,
77                        const FactoryPointer f);
78     static Pointer New(BlackBoxPointer from, const std::string& output,
79                        BlackBoxPointer to, const std::string& input);
80     /// Dtor
81     //    ~Connection();
82
83     // void Delete();
84     
85     /// Amont direction pipeline processing
86     /// 1) call bbBackwardUpdate(this) on the upstream box
87     /// 2) copies the upstream box output to the downstream box input adapting it if needed
88     virtual IOStatus BackwardUpdate();
89
90     /// Aval direction pipeline processing :
91     /// 1) copies the upstream box output to the downstream box input adapting it if needed
92     /// 2) call bbForwardUpdate(this) on the downstream box
93     //    virtual void ForwardUpdate();
94
95     virtual void SetModifiedStatus();
96     std::string GetFullName() const; 
97
98     /// Returns the original initial black box of the connection
99     BlackBoxPointer GetOriginalBlackBoxFrom() const { return mOriginalFrom.lock(); }
100     /// Returns the origianl final black box of the connection
101     BlackBoxPointer GetOriginalBlackBoxTo() const { return mOriginalTo.lock(); }
102     /// Returns the original output of the initial black box of the connection
103     const std::string& GetOriginalBlackBoxFromOutput() const { return mOriginalOutput; }
104     /// Returns the original input of the final black box of the connection
105     const std::string& GetOriginalBlackBoxToInput() const { return mOriginalInput; }
106     
107     /// Returns the initial black box of the connection
108     BlackBoxPointer GetBlackBoxFrom() const { return mFrom; }
109     /// Returns the final black box of the connection
110     BlackBoxPointer GetBlackBoxTo() const { return mTo; }
111     /// Returns the output of the initial black box of the connection
112     const std::string& GetBlackBoxFromOutput() const { return mOutput; }
113     /// Returns the input of the final black box of the connection
114     const std::string& GetBlackBoxToInput() const { return mInput; }
115
116     /// Sets the initial black box of the connection
117     void SetBlackBoxFrom(BlackBoxPointer b) { mFrom = b; }
118     /// Sets the final black box of the connection
119     void SetBlackBoxTo(BlackBoxPointer b) { mTo = b; }
120     /// Sets the output of the initial black box of the connection
121     void SetBlackBoxFromOutput(const std::string& o) { mOutput = o; }
122     /// Sets the input of the final black box of the connection
123     void SetBlackBoxToInput(const std::string& o) { mInput = o; }
124
125     /// Checks that the connection is ok (throws error if not)
126     void Check() const;
127     
128   protected:
129     /// Black box origin of the connection
130     BlackBoxPointer mFrom;
131     BlackBoxWeakPointer mOriginalFrom;
132     /// Output of mFrom which is connected
133     std::string mOutput;
134     std::string mOriginalOutput;
135     /// Output connector of mFrom which is connected
136     //  BlackBoxOutputConnector* mOutputConnector;
137     /// Black box destination of the connection
138     BlackBoxPointer mTo;
139     BlackBoxWeakPointer mOriginalTo;
140     /// Input of mTo which is connected
141     std::string mInput;
142     std::string mOriginalInput;
143     /// Input connector of mTo which is connected
144     //  BlackBoxInputConnector* mInputConnector;
145     /// Adaptor black box if needed
146     BlackBoxPointer mAdaptor;
147
148     /// The factory used to create adaptors
149     const FactoryWeakPointer mFactory;
150
151     /// Is the connection input type is any<thing> ?
152     bool mFromAny;
153
154     /// Is the connection output type is any<thing> ?
155     bool mToAny;
156
157
158     /// Have to do dynamic_cast ?
159     bool mDoDynamicCast;
160
161     /// Ctor with the black box from and to and their input and output
162     /// and a dummy int to differentiate from the public constructor.
163     /// Sets the members but does not test compatibility (used by bbtk::AdaptiveConnection)
164     //  Connection(BlackBox* from, const std::string& output,
165     //         BlackBox* to, const std::string& input, int   );
166     
167     void TransferData(); 
168
169   private:
170     /// Ctor 
171     Connection(BlackBoxPointer from, const std::string& output,
172                BlackBoxPointer to, const std::string& input,
173                const FactoryPointer f);
174     /// Ctor 
175     Connection(BlackBoxPointer from, const std::string& output,
176                BlackBoxPointer to, const std::string& input);
177
178   };
179
180 }// namespace bbtk
181
182 #endif
183