Salome HOME
Correction of bug revealed by otgui with multi lock/unlock session.
[modules/yacs.git] / src / evalyfx / YACSEvalPort.hxx
1 // Copyright (C) 2012-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 // Author : Anthony Geay (EDF R&D)
20
21 #ifndef __YACSEVALPORT_HXX__
22 #define __YACSEVALPORT_HXX__
23
24 #include "YACSEvalYFXExport.hxx"
25
26 #include <string>
27
28 namespace YACS
29 {
30   namespace ENGINE
31   {
32     class Any;
33     class DataPort;
34     class InputPort;
35     class OutputPort;
36     class InputPyPort;
37   }
38 }
39
40 class YACSEvalSeqAny;
41
42 class YACSEvalAny
43 {
44 public:
45   YACSEVALYFX_EXPORT virtual ~YACSEvalAny() { }
46   YACSEVALYFX_EXPORT virtual std::string getTypeOfData() const = 0;
47   YACSEVALYFX_EXPORT virtual int toInt() const = 0;
48   YACSEVALYFX_EXPORT virtual double toDouble() const = 0;
49   YACSEVALYFX_EXPORT virtual YACSEvalAny *deepCpy() const = 0;
50 };
51
52 class YACSEvalAnyDouble : public YACSEvalAny
53 {
54 public:
55   YACSEVALYFX_EXPORT YACSEvalAnyDouble(double val):_v(val) { }
56   YACSEVALYFX_EXPORT std::string getTypeOfData() const { return std::string(TYPE_REPR); }
57   YACSEVALYFX_EXPORT int toInt() const;
58   YACSEVALYFX_EXPORT double toDouble() const;
59   YACSEVALYFX_EXPORT YACSEvalAnyDouble *deepCpy() const;
60   YACSEVALYFX_EXPORT ~YACSEvalAnyDouble() { }
61 private:
62   double _v;
63 public:
64   static const char TYPE_REPR[];
65 };
66
67 class YACSEvalAnyInt : public YACSEvalAny
68 {
69 public:
70   YACSEVALYFX_EXPORT YACSEvalAnyInt(int val):_v(val) { }
71   YACSEVALYFX_EXPORT std::string getTypeOfData() const { return std::string(TYPE_REPR); }
72   YACSEVALYFX_EXPORT int toInt() const;
73   YACSEVALYFX_EXPORT double toDouble() const;
74   YACSEVALYFX_EXPORT YACSEvalAnyInt *deepCpy() const;
75   YACSEVALYFX_EXPORT ~YACSEvalAnyInt() { }
76 private:
77   int _v;
78 public:
79   static const char TYPE_REPR[];
80 };
81
82 class YACSEvalPort
83 {
84 public:
85   YACSEVALYFX_EXPORT virtual std::string getTypeOfData() const = 0;
86   YACSEVALYFX_EXPORT virtual ~YACSEvalPort() { }
87 public:
88   YACSEVALYFX_EXPORT static bool IsInputPortPublishable(const YACS::ENGINE::InputPort *port);
89   YACSEVALYFX_EXPORT static bool IsOutputPortPublishable(const YACS::ENGINE::OutputPort *port);
90 protected:
91   YACSEVALYFX_EXPORT static std::string GetTypeOfData(const YACS::ENGINE::DataPort *port);
92 };
93
94 class YACSEvalInputPort : public YACSEvalPort
95 {
96 public:
97   YACSEVALYFX_EXPORT YACSEvalInputPort(YACS::ENGINE::InputPort *ptr);
98   YACSEVALYFX_EXPORT std::string getName() const;
99   YACSEVALYFX_EXPORT std::string getTypeOfData() const;
100   YACSEVALYFX_EXPORT bool isOKForLock() const;
101   YACSEVALYFX_EXPORT bool isLocked() const;
102   //
103   YACSEVALYFX_EXPORT bool hasDefaultValueDefined() const;
104   YACSEVALYFX_EXPORT YACSEvalAny *getDefaultValueDefined() const;
105   YACSEVALYFX_EXPORT void setDefaultValue(const YACSEvalAny *parameter);
106   YACSEVALYFX_EXPORT void setSequenceOfValuesToEval(const YACSEvalSeqAny* vals);
107   YACSEVALYFX_EXPORT bool hasSequenceOfValuesToEval() const;
108   YACSEVALYFX_EXPORT bool isRandomVar() const { return _isRandom; }
109   YACSEVALYFX_EXPORT void declareRandomnessStatus(bool isRandom);
110   //
111   YACSEVALYFX_EXPORT YACS::ENGINE::InputPort *getUndergroundPtr() const { return _ptr; }
112   YACSEVALYFX_EXPORT std::size_t initializeUndergroundWithSeq() const;
113   //
114   YACSEVALYFX_EXPORT virtual ~YACSEvalInputPort();
115   void lock() const { _isLocked=true; }
116   void unlock() const { _isLocked=false; _isRandom=false; }
117   void setUndergroundPortToBeSet(YACS::ENGINE::InputPyPort *p) const;
118 private:
119   YACSEvalAny *convertFromInternalAnyToExternal(YACS::ENGINE::Any *data) const;
120   void checkForNonConstMethod() const;
121 private:
122   YACS::ENGINE::InputPort * _ptr;
123   YACSEvalSeqAny *_mySeq;
124   mutable bool _isRandom;
125   mutable bool _isLocked;
126   mutable YACS::ENGINE::InputPyPort *_undergroundPort;
127 };
128
129 class YACSEvalOutputPort : public YACSEvalPort
130 {
131 public:
132   YACSEVALYFX_EXPORT YACSEvalOutputPort(YACS::ENGINE::OutputPort *ptr);
133   YACSEVALYFX_EXPORT std::string getName() const;
134   YACSEVALYFX_EXPORT std::string getTypeOfData() const;
135   //
136   YACSEVALYFX_EXPORT YACS::ENGINE::OutputPort *getUndergroundPtr() const { return _ptr; }
137   //
138 private:
139   YACS::ENGINE::OutputPort * _ptr;
140 };
141
142 #endif