Salome HOME
GlobalNodeIds in MEDReader in // context.
[tools/medcoupling.git] / src / MEDLoader / MEDFileEquivalence.hxx
1 // Copyright (C) 2007-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 __MEDFILEEQUIVALENCE_HXX__
22 #define __MEDFILEEQUIVALENCE_HXX__
23
24 #include "MEDLoaderDefines.hxx"
25 #include "MEDCouplingRefCountObject.hxx"
26 #include "MEDCouplingMemArray.hxx"
27 #include "MEDFileUtilities.hxx"
28 #include "MCAuto.hxx"
29
30 #include <vector>
31
32 namespace MEDCoupling
33 {
34   class MEDFileEquivalenceCell;
35   class MEDFileEquivalenceNode;
36   class MEDFileEquivalences;
37   class MEDFileMesh;
38
39   class MEDFileEquivalencePair : public RefCountObject
40   {
41   public:
42     static MEDFileEquivalencePair *Load(MEDFileEquivalences *father, med_idt fid, const std::string& name, const std::string &desc);
43     void write(med_idt fid) const;
44     const MEDFileEquivalences *getFather() const { return _father; }
45     MEDFileEquivalences *getFather() { return _father; }
46     const MEDFileMesh *getMesh() const;
47     MEDFileMesh *getMesh();
48     MEDFileEquivalencePair *deepCopy(MEDFileEquivalences *father) const;
49     bool isEqual(const MEDFileEquivalencePair *other, std::string& what) const;
50     void getRepr(std::ostream& oss) const;
51     static MEDFileEquivalencePair *New(MEDFileEquivalences *father, const std::string& name);
52     MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
53     MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
54   public:
55     MEDLOADER_EXPORT std::string getName() const { return _name; }
56     MEDLOADER_EXPORT void setName(const std::string& name) { _name=name; }
57     MEDLOADER_EXPORT std::string getDescription() const { return _description; }
58     MEDLOADER_EXPORT void setDescription(const std::string& descr) { _description=descr; }
59     MEDLOADER_EXPORT MEDFileEquivalenceCell *initCell();
60     MEDLOADER_EXPORT MEDFileEquivalenceNode *initNode();
61     MEDLOADER_EXPORT MEDFileEquivalenceCell *getCell() { return _cell; }
62     MEDLOADER_EXPORT MEDFileEquivalenceNode *getNode() { return _node; }
63     MEDLOADER_EXPORT void setArray(int meshDimRelToMaxExt, DataArrayInt *da);
64   private:
65     MEDFileEquivalencePair(MEDFileEquivalences *father, const std::string& name, const std::string& desc):_father(father),_name(name),_description(desc) { }
66     void load(med_idt fid);
67   private:
68     MEDFileEquivalences *_father;
69     std::string _name;
70     std::string _description;
71     MCAuto<MEDFileEquivalenceCell> _cell;
72     MCAuto<MEDFileEquivalenceNode> _node;
73   };
74
75   class MEDFileEquivalences : public RefCountObject
76   {
77   public:
78     MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
79     MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
80     MEDLOADER_EXPORT const MEDFileMesh *getMesh() const { return _owner; }
81     MEDLOADER_EXPORT MEDFileMesh *getMesh() { return _owner; }
82     void getDtIt(int &dt, int &it) const;
83     std::string getMeshName() const;
84     void pushEquivalence(MEDFileEquivalencePair *elt);
85     static MEDFileEquivalences *New(MEDFileMesh *owner) { return new MEDFileEquivalences(owner); }
86     MEDFileEquivalences *deepCopy(MEDFileMesh *owner) const;
87     bool isEqual(const MEDFileEquivalences *other, std::string& what) const;
88     void getRepr(std::ostream& oss) const;
89   public:
90     MEDLOADER_EXPORT MEDFileEquivalencePair *getEquivalence(int i);
91     MEDLOADER_EXPORT MEDFileEquivalencePair *getEquivalenceWithName(const std::string& name);
92     MEDLOADER_EXPORT int size() const;
93     MEDLOADER_EXPORT std::vector<std::string> getEquivalenceNames() const;
94     MEDLOADER_EXPORT MEDFileEquivalencePair *appendEmptyEquivalenceWithName(const std::string& name);
95     MEDLOADER_EXPORT void killEquivalenceWithName(const std::string& name);
96     MEDLOADER_EXPORT void killEquivalenceAt(int i);
97     MEDLOADER_EXPORT void clear();
98   public:
99     void write(med_idt fid) const;
100     static int PresenceOfEquivalences(med_idt fid, const std::string& meshName);
101     static MEDFileEquivalences *Load(med_idt fid, int nbOfEq, MEDFileMesh *owner);
102     static void CheckDataArray(const DataArrayInt *data);
103   private:
104     MEDFileEquivalences(MEDFileMesh *owner):_owner(owner) { }
105     void deepCpyFrom(const MEDFileEquivalences& other);
106   private:
107     MEDFileMesh *_owner;
108     std::vector< MCAuto<MEDFileEquivalencePair> > _equ;
109   };
110
111   class MEDFileEquivalenceBase : public RefCountObject
112   {
113   protected:
114     MEDFileEquivalenceBase(MEDFileEquivalencePair *father);
115     const MEDFileEquivalencePair *getFather() const { return _father; }
116     MEDFileEquivalencePair *getFather() { return _father; }
117     const MEDFileMesh *getMesh() const { return getFather()->getMesh(); }
118     MEDFileMesh *getMesh() { return getFather()->getMesh(); }
119   protected:
120     ~MEDFileEquivalenceBase() { }
121   private:
122     MEDFileEquivalencePair *_father;
123   };
124
125   class MEDFileEquivalenceData : public MEDFileEquivalenceBase
126   {
127   public:
128     MEDFileEquivalenceData(MEDFileEquivalencePair *owner, DataArrayInt *data);
129     MEDLOADER_EXPORT void setArray(DataArrayInt *data);
130     MEDLOADER_EXPORT const DataArrayInt *getArray() const { return _data; }
131     MEDLOADER_EXPORT DataArrayInt *getArray() { return _data; }
132     MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
133     bool isEqual(const MEDFileEquivalenceData *other, std::string& what) const;
134   protected:
135     void writeLL(med_idt fid, med_entity_type medtype, med_geometry_type medgt) const;
136   protected:
137     ~MEDFileEquivalenceData() { }
138   protected:
139     MCAuto<DataArrayInt> _data;
140   };
141
142   class MEDFileEquivalenceCellType : public MEDFileEquivalenceData
143   {
144   public:
145     MEDFileEquivalenceCellType(MEDFileEquivalencePair *owner, INTERP_KERNEL::NormalizedCellType type, DataArrayInt *data):MEDFileEquivalenceData(owner,data),_type(type) { }
146     MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
147     INTERP_KERNEL::NormalizedCellType getType() const { return _type; }
148     MEDFileEquivalenceCellType *deepCopy(MEDFileEquivalencePair *owner) const;
149     bool isEqual(const MEDFileEquivalenceCellType *other, std::string& what) const;
150     void getRepr(std::ostream& oss) const;
151   public:
152     void write(med_idt fid) const;
153   private:
154     ~MEDFileEquivalenceCellType() { }
155   private:
156     INTERP_KERNEL::NormalizedCellType _type;
157   };
158
159   class MEDFileEquivalenceCell : public MEDFileEquivalenceBase
160   {
161   public:
162     MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
163     MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
164     static MEDFileEquivalenceCell *Load(med_idt fid, MEDFileEquivalencePair *owner);
165     void write(med_idt fid) const;
166     MEDFileEquivalenceCell *deepCopy(MEDFileEquivalencePair *owner) const;
167     bool isEqual(const MEDFileEquivalenceCell *other, std::string& what) const;
168     void getRepr(std::ostream& oss) const;
169   public:
170     MEDLOADER_EXPORT void clear() { _types.clear(); }
171     MEDLOADER_EXPORT std::size_t size() const { return _types.size(); }
172     MEDLOADER_EXPORT DataArrayInt *getArray(INTERP_KERNEL::NormalizedCellType type);
173     MEDLOADER_EXPORT void setArray(int meshDimRelToMax, DataArrayInt *da);
174     MEDLOADER_EXPORT void setArrayForType(INTERP_KERNEL::NormalizedCellType type, DataArrayInt *da);
175     MEDLOADER_EXPORT std::vector<INTERP_KERNEL::NormalizedCellType> getTypes() const;
176   public:
177     MEDFileEquivalenceCell(MEDFileEquivalencePair *owner):MEDFileEquivalenceBase(owner) { }
178   private:
179     ~MEDFileEquivalenceCell() { }
180   private:
181     void load(med_idt fid);
182     std::string getName() const { return getFather()->getName(); }
183   private:
184     std::vector< MCAuto<MEDFileEquivalenceCellType> > _types;
185   };
186
187   class MEDFileEquivalenceNode : public MEDFileEquivalenceData
188   {
189   public:
190     MEDFileEquivalenceNode(MEDFileEquivalencePair *owner, DataArrayInt *data):MEDFileEquivalenceData(owner,data) { }
191     MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
192     void write(med_idt fid) const;
193     MEDFileEquivalenceNode *deepCopy(MEDFileEquivalencePair *owner) const;
194     bool isEqual(const MEDFileEquivalenceNode *other, std::string& what) const;
195     void getRepr(std::ostream& oss) const;
196   private:
197     ~MEDFileEquivalenceNode() { }
198   };
199 }
200
201 #endif
202