Salome HOME
First implementation of evalyfx.
[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 protected:
88   YACSEVALYFX_EXPORT static std::string GetTypeOfData(const YACS::ENGINE::DataPort *port);
89 };
90
91 class YACSEvalInputPort : public YACSEvalPort
92 {
93 public:
94   YACSEVALYFX_EXPORT YACSEvalInputPort(YACS::ENGINE::InputPort *ptr);
95   YACSEVALYFX_EXPORT std::string getName() const;
96   YACSEVALYFX_EXPORT std::string getTypeOfData() const;
97   YACSEVALYFX_EXPORT bool isOKForLock() const;
98   //
99   YACSEVALYFX_EXPORT bool hasDefaultValueDefined() const;
100   YACSEVALYFX_EXPORT YACSEvalAny *getDefaultValueDefined() const;
101   YACSEVALYFX_EXPORT void setDefaultValue(const YACSEvalAny *parameter);
102   YACSEVALYFX_EXPORT void setSequenceOfValuesToEval(const YACSEvalSeqAny* vals);
103   YACSEVALYFX_EXPORT bool hasSequenceOfValuesToEval(std::size_t& sz) const;
104   //
105   YACSEVALYFX_EXPORT YACS::ENGINE::InputPort *getUndergroundPtr() const { return _ptr; }
106   YACSEVALYFX_EXPORT void initializeUndergroundWithSeq(YACS::ENGINE::InputPyPort *p) const;
107   //
108   YACSEVALYFX_EXPORT virtual ~YACSEvalInputPort();
109   void lock() const { _isLocked=true; }
110   void unlock() const { _isLocked=false; }
111 private:
112   YACSEvalAny *convertFromInternalAnyToExternal(YACS::ENGINE::Any *data) const;
113   void checkForNonConstMethod() const;
114 private:
115   YACS::ENGINE::InputPort * _ptr;
116   YACSEvalSeqAny *_mySeq;
117   mutable bool _isLocked;
118 };
119
120 class YACSEvalOutputPort : public YACSEvalPort
121 {
122 public:
123   YACSEVALYFX_EXPORT YACSEvalOutputPort(YACS::ENGINE::OutputPort *ptr);
124   YACSEVALYFX_EXPORT std::string getName() const;
125   YACSEVALYFX_EXPORT std::string getTypeOfData() const;
126   //
127   YACSEVALYFX_EXPORT YACS::ENGINE::OutputPort *getUndergroundPtr() const { return _ptr; }
128   //
129 private:
130   YACS::ENGINE::OutputPort * _ptr;
131 };
132
133 #endif