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