Salome HOME
Step 8 : meshes have been managed, fields still remaining.
[tools/medcoupling.git] / src / MEDLoader / MEDFileUtilities.hxx
1 // Copyright (C) 2007-2016  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     void copyOptionsFrom(const MEDFileWritable& other) const;
57     int getTooLongStrPolicy() const;
58     void setTooLongStrPolicy(int newVal);
59     int getZipConnPolicy();
60     void setZipConnPolicy(int newVal);
61     static std::string FileNameFromFID(med_idt fid);
62   protected://policies on write
63     mutable int _too_long_str;
64     mutable int _zipconn_pol;
65   };
66
67   class MEDFileWritableStandAlone : public MEDFileWritable
68   {
69   public:
70     MEDLOADER_EXPORT virtual void writeLL(med_idt fid) const = 0;
71     MEDLOADER_EXPORT virtual void write(const std::string& fileName, int mode) const;
72     MEDLOADER_EXPORT virtual void write30(const std::string& fileName, int mode) const;
73     MEDLOADER_EXPORT MCAuto<DataArrayByte> serialize() const;
74     MEDLOADER_EXPORT static std::string GenerateUniqueDftFileNameInMem();
75   public:
76     MEDLOADER_EXPORT static const char DFT_FILENAME_IN_MEM[];
77     template<class T>
78     static T *BuildFromMemoryChunk(DataArrayByte *db);
79   };
80   
81   MEDFileUtilities::AutoFid OpenMEDFileForRead(const std::string& fileName);
82 }
83
84 #endif