]> Creatis software - bbtk.git/blob - kernel/src/bbtkConnection.h
#2498 BBTKFeatureNewNormalwt-version kernel
[bbtk.git] / kernel / src / bbtkConnection.h
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbtkConnection.h,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:49:01 $
33   Version:   $Revision: 1.14 $
34 =========================================================================*/
35
36                                                                        
37
38 /**
39  *\file
40  *\brief Class bbtk::Connection
41  */
42 /**
43  *\class bbtk::Connection
44  *\brief DDD
45  *
46  */
47
48 #ifndef __bbtkConnection_h__
49 #define __bbtkConnection_h__
50
51 #include "bbtkSystem.h"
52 #include "bbtkObject.h"
53
54 #include <string>
55
56 namespace bbtk
57 {
58
59   class Factory;
60   BBTK_FORWARD_DECLARE_POINTER(Factory);
61   class BlackBox;
62   BBTK_FORWARD_DECLARE_POINTER(BlackBox);
63   class BlackBoxInputConnector;
64   class BlackBoxOutputConnector;
65
66   /// The type of input / output status 
67   typedef unsigned char IOStatus;
68   /// Up-to-date status value
69   const IOStatus UPTODATE  = 0;
70   /// Modified status value
71   const IOStatus MODIFIED  = 1;
72   /// Out-of-date status value
73   const IOStatus OUTOFDATE = 2;
74
75   BBTK_EXPORT const std::string& GetIOStatusString( IOStatus );
76
77
78   class BBTK_EXPORT Connection : public Object
79   {
80      BBTK_OBJECT_INTERFACE(Connection);
81     typedef Object Superclass;
82   public:
83
84     static Pointer New(BlackBoxPointer from, const std::string& output,
85                        BlackBoxPointer to, const std::string& input,
86                        const FactoryPointer f);
87     static Pointer New(BlackBoxPointer from, const std::string& output,
88                        BlackBoxPointer to, const std::string& input);
89     /// Dtor
90     //    ~Connection();
91
92     // void Delete();
93     
94     /// Pipeline processing method
95     /// 1) call bbRecursiveExecute(this) on the from box
96     /// 2) copies the from box output to the to box input 
97     ///    adapting it if needed
98     /// 3) sets the new IOStatus of the to box input to the 
99     ///    status of the from box output
100     void RecursiveExecute();
101     
102     /// Change callback
103     void OnOutputChange(BlackBoxPointer, const std::string&, 
104                         IOStatus);
105
106     std::string GetFullName() const; 
107
108     /// Returns the original initial black box of the connection
109     BlackBoxPointer GetOriginalBlackBoxFrom() const { return mOriginalFrom.lock(); }
110     /// Returns the origianl final black box of the connection
111     BlackBoxPointer GetOriginalBlackBoxTo() const { return mOriginalTo.lock(); }
112     /// Returns the original output of the initial black box of the connection
113     const std::string& GetOriginalBlackBoxFromOutput() const { return mOriginalOutput; }
114     /// Returns the original input of the final black box of the connection
115     const std::string& GetOriginalBlackBoxToInput() const { return mOriginalInput; }
116     
117     /// Returns the initial black box of the connection
118     BlackBoxPointer GetBlackBoxFrom() const { return mFrom; }
119     /// Returns the final black box of the connection
120     BlackBoxPointer GetBlackBoxTo() const { return mTo; }
121     /// Returns the output of the initial black box of the connection
122     const std::string& GetBlackBoxFromOutput() const { return mOutput; }
123     /// Returns the input of the final black box of the connection
124     const std::string& GetBlackBoxToInput() const { return mInput; }
125
126     /// Sets the initial black box of the connection
127     void SetBlackBoxFrom(BlackBoxPointer b) { mFrom = b; }
128     /// Sets the final black box of the connection
129     void SetBlackBoxTo(BlackBoxPointer b) { mTo = b; }
130     /// Sets the output of the initial black box of the connection
131     void SetBlackBoxFromOutput(const std::string& o) { mOutput = o; }
132     /// Sets the input of the final black box of the connection
133     void SetBlackBoxToInput(const std::string& o) { mInput = o; }
134
135     /// Checks that the connection is ok (throws error if not)
136     void Check() const;
137     
138   protected:
139     /// Black box origin of the connection
140     BlackBoxPointer mFrom;
141     BlackBoxWeakPointer mOriginalFrom;
142     /// Output of mFrom which is connected
143     std::string mOutput;
144     std::string mOriginalOutput;
145     /// Output connector of mFrom which is connected
146     //  BlackBoxOutputConnector* mOutputConnector;
147     /// Black box destination of the connection
148     BlackBoxPointer mTo;
149     BlackBoxWeakPointer mOriginalTo;
150     /// Input of mTo which is connected
151     std::string mInput;
152     std::string mOriginalInput;
153     /// Input connector of mTo which is connected
154     //  BlackBoxInputConnector* mInputConnector;
155     /// Adaptor black box if needed
156     BlackBoxPointer mAdaptor;
157
158     /// The factory used to create adaptors
159     const FactoryWeakPointer mFactory;
160
161     /// Is the connection input type is any<thing> ?
162     bool mFromAny;
163
164     /// Is the connection output type is any<thing> ?
165     bool mToAny;
166
167
168     /// Have to do dynamic_cast ?
169     bool mDoDynamicCast;
170
171     /// Ctor with the black box from and to and their input and output
172     /// and a dummy int to differentiate from the public constructor.
173     /// Sets the members but does not test compatibility (used by bbtk::AdaptiveConnection)
174     //  Connection(BlackBox* from, const std::string& output,
175     //         BlackBox* to, const std::string& input, int   );
176   public:   
177     void TransferData(); 
178
179   private:
180     /// Ctor 
181     Connection(BlackBoxPointer from, const std::string& output,
182                BlackBoxPointer to, const std::string& input,
183                const FactoryPointer f);
184     /// Ctor 
185     Connection(BlackBoxPointer from, const std::string& output,
186                BlackBoxPointer to, const std::string& input);
187
188   };
189
190 }// namespace bbtk
191
192 #endif
193