Salome HOME
0c52ad113c48214e5dcf995eb821ea1a0c25c333
[modules/yacs.git] / src / evalyfx / YACSEvalSeqAny.hxx
1 // Copyright (C) 2012-2021  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 __YACSEVALSEQANY_HXX__
22 #define __YACSEVALSEQANY_HXX__
23
24 #include "YACSEvalYFXExport.hxx"
25 #include "RefCounter.hxx"
26 #include "Exception.hxx"
27
28 #include <vector>
29 #include <string>
30
31 namespace YACS
32 {
33   namespace ENGINE
34   {
35     class InputPyPort;
36   }
37 }
38
39 class YACSEvalSeqAny
40 {
41 public:
42   YACSEVALYFX_EXPORT static YACSEvalSeqAny *BuildEmptyFromType(const std::string& dataType);
43   YACSEVALYFX_EXPORT virtual std::size_t size() const = 0;
44   YACSEVALYFX_EXPORT virtual std::string getTypeOfConstitutingElements() const = 0;
45   YACSEVALYFX_EXPORT virtual YACSEvalSeqAny *copy() const = 0;
46   YACSEVALYFX_EXPORT virtual void initialize(YACS::ENGINE::InputPyPort *p) const = 0;
47   YACSEVALYFX_EXPORT virtual ~YACSEvalSeqAny() { }
48 };
49
50 template<class T>
51 class YACSEvalSeqAnyInternal : public YACS::ENGINE::RefCounter
52 {
53 public:
54   static YACSEvalSeqAnyInternal<T> *New(std::vector<T> *arr) { return new YACSEvalSeqAnyInternal(arr); }
55   std::size_t size() const;
56   T operator[](const std::size_t i) const { if(_arr) return (*_arr)[i]; else throw YACS::Exception("YACSEvalSeqAnyInternal[] : internal pointer is null !"); }
57   std::vector<T> *getInternal() const { return _arr; }
58 private:
59   ~YACSEvalSeqAnyInternal() { delete _arr; }
60   YACSEvalSeqAnyInternal(std::vector<T> *arr):_arr(arr) { }
61 private:
62   std::vector<T> *_arr;
63 };
64
65 class YACSEvalSeqAnyDouble : public YACSEvalSeqAny
66 {
67 public:
68   YACSEVALYFX_EXPORT std::size_t size() const { return _arr->size(); }
69   YACSEVALYFX_EXPORT ~YACSEvalSeqAnyDouble() { if(_arr) _arr->decrRef(); }
70   YACSEVALYFX_EXPORT YACSEvalSeqAnyDouble(const std::vector<double>& arr);
71   YACSEVALYFX_EXPORT YACSEvalSeqAnyDouble(const YACSEvalSeqAnyDouble& other);
72   YACSEVALYFX_EXPORT YACSEvalSeqAnyDouble();
73   YACSEVALYFX_EXPORT std::string getTypeOfConstitutingElements() const;
74   YACSEVALYFX_EXPORT YACSEvalSeqAnyDouble *copy() const;
75   YACSEVALYFX_EXPORT void initialize(YACS::ENGINE::InputPyPort *p) const;
76   YACSEVALYFX_EXPORT std::vector<double> *getInternal() const;
77 private:
78   YACSEvalSeqAnyInternal<double> *_arr;
79 };
80
81 class YACSEvalSeqAnyInt : public YACSEvalSeqAny
82 {
83 public:
84   YACSEVALYFX_EXPORT std::size_t size() const { return _arr->size(); }
85   YACSEVALYFX_EXPORT ~YACSEvalSeqAnyInt() { if(_arr) _arr->decrRef(); }
86   YACSEVALYFX_EXPORT YACSEvalSeqAnyInt(const std::vector<int>& arr);
87   YACSEVALYFX_EXPORT YACSEvalSeqAnyInt(const YACSEvalSeqAnyInt& other);
88   YACSEVALYFX_EXPORT YACSEvalSeqAnyInt();
89   YACSEVALYFX_EXPORT std::string getTypeOfConstitutingElements() const;
90   YACSEVALYFX_EXPORT YACSEvalSeqAnyInt *copy() const;
91   YACSEVALYFX_EXPORT void initialize(YACS::ENGINE::InputPyPort *p) const;
92   YACSEVALYFX_EXPORT std::vector<int> *getInternal() const;
93 private:
94   YACSEvalSeqAnyInternal<int> *_arr;
95 };
96
97 template<class T>
98 std::size_t YACSEvalSeqAnyInternal<T>::size() const
99 {
100   if(!_arr)
101     throw YACS::Exception("YACSEvalSeqAnyDouble<T>::size : empty array !");
102   return _arr->size();
103 }
104
105 #endif