]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDLoader/MEDFileParameter.hxx
Salome HOME
Unwarningization under Win.
[tools/medcoupling.git] / src / MEDLoader / MEDFileParameter.hxx
1 // Copyright (C) 2007-2013  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.
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 (CEA/DEN)
20
21 #ifndef __MEDFILEPARAMETER_HXX__
22 #define __MEDFILEPARAMETER_HXX__
23
24 #include "MEDLoaderDefines.hxx"
25 #include "MEDFileUtilities.hxx"
26 #include "MEDCouplingMemArray.hxx"
27 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
28
29 namespace ParaMEDMEM
30 {
31   class MEDFileParameter1TS : public RefCountObject
32   {
33   public:
34     MEDLOADER_EXPORT virtual MEDFileParameter1TS *deepCpy() const throw(INTERP_KERNEL::Exception) = 0;
35     MEDLOADER_EXPORT virtual bool isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const;
36     MEDLOADER_EXPORT virtual void simpleRepr2(int bkOffset, std::ostream& oss) const = 0;
37     MEDLOADER_EXPORT virtual void readValue(med_idt fid, const std::string& name) throw(INTERP_KERNEL::Exception) = 0;
38     MEDLOADER_EXPORT virtual void writeLL(med_idt fid, const std::string& name, const MEDFileWritable& mw) const throw(INTERP_KERNEL::Exception) = 0;
39   public:
40     MEDLOADER_EXPORT void setIteration(int it) { _iteration=it; }
41     MEDLOADER_EXPORT int getIteration() const { return _iteration; }
42     MEDLOADER_EXPORT void setOrder(int order) { _order=order; }
43     MEDLOADER_EXPORT int getOrder() const { return _order; }
44     MEDLOADER_EXPORT void setTimeValue(double time) { _time=time; }
45     MEDLOADER_EXPORT void setTime(int dt, int it, double time) { _time=time; _iteration=dt; _order=it; }
46     MEDLOADER_EXPORT double getTime(int& dt, int& it) { dt=_iteration; it=_order; return _time; }
47     MEDLOADER_EXPORT double getTimeValue() const { return _time; }
48   protected:
49     MEDFileParameter1TS(int iteration, int order, double time);
50     MEDFileParameter1TS();
51   protected:
52     int _iteration;
53     int _order;
54     double _time;    
55   };
56   
57   class MEDFileParameterDouble1TSWTI : public MEDFileParameter1TS
58   {
59   public:
60     MEDLOADER_EXPORT static MEDFileParameterDouble1TSWTI *New(int iteration, int order, double time);
61     MEDLOADER_EXPORT MEDFileParameter1TS *deepCpy() const throw(INTERP_KERNEL::Exception);
62     MEDLOADER_EXPORT void setValue(double val) throw(INTERP_KERNEL::Exception) { _arr=val; }
63     MEDLOADER_EXPORT double getValue() const throw(INTERP_KERNEL::Exception) { return _arr; }
64     MEDLOADER_EXPORT bool isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const;
65     MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
66     MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildren() const;
67     MEDLOADER_EXPORT void readValue(med_idt fid, const std::string& name) throw(INTERP_KERNEL::Exception);
68     MEDLOADER_EXPORT std::string simpleRepr() const;
69   protected:
70     MEDFileParameterDouble1TSWTI();
71     MEDFileParameterDouble1TSWTI(int iteration, int order, double time);
72     void simpleRepr2(int bkOffset, std::ostream& oss) const;
73     void finishLoading(med_idt fid, const std::string& name, int dt, int it, int nbOfSteps) throw(INTERP_KERNEL::Exception);
74     void finishLoading(med_idt fid, const std::string& name, int timeStepId) throw(INTERP_KERNEL::Exception);
75     void writeLL(med_idt fid, const std::string& name, const MEDFileWritable& mw) const throw(INTERP_KERNEL::Exception);
76   protected:
77     double _arr;
78   };
79
80   class MEDFileParameterTinyInfo : public MEDFileWritable
81   {
82   public:
83     MEDLOADER_EXPORT void setDescription(const char *name) { _desc_name=name; }
84     MEDLOADER_EXPORT std::string getDescription() const { return _desc_name; }
85     MEDLOADER_EXPORT void setTimeUnit(const char *unit) { _dt_unit=unit; }
86     MEDLOADER_EXPORT std::string getTimeUnit() const { return _dt_unit; }
87     MEDLOADER_EXPORT std::size_t getHeapMemSizeOfStrings() const;
88     MEDLOADER_EXPORT bool isEqualStrings(const MEDFileParameterTinyInfo& other, std::string& what) const;
89   protected:
90     void writeLLHeader(med_idt fid, med_parameter_type typ) const throw(INTERP_KERNEL::Exception);
91     void mainRepr(int bkOffset, std::ostream& oss) const;
92   protected:
93     std::string _dt_unit;
94     std::string _name;
95     std::string _desc_name;
96   };
97
98   class MEDFileParameterDouble1TS : public MEDFileParameterDouble1TSWTI, public MEDFileParameterTinyInfo
99   {
100   public:
101     MEDLOADER_EXPORT static MEDFileParameterDouble1TS *New();
102     MEDLOADER_EXPORT static MEDFileParameterDouble1TS *New(const char *fileName) throw(INTERP_KERNEL::Exception);
103     MEDLOADER_EXPORT static MEDFileParameterDouble1TS *New(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception);
104     MEDLOADER_EXPORT static MEDFileParameterDouble1TS *New(const char *fileName, const char *paramName, int dt, int it) throw(INTERP_KERNEL::Exception);
105     MEDLOADER_EXPORT virtual MEDFileParameter1TS *deepCpy() const throw(INTERP_KERNEL::Exception);
106     MEDLOADER_EXPORT virtual bool isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const;
107     MEDLOADER_EXPORT virtual std::string simpleRepr() const;
108     MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
109     MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildren() const;
110     MEDLOADER_EXPORT void setName(const char *name) throw(INTERP_KERNEL::Exception) { _name=name; }
111     MEDLOADER_EXPORT std::string getName() const throw(INTERP_KERNEL::Exception) { return _name; }
112     MEDLOADER_EXPORT void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
113   private:
114     MEDFileParameterDouble1TS();
115     MEDFileParameterDouble1TS(const char *fileName) throw(INTERP_KERNEL::Exception);
116     MEDFileParameterDouble1TS(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception);
117     MEDFileParameterDouble1TS(const char *fileName, const char *paramName, int dt, int it) throw(INTERP_KERNEL::Exception);
118   };
119
120   class MEDFileParameterMultiTS : public RefCountObject, public MEDFileParameterTinyInfo
121   {
122   public:
123     MEDLOADER_EXPORT static MEDFileParameterMultiTS *New();
124     MEDLOADER_EXPORT static MEDFileParameterMultiTS *New(const char *fileName) throw(INTERP_KERNEL::Exception);
125     MEDLOADER_EXPORT static MEDFileParameterMultiTS *New(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception);
126     MEDLOADER_EXPORT std::string getName() const { return _name; }
127     MEDLOADER_EXPORT void setName(const char *name) { _name=name; }
128     MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
129     MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildren() const;
130     MEDLOADER_EXPORT MEDFileParameterMultiTS *deepCpy() const throw(INTERP_KERNEL::Exception);
131     MEDLOADER_EXPORT bool isEqual(const MEDFileParameterMultiTS *other, double eps, std::string& what) const;
132     MEDLOADER_EXPORT void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
133     MEDLOADER_EXPORT void writeLL(med_idt fid, const MEDFileWritable& mw) const throw(INTERP_KERNEL::Exception);
134     MEDLOADER_EXPORT std::string simpleRepr() const;
135     MEDLOADER_EXPORT void appendValue(int dt, int it, double time, double val) throw(INTERP_KERNEL::Exception);
136     MEDLOADER_EXPORT double getDoubleValue(int iteration, int order) const throw(INTERP_KERNEL::Exception);
137     MEDLOADER_EXPORT int getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception);
138     MEDLOADER_EXPORT int getPosGivenTime(double time, double eps=1e-8) const throw(INTERP_KERNEL::Exception);
139     MEDLOADER_EXPORT MEDFileParameter1TS *getTimeStepAtPos(int posId) const throw(INTERP_KERNEL::Exception);
140     MEDLOADER_EXPORT void eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception);
141     MEDLOADER_EXPORT std::vector< std::pair<int,int> > getIterations() const throw(INTERP_KERNEL::Exception);
142     MEDLOADER_EXPORT std::vector< std::pair<int,int> > getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception);
143     MEDLOADER_EXPORT void simpleRepr2(int bkOffset, std::ostream& oss) const;
144   protected:
145     MEDFileParameterMultiTS();
146     MEDFileParameterMultiTS(const MEDFileParameterMultiTS& other, bool deepCopy);
147     MEDFileParameterMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception);
148     MEDFileParameterMultiTS(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception);
149     void finishLoading(med_idt fid, med_parameter_type typ, int nbOfSteps) throw(INTERP_KERNEL::Exception);
150   protected:
151     std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> > _param_per_ts;
152   };
153
154   class MEDFileParameters : public RefCountObject, public MEDFileWritable
155   {
156   public:
157     MEDLOADER_EXPORT static MEDFileParameters *New();
158     MEDLOADER_EXPORT static MEDFileParameters *New(const char *fileName) throw(INTERP_KERNEL::Exception);
159     MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
160     MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildren() const;
161     MEDLOADER_EXPORT MEDFileParameters *deepCpy() const throw(INTERP_KERNEL::Exception);
162     MEDLOADER_EXPORT bool isEqual(const MEDFileParameters *other, double eps, std::string& what) const;
163     MEDLOADER_EXPORT void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
164     MEDLOADER_EXPORT void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception);
165     MEDLOADER_EXPORT std::vector<std::string> getParamsNames() const throw(INTERP_KERNEL::Exception);
166     MEDLOADER_EXPORT std::string simpleRepr() const;
167     MEDLOADER_EXPORT void simpleReprWithoutHeader(std::ostream& oss) const;
168     MEDLOADER_EXPORT void resize(int newSize) throw(INTERP_KERNEL::Exception);
169     MEDLOADER_EXPORT void pushParam(MEDFileParameterMultiTS *param) throw(INTERP_KERNEL::Exception);
170     MEDLOADER_EXPORT void setParamAtPos(int i, MEDFileParameterMultiTS *param) throw(INTERP_KERNEL::Exception);
171     MEDLOADER_EXPORT MEDFileParameterMultiTS *getParamAtPos(int i) const throw(INTERP_KERNEL::Exception);
172     MEDLOADER_EXPORT MEDFileParameterMultiTS *getParamWithName(const char *paramName) const throw(INTERP_KERNEL::Exception);
173     MEDLOADER_EXPORT void destroyParamAtPos(int i) throw(INTERP_KERNEL::Exception);
174     MEDLOADER_EXPORT int getPosFromParamName(const char *paramName) const throw(INTERP_KERNEL::Exception);
175     MEDLOADER_EXPORT int getNumberOfParams() const throw(INTERP_KERNEL::Exception);
176   protected:
177     void simpleRepr2(int bkOffset, std::ostream& oss) const;
178     MEDFileParameters(const char *fileName) throw(INTERP_KERNEL::Exception);
179     MEDFileParameters(const MEDFileParameters& other, bool deepCopy);
180     MEDFileParameters();
181   protected:
182     std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> > _params;
183   };
184 }
185
186 #endif