]> Creatis software - bbtk.git/blob - kernel/src/bbtkConnection.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkConnection.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkConnection.h,v $
5   Language:  C++
6   Date:      $Date: 2008/07/25 07:44:12 $
7   Version:   $Revision: 1.7 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See doc/license.txt or
11   http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 /**
19  *\file
20  *\brief Class bbtk::Connection
21  */
22 /**
23  *\class bbtk::Connection
24  *\brief DDD
25  *
26  */
27
28 #ifndef __bbtkConnection_h__
29 #define __bbtkConnection_h__
30
31 #include "bbtkSystem.h"
32 #include "bbtkObject.h"
33
34 #include <string>
35
36 namespace bbtk
37 {
38
39   class Factory;
40   BBTK_FORWARD_DECLARE_POINTER(Factory);
41   class BlackBox;
42   BBTK_FORWARD_DECLARE_POINTER(BlackBox);
43   class BlackBoxInputConnector;
44   class BlackBoxOutputConnector;
45
46   /// 
47   typedef int IOStatus;
48   /// 
49   const int MODIFIED = 0;
50   /// 
51   const int UPTODATE = 1;
52   /// 
53   const int UPDATING = 2;
54
55
56   class BBTK_EXPORT Connection : public Object
57   {
58      BBTK_OBJECT_INTERFACE(Connection);
59     typedef Object Superclass;
60   public:
61
62     static Pointer New(BlackBoxPointer from, const std::string& output,
63                        BlackBoxPointer to, const std::string& input,
64                        const FactoryPointer f);
65     static Pointer New(BlackBoxPointer from, const std::string& output,
66                        BlackBoxPointer to, const std::string& input);
67     /// Dtor
68     //    ~Connection();
69
70     // void Delete();
71     
72     /// Amont direction pipeline processing
73     /// 1) call bbBackwardUpdate(this) on the upstream box
74     /// 2) copies the upstream box output to the downstream box input adapting it if needed
75     virtual IOStatus BackwardUpdate();
76
77     /// Aval direction pipeline processing :
78     /// 1) copies the upstream box output to the downstream box input adapting it if needed
79     /// 2) call bbForwardUpdate(this) on the downstream box
80     //    virtual void ForwardUpdate();
81
82     virtual void SetModifiedStatus();
83     std::string GetFullName() const; 
84
85     /// Returns the original initial black box of the connection
86     BlackBoxPointer GetOriginalBlackBoxFrom() const { return mOriginalFrom.lock(); }
87     /// Returns the origianl final black box of the connection
88     BlackBoxPointer GetOriginalBlackBoxTo() const { return mOriginalTo.lock(); }
89     /// Returns the original output of the initial black box of the connection
90     const std::string& GetOriginalBlackBoxFromOutput() const { return mOriginalOutput; }
91     /// Returns the original input of the final black box of the connection
92     const std::string& GetOriginalBlackBoxToInput() const { return mOriginalInput; }
93     
94     /// Returns the initial black box of the connection
95     BlackBoxPointer GetBlackBoxFrom() const { return mFrom; }
96     /// Returns the final black box of the connection
97     BlackBoxPointer GetBlackBoxTo() const { return mTo; }
98     /// Returns the output of the initial black box of the connection
99     const std::string& GetBlackBoxFromOutput() const { return mOutput; }
100     /// Returns the input of the final black box of the connection
101     const std::string& GetBlackBoxToInput() const { return mInput; }
102
103     /// Sets the initial black box of the connection
104     void SetBlackBoxFrom(BlackBoxPointer b) { mFrom = b; }
105     /// Sets the final black box of the connection
106     void SetBlackBoxTo(BlackBoxPointer b) { mTo = b; }
107     /// Sets the output of the initial black box of the connection
108     void SetBlackBoxFromOutput(const std::string& o) { mOutput = o; }
109     /// Sets the input of the final black box of the connection
110     void SetBlackBoxToInput(const std::string& o) { mInput = o; }
111
112     /// Checks that the connection is ok (throws error if not)
113     void Check() const;
114     
115   protected:
116     /// Black box origin of the connection
117     BlackBoxPointer mFrom;
118     BlackBoxWeakPointer mOriginalFrom;
119     /// Output of mFrom which is connected
120     std::string mOutput;
121     std::string mOriginalOutput;
122     /// Output connector of mFrom which is connected
123     //  BlackBoxOutputConnector* mOutputConnector;
124     /// Black box destination of the connection
125     BlackBoxPointer mTo;
126     BlackBoxWeakPointer mOriginalTo;
127     /// Input of mTo which is connected
128     std::string mInput;
129     std::string mOriginalInput;
130     /// Input connector of mTo which is connected
131     //  BlackBoxInputConnector* mInputConnector;
132     /// Adaptor black box if needed
133     BlackBoxPointer mAdaptor;
134
135     /// The factory used to create adaptors
136     const FactoryWeakPointer mFactory;
137
138     /// Is the connection input type is any<thing> ?
139     bool mFromAny;
140
141     /// Is the connection output type is any<thing> ?
142     bool mToAny;
143
144
145     /// Have to do dynamic_cast ?
146     bool mDoDynamicCast;
147
148     /// Ctor with the black box from and to and their input and output
149     /// and a dummy int to differentiate from the public constructor.
150     /// Sets the members but does not test compatibility (used by bbtk::AdaptiveConnection)
151     //  Connection(BlackBox* from, const std::string& output,
152     //         BlackBox* to, const std::string& input, int   );
153     
154     void TransferData(); 
155
156   private:
157     /// Ctor 
158     Connection(BlackBoxPointer from, const std::string& output,
159                BlackBoxPointer to, const std::string& input,
160                const FactoryPointer f);
161     /// Ctor 
162     Connection(BlackBoxPointer from, const std::string& output,
163                BlackBoxPointer to, const std::string& input);
164
165   };
166
167 }// namespace bbtk
168
169 #endif
170