1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #ifndef __MEDFILEBASIS_HXX__
22 #define __MEDFILEBASIS_HXX__
24 #include "InterpKernelException.hxx"
25 #include "MEDCouplingMemArray.hxx"
26 #include "MEDCouplingMemArray.txx"
38 MEDFileString(int maxLgth);
41 void set(const char *s);
42 char *getPointer() { return _content; }
43 const char *getReprForWrite() const { return _content; }
44 std::string getRepr() const;
51 class MEDFileMultiString
54 MEDFileMultiString(int nbOfCompo, int maxLgthPerCompo);
55 ~MEDFileMultiString();
56 void set(int compoId, const char *s);
57 const char *getReprForWrite() const;
58 std::vector<std::string> getRepr() const;
59 std::string getReprPerComp(int compId) const;
62 int _max_lgth_per_comp;
70 class DataArrayMedInt : public DataArrayDiscreteSigned< med_int >
72 friend class DataArrayDiscrete<med_int>;
74 template<class INTARRAY>
75 static DataArrayMedInt *Copy( const INTARRAY* array );
76 static DataArrayMedInt *New() { return new DataArrayMedInt(); }
77 std::string getClassName() const override { return std::string("DataArrayMedInt"); }
78 DataArrayMedInt *deepCopy() const { return new DataArrayMedInt(*this); }
79 //DataArrayMedInt *buildNewEmptyInstance() const { return new DataArrayMedInt(); }//ko
80 DataArray *buildNewEmptyInstance() const { if ( sizeof(med_int)==sizeof(int)) return DataArrayInt32::New(); return DataArrayInt64::New(); }
82 DataArrayMedInt *copySorted(bool asc=true) const override { MCAuto<DataArrayMedInt> ret(this->deepCopy()); ret->sort(); return ret.retn(); }
83 DataArray *selectByTupleId(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return this->mySelectByTupleId(new2OldBg,new2OldEnd); }
84 DataArray *selectByTupleId(const DataArrayIdType& di) const { return this->mySelectByTupleId(di); }
85 DataArray *selectByTupleIdSafe(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return this->mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
86 DataArray *keepSelectedComponents(const std::vector<std::size_t>& compoIds) const { return this->myKeepSelectedComponents(compoIds); }
87 DataArray *selectByTupleIdSafeSlice(mcIdType bg, mcIdType end2, mcIdType step) const { return this->mySelectByTupleIdSafeSlice(bg,end2,step); }
88 DataArray *selectByTupleRanges(const std::vector<std::pair<mcIdType,mcIdType> >& ranges) const { return this->mySelectByTupleRanges(ranges); }
90 ~DataArrayMedInt() { }
94 template< class T1, class T2 >
95 MCAuto<T1> StaticCast( const MCAuto< T2 >& array )
97 DataArray *src = const_cast< T2* >((const T2*) array );
98 T1* tgt = static_cast<T1*>( src );
104 template< class INTARRAY >
105 MCAuto<DataArrayMedInt> ToMedIntArray(const MCAuto<INTARRAY>& intArray )
107 if ( sizeof( med_int ) == sizeof( typename INTARRAY::Type ))
108 return StaticCast< DataArrayMedInt >( intArray );
109 return DataArrayMedInt::Copy((const INTARRAY*) intArray );
112 template< class INT >
113 MCAuto<DataArrayMedInt> ToMedIntArray(const typename MEDCoupling::Traits<INT>::ArrayType* intArray )
115 if ( sizeof( med_int ) == sizeof( INT ))
117 typedef typename MEDCoupling::Traits<INT>::ArrayType INTARRAY;
118 MCAuto< INTARRAY > ia = const_cast< INTARRAY* >( intArray );
120 return StaticCast< DataArrayMedInt >( ia );
122 return DataArrayMedInt::Copy( intArray );
125 template< class INT >
126 MCAuto< typename MEDCoupling::Traits<INT>::ArrayType> FromMedIntArray(MCAuto<DataArrayMedInt>& medIntArray )
128 typedef typename MEDCoupling::Traits<INT>::ArrayType INTARRAY;
129 if ( sizeof( med_int ) == sizeof( INT ))
130 return StaticCast< INTARRAY >( medIntArray );
132 INTARRAY* intArray = INTARRAY::New();
133 intArray->alloc( medIntArray->getNumberOfTuples(), medIntArray->getNumberOfComponents() );
134 intArray->copyStringInfoFrom( * medIntArray.operator->() );
135 std::copy( medIntArray->begin(), medIntArray->end(), intArray->getPointer() );
139 template< class INT >
140 MCAuto<DataArrayMedInt> ToMedIntArray(const std::vector<INT>& intVec )
142 DataArrayMedInt* medIntArray = DataArrayMedInt::New();
143 if ( sizeof( med_int ) == sizeof( INT ))
145 medIntArray->useArray( reinterpret_cast<const med_int*>(intVec.data()), /*owner=*/false, DeallocType::CPP_DEALLOC, intVec.size(), /*nbComp=*/1 );
149 medIntArray->alloc( intVec.size(), 1 );
150 std::copy( intVec.begin(), intVec.end(), medIntArray->getPointer() );
155 template< class INT >
156 med_int ToMedInt( INT i )
158 return static_cast< med_int >( i );
161 template< class INT >
162 INT FromMedInt( med_int mi )
164 return static_cast< INT >( mi );
167 template<class INTARRAY>
168 DataArrayMedInt * DataArrayMedInt::Copy( const INTARRAY* intArray )
170 DataArrayMedInt* medIntArray = DataArrayMedInt::New();
171 medIntArray->alloc( intArray->getNumberOfTuples(), intArray->getNumberOfComponents() );
172 medIntArray->copyStringInfoFrom( *intArray );
173 std::copy( intArray->begin(), intArray->end(), medIntArray->getPointer() );