1 // Copyright (C) 2007-2019 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"
37 MEDFileString(int maxLgth);
40 void set(const char *s);
41 char *getPointer() { return _content; }
42 const char *getReprForWrite() const { return _content; }
43 std::string getRepr() const;
50 class MEDFileMultiString
53 MEDFileMultiString(int nbOfCompo, int maxLgthPerCompo);
54 ~MEDFileMultiString();
55 void set(int compoId, const char *s);
56 const char *getReprForWrite() const;
57 std::vector<std::string> getRepr() const;
58 std::string getReprPerComp(int compId) const;
61 int _max_lgth_per_comp;
69 class DataArrayMedInt : public DataArrayDiscreteSigned< med_int >
71 friend class DataArrayDiscrete<med_int>;
73 template<class INTARRAY>
74 static DataArrayMedInt *Copy( const INTARRAY* array );
75 static DataArrayMedInt *New() { return new DataArrayMedInt(); }
76 DataArrayMedInt *deepCopy() const { return new DataArrayMedInt(*this); }
77 //DataArrayMedInt *buildNewEmptyInstance() const { return new DataArrayMedInt(); }//ko
78 DataArray *buildNewEmptyInstance() const { if ( sizeof(med_int)==sizeof(long)) return DataArrayInt64::New(); return DataArrayInt32::New(); }
80 DataArray *selectByTupleId(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return this->mySelectByTupleId(new2OldBg,new2OldEnd); }
81 DataArray *selectByTupleId(const DataArrayIdType& di) const { return this->mySelectByTupleId(di); }
82 DataArray *selectByTupleIdSafe(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return this->mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
83 DataArray *keepSelectedComponents(const std::vector<std::size_t>& compoIds) const { return this->myKeepSelectedComponents(compoIds); }
84 DataArray *selectByTupleIdSafeSlice(mcIdType bg, mcIdType end2, mcIdType step) const { return this->mySelectByTupleIdSafeSlice(bg,end2,step); }
85 DataArray *selectByTupleRanges(const std::vector<std::pair<mcIdType,mcIdType> >& ranges) const { return this->mySelectByTupleRanges(ranges); }
87 ~DataArrayMedInt() { }
91 template< class T1, class T2 >
92 MCAuto<T1> StaticCast( const MCAuto< T2 >& array )
94 DataArray *src = const_cast< T2* >((const T2*) array );
95 T1* tgt = static_cast<T1*>( src );
101 template< class INTARRAY >
102 MCAuto<DataArrayMedInt> ToMedIntArray(const MCAuto<INTARRAY>& intArray )
104 if ( sizeof( med_int ) == sizeof( typename INTARRAY::Type ))
105 return StaticCast< DataArrayMedInt >( intArray );
106 return DataArrayMedInt::Copy((const INTARRAY*) intArray );
109 template< class INT >
110 MCAuto<DataArrayMedInt> ToMedIntArray(const typename MEDCoupling::Traits<INT>::ArrayType* intArray )
112 if ( sizeof( med_int ) == sizeof( INT ))
114 typedef typename MEDCoupling::Traits<INT>::ArrayType INTARRAY;
115 MCAuto< INTARRAY > ia = const_cast< INTARRAY* >( intArray );
117 return StaticCast< DataArrayMedInt >( ia );
119 return DataArrayMedInt::Copy( intArray );
122 template< class INT >
123 MCAuto< typename MEDCoupling::Traits<INT>::ArrayType> FromMedIntArray(MCAuto<DataArrayMedInt>& medIntArray )
125 typedef typename MEDCoupling::Traits<INT>::ArrayType INTARRAY;
126 if ( sizeof( med_int ) == sizeof( INT ))
127 return StaticCast< INTARRAY >( medIntArray );
129 INTARRAY* intArray = INTARRAY::New();
130 intArray->alloc( medIntArray->getNumberOfTuples(), medIntArray->getNumberOfComponents() );
131 intArray->copyStringInfoFrom( * medIntArray.operator->() );
132 std::copy( medIntArray->begin(), medIntArray->end(), intArray->getPointer() );
136 template< class INT >
137 MCAuto<DataArrayMedInt> ToMedIntArray(const std::vector<INT>& intVec )
139 DataArrayMedInt* medIntArray = DataArrayMedInt::New();
140 if ( sizeof( med_int ) == sizeof( INT ))
142 medIntArray->useArray( reinterpret_cast<const med_int*>(intVec.data()), /*owner=*/false, DeallocType::CPP_DEALLOC, intVec.size(), /*nbComp=*/1 );
146 medIntArray->alloc( intVec.size(), 1 );
147 std::copy( intVec.begin(), intVec.end(), medIntArray->getPointer() );
152 template< class INT >
153 med_int ToMedInt( INT i )
155 return static_cast< med_int >( i );
158 template< class INT >
159 INT FromMedInt( med_int mi )
161 return static_cast< INT >( mi );
164 template<class INTARRAY>
165 DataArrayMedInt * DataArrayMedInt::Copy( const INTARRAY* intArray )
167 DataArrayMedInt* medIntArray = DataArrayMedInt::New();
168 medIntArray->alloc( intArray->getNumberOfTuples(), intArray->getNumberOfComponents() );
169 medIntArray->copyStringInfoFrom( *intArray );
170 std::copy( intArray->begin(), intArray->end(), medIntArray->getPointer() );