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