Salome HOME
Merge branch 'master' of https://codev-tuleap.cea.fr/plugins/git/salome/medcoupling
[tools/medcoupling.git] / src / MEDLoader / MEDFileUtilities.hxx
1 // Copyright (C) 2007-2020  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 (CEA/DEN)
20
21 #ifndef __MEDFILEUTILITIES_HXX__
22 #define __MEDFILEUTILITIES_HXX__
23
24 #include "InterpKernelException.hxx"
25 #include "MEDLoaderDefines.hxx"
26
27 #include "MCAuto.hxx"
28 #include "MEDCouplingMemArray.hxx"
29
30 #include "med.h"
31
32 namespace MEDFileUtilities
33 {
34   med_access_mode TraduceWriteMode(int medloaderwritemode);
35   const char *GetReadableMEDFieldType(med_field_type ft);
36   void CheckMEDCode(int code, med_idt fid, const std::string& msg);
37   void CheckFileForRead(const std::string& fileName);
38
39   class AutoFid
40   {
41   public:
42     AutoFid(med_idt fid);
43     operator med_idt() const { return _fid; }
44     ~AutoFid();
45   private:
46     med_idt _fid;
47   };
48 }
49
50 namespace MEDCoupling
51 {
52   class MEDLOADER_EXPORT MEDFileWritable
53   {
54   public:
55     MEDFileWritable();
56     virtual ~MEDFileWritable() {}
57     void copyOptionsFrom(const MEDFileWritable& other) const;
58     int getTooLongStrPolicy() const;
59     void setTooLongStrPolicy(int newVal);
60     int getZipConnPolicy();
61     void setZipConnPolicy(int newVal);
62     static std::string FileNameFromFID(med_idt fid);
63   protected://policies on write
64     mutable int _too_long_str;
65     mutable int _zipconn_pol;
66   };
67
68   class MEDFileWritableStandAlone : public MEDFileWritable
69   {
70   public:
71     MEDLOADER_EXPORT virtual void writeLL(med_idt fid) const = 0;
72     MEDLOADER_EXPORT virtual void write(const std::string& fileName, int mode) const;
73     MEDLOADER_EXPORT virtual void write33(const std::string& fileName, int mode) const;
74     MEDLOADER_EXPORT virtual void write30(const std::string& fileName, int mode) const;
75     MEDLOADER_EXPORT MCAuto<DataArrayByte> serialize() const;
76     MEDLOADER_EXPORT static std::string GenerateUniqueDftFileNameInMem();
77   public:
78     MEDLOADER_EXPORT static const char DFT_FILENAME_IN_MEM[];
79     template<class T>
80     static T *BuildFromMemoryChunk(DataArrayByte *db);
81   private:
82     void writeXX(const std::string& fileName, int mode, med_int maj, med_int min, med_int rel) const;
83   };
84   
85   class MEDFileCapability
86   {
87   public:
88     MEDFileCapability(med_idt fid);
89     bool isFastReader() const { return _maj>=4 && _min >=1; }
90   private:
91     med_int _maj;
92     med_int _min;
93     med_int _rel;
94   };
95   MEDFileUtilities::AutoFid OpenMEDFileForRead(const std::string& fileName);
96 }
97
98 #endif