]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/InputPort.hxx
Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[modules/yacs.git] / src / engine / InputPort.hxx
1 #ifndef __INPUTPORT_HXX__
2 #define __INPUTPORT_HXX__
3
4 #include "Any.hxx"
5 #include "InPort.hxx"
6 #include "Runtime.hxx"
7 #include "DataFlowPort.hxx"
8 #include "ConversionException.hxx"
9 #include "yacsconfig.h"
10
11 #include <string>
12
13 namespace YACS
14 {
15   namespace ENGINE
16   {
17     class OutPort;
18 /*! \brief Base class for Input Ports
19  *
20  * \ingroup Ports
21  *
22  */
23     class InputPort : public DataFlowPort, public InPort
24     {
25       friend class Runtime; // for port creation
26       friend class OutPort;
27     public:
28       static const char NAME[];
29     public:
30       virtual ~InputPort();
31
32       std::string getNameOfTypeOfCurrentInstance() const;
33       //! returns the final physical port behind 'this'.
34 #ifdef NOCOVARIANT
35       virtual InPort *getPublicRepresentant() { return this; }
36 #else
37       virtual InputPort *getPublicRepresentant() { return this; }
38 #endif
39       virtual bool isIntermediate() const { return false; }
40       virtual bool edIsManuallyInitialized() const;
41       //!soon deprecated
42       bool edIsInitialized() const;
43
44       template<class T>
45       void edInit(T value);
46       void edInit(Any *value);
47       void edInit(const std::string& impl,const void* value);
48       virtual void edRemoveManInit();
49       virtual void checkBasicConsistency() const throw(Exception);
50       virtual void exInit(bool start);
51       virtual void exSaveInit() = 0;
52       virtual void exRestoreInit() = 0;
53       virtual InputPort *clone(Node *newHelder) const = 0;
54       virtual bool isEmpty();
55
56       virtual void *get() const = 0;
57       virtual void put(const void *data) throw(ConversionException) = 0;
58       virtual std::string dump();
59       virtual void setStringRef(std::string strRef);
60       virtual std::string typeName() {return "YACS__ENGINE__InputPort";}
61     protected:
62       InputPort(const InputPort& other, Node *newHelder);
63       InputPort(const std::string& name, Node *node, TypeCode* type);
64     protected:
65       Any *_initValue;
66       std::string _stringRef;
67     };
68
69 /*! \brief Base class for Proxy Input Ports
70  *
71  * \ingroup Ports
72  *
73  */
74     class ProxyPort : public InputPort
75     {
76     public:
77       ProxyPort(InputPort* p);
78       ~ProxyPort();
79       
80       void edRemoveAllLinksLinkedWithMe() throw(Exception);
81       InputPort *clone(Node *newHelder) const;
82       void edNotifyReferencedBy(OutPort *fromPort);
83       void edNotifyDereferencedBy(OutPort *fromPort);
84       std::set<OutPort *> edSetOutPort() const;
85 #ifdef NOCOVARIANT
86       InPort *getPublicRepresentant();
87 #else
88       InputPort *getPublicRepresentant();
89 #endif
90       void *get() const;
91       virtual void put(const void *data) throw(ConversionException) ;
92       int edGetNumberOfLinks() const;
93       bool isIntermediate() const { return true; }
94       void exRestoreInit();
95       void exSaveInit();
96       void getAllRepresentants(std::set<InPort *>& repr) const;
97       virtual std::string typeName() {return "YACS__ENGINE__ProxyPort";}
98     protected:
99       InputPort* _port;
100     };
101
102     template<class T>
103     void InputPort::edInit(T value)
104     { 
105       InputPort *manuallySet=getRuntime()->adapt(this,
106                                                  Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME,_type);
107       Any* any=AtomAny::New(value);
108       manuallySet->put((const void *) any);
109       if(manuallySet!=this)
110         delete manuallySet;
111       any->decrRef();
112       exSaveInit();
113       modified();
114     }
115   }
116 }
117
118 #endif