Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[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 "TypeCode.hxx"
8 #include "DataFlowPort.hxx"
9 #include "ConversionException.hxx"
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       virtual InputPort *getPublicRepresentant() { return this; }
35       virtual bool isIntermediate() const { return false; }
36       virtual bool edIsManuallyInitialized() const;
37       //!soon deprecated
38       bool edIsInitialized() const;
39
40       template<class T>
41       void edInit(T value);
42       void edInit(Any *value);
43       void edInit(const std::string& impl,const void* value);
44       virtual void edRemoveManInit();
45       void checkBasicConsistency() const throw(Exception);
46       virtual void exInit(bool start);
47       virtual void exSaveInit() = 0;
48       virtual void exRestoreInit() = 0;
49       virtual InputPort *clone(Node *newHelder) const = 0;
50       virtual bool isEmpty();
51
52       virtual void *get() const throw(Exception) = 0;
53       virtual void put(const void *data) throw(ConversionException) = 0;
54       virtual std::string dump();
55       virtual void setStringRef(std::string strRef);
56     protected:
57       InputPort(const InputPort& other, Node *newHelder);
58       InputPort(const std::string& name, Node *node, TypeCode* type);
59     protected:
60       Any *_initValue;
61       std::string _stringRef;
62     };
63
64 /*! \brief Base class for Proxy Input Ports
65  *
66  * \ingroup Ports
67  *
68  */
69     class ProxyPort : public InputPort
70     {
71     public:
72       ProxyPort(InputPort* p);
73       ~ProxyPort();
74       
75       void edRemoveAllLinksLinkedWithMe() throw(Exception);
76       InputPort *clone(Node *newHelder) const;
77       void edNotifyReferencedBy(OutPort *fromPort);
78       void edNotifyDereferencedBy(OutPort *fromPort);
79       std::set<OutPort *> edSetOutPort() const;
80       InputPort *getPublicRepresentant();
81       void *get() const throw(Exception);
82       virtual void put(const void *data) throw(ConversionException) ;
83       int edGetNumberOfLinks() const;
84       bool isIntermediate() const { return true; }
85       void exRestoreInit();
86       void exSaveInit();
87       void getAllRepresentants(std::set<InPort *>& repr) const;
88     protected:
89       InputPort* _port;
90     };
91
92     template<class T>
93     void InputPort::edInit(T value)
94     { 
95       InputPort *manuallySet=getRuntime()->adapt(this,
96                                                  Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME,_type);
97       Any* any=AtomAny::New(value);
98       manuallySet->put((const void *) any);
99       if(manuallySet!=this)
100         delete manuallySet;
101       any->decrRef();
102       exSaveInit();
103     }
104   }
105 }
106
107 #endif