Salome HOME
80c565f2236f9ce5bf39af1f1d33071dead3cea7
[modules/yacs.git] / src / engine / InputPort.hxx
1 // Copyright (C) 2006-2015  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef __INPUTPORT_HXX__
21 #define __INPUTPORT_HXX__
22
23 #include "YACSlibEngineExport.hxx"
24 #include "Any.hxx"
25 #include "InPort.hxx"
26 #include "Runtime.hxx"
27 #include "DataFlowPort.hxx"
28 #include "ConversionException.hxx"
29 #include "yacsconfig.h"
30
31 #include <string>
32
33 namespace YACS
34 {
35   namespace ENGINE
36   {
37     class OutPort;
38 /*! \brief Base class for Input Ports
39  *
40  * \ingroup Ports
41  *
42  */
43     class YACSLIBENGINE_EXPORT InputPort : public DataFlowPort, public InPort
44     {
45       friend class Runtime; // for port creation
46       friend class OutPort;
47     public:
48       static const char NAME[];
49     public:
50       virtual ~InputPort();
51
52       std::string getNameOfTypeOfCurrentInstance() const;
53       //! returns the final physical port behind 'this'.
54 #ifdef NOCOVARIANT
55       virtual InPort *getPublicRepresentant() { return this; }
56 #else
57       virtual InputPort *getPublicRepresentant() { return this; }
58 #endif
59       virtual bool isIntermediate() const { return false; }
60       virtual bool edIsManuallyInitialized() const;
61       //!soon deprecated
62       bool edIsInitialized() const;
63
64       template<class T>
65       void edInit(T value);
66       void edInit(Any *value);
67       void edInit(const std::string& impl,const void* value);
68       virtual void edRemoveManInit();
69       virtual void checkBasicConsistency() const throw(Exception);
70       virtual void exInit(bool start);
71       virtual void exSaveInit() = 0;
72       virtual void exRestoreInit() = 0;
73       virtual InputPort *clone(Node *newHelder) const = 0;
74       virtual bool isEmpty();
75
76       virtual void *get() const = 0;
77       virtual void put(const void *data) throw(ConversionException) = 0;
78       virtual std::string dump();
79       virtual void setStringRef(std::string strRef);
80       virtual std::string typeName() {return "YACS__ENGINE__InputPort";}
81       bool canBeNull() const;
82     protected:
83       InputPort(const InputPort& other, Node *newHelder);
84       InputPort(const std::string& name, Node *node, TypeCode* type, bool canBeNull = false);
85     protected:
86       Any *_initValue;
87       std::string _stringRef;
88       bool _canBeNull;
89     };
90
91 /*! \brief Base class for Proxy Input Ports
92  *
93  * \ingroup Ports
94  *
95  */
96     class YACSLIBENGINE_EXPORT ProxyPort : public InputPort
97     {
98     public:
99       ProxyPort(InputPort* p);
100       ~ProxyPort();
101       
102       void edRemoveAllLinksLinkedWithMe() throw(Exception);
103       InputPort *clone(Node *newHelder) const;
104       void edNotifyReferencedBy(OutPort *fromPort);
105       void edNotifyDereferencedBy(OutPort *fromPort);
106       std::set<OutPort *> edSetOutPort() const;
107 #ifdef NOCOVARIANT
108       InPort *getPublicRepresentant();
109 #else
110       InputPort *getPublicRepresentant();
111 #endif
112       void *get() const;
113       virtual void put(const void *data) throw(ConversionException) ;
114       int edGetNumberOfLinks() const;
115       bool isIntermediate() const { return true; }
116       void exRestoreInit();
117       void exSaveInit();
118       void getAllRepresentants(std::set<InPort *>& repr) const;
119       virtual std::string typeName() {return "YACS__ENGINE__ProxyPort";}
120     protected:
121       InputPort* _port;
122     };
123
124     template<class T>
125     void InputPort::edInit(T value)
126     { 
127       Any* any=AtomAny::New(value);
128       try
129       {
130         edInit(any);
131         any->decrRef();
132       }
133       catch(ConversionException&)
134       {
135         any->decrRef();
136         throw;
137       }
138     }
139   }
140 }
141
142 #endif