Salome HOME
9380530b3491130069bdc0f1e7714512ce279b0a
[modules/yacs.git] / src / evalyfx / YACSEvalPort.hxx
1 // Copyright (C) 2012-2023  CEA, EDF
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   YACSEVALYFX_EXPORT 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   YACSEVALYFX_EXPORT 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 YACSEvalSeqAny *getSequenceOfValuesToEval() const { return _mySeq; }
109   YACSEVALYFX_EXPORT bool isRandomVar() const { return _isRandom; }
110   YACSEVALYFX_EXPORT void declareRandomnessStatus(bool isRandom);
111   //
112   YACSEVALYFX_EXPORT YACS::ENGINE::InputPort *getUndergroundPtr() const { return _ptr; }
113   YACSEVALYFX_EXPORT std::size_t initializeUndergroundWithSeq() const;
114   //
115   YACSEVALYFX_EXPORT virtual ~YACSEvalInputPort();
116   void lock() const { _isLocked=true; }
117   void unlock() const { _isLocked=false; _isRandom=false; }
118   void setUndergroundPortToBeSet(YACS::ENGINE::InputPyPort *p) const;
119 private:
120   YACSEvalAny *convertFromInternalAnyToExternal(YACS::ENGINE::Any *data) const;
121   void checkForNonConstMethod() const;
122 private:
123   YACS::ENGINE::InputPort * _ptr;
124   YACSEvalSeqAny *_mySeq;
125   mutable bool _isRandom;
126   mutable bool _isLocked;
127   mutable YACS::ENGINE::InputPyPort *_undergroundPort;
128 };
129
130 class YACSEvalOutputPort : public YACSEvalPort
131 {
132 public:
133   YACSEVALYFX_EXPORT YACSEvalOutputPort(YACS::ENGINE::OutputPort *ptr);
134   YACSEVALYFX_EXPORT std::string getName() const;
135   YACSEVALYFX_EXPORT std::string getTypeOfData() const;
136   YACSEVALYFX_EXPORT bool setQOfInterestStatus(bool newStatus) { _isQOfInt=newStatus; return _isQOfInt; }
137   YACSEVALYFX_EXPORT bool isQOfInterest() const { return _isQOfInt; }
138   //
139   YACSEVALYFX_EXPORT YACS::ENGINE::OutputPort *getUndergroundPtr() const { return _ptr; }
140   //
141 private:
142   YACS::ENGINE::OutputPort * _ptr;
143   bool _isQOfInt;
144 };
145
146 #endif