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;
69 #ifdef MED_INT_IS_LONG
70 using DataArrayMedInt = DataArrayInt64;
72 using DataArrayMedInt = DataArrayInt32;
75 template<class INTARRAY>
76 DataArrayMedInt * DataArrayMedInt_Copy( const INTARRAY* intArray )
78 DataArrayMedInt* medIntArray = DataArrayMedInt::New();
79 medIntArray->alloc( intArray->getNumberOfTuples(), intArray->getNumberOfComponents() );
80 medIntArray->copyStringInfoFrom( *intArray );
81 std::copy( intArray->begin(), intArray->end(), medIntArray->getPointer() );
85 template< class T1, class T2 >
86 MCAuto<T1> StaticCast( const MCAuto< T2 >& array )
88 DataArray *src = const_cast< T2* >((const T2*) array );
89 T1* tgt = static_cast<T1*>( src );
95 template< class INTARRAY >
96 MCAuto<DataArrayMedInt> ToMedIntArray(const MCAuto<INTARRAY>& intArray )
98 if ( sizeof( med_int ) == sizeof( typename INTARRAY::Type ))
99 return StaticCast< DataArrayMedInt >( intArray );
100 return DataArrayMedInt_Copy((const INTARRAY*) intArray );
103 template< class INT >
104 MCAuto<DataArrayMedInt> ToMedIntArray(const typename MEDCoupling::Traits<INT>::ArrayType* intArray )
106 if ( sizeof( med_int ) == sizeof( INT ))
108 typedef typename MEDCoupling::Traits<INT>::ArrayType INTARRAY;
109 MCAuto< INTARRAY > ia = const_cast< INTARRAY* >( intArray );
111 return StaticCast< DataArrayMedInt >( ia );
113 return DataArrayMedInt_Copy( intArray );
116 template< class INT >
117 MCAuto< typename MEDCoupling::Traits<INT>::ArrayType> FromMedIntArray(MCAuto<DataArrayMedInt>& medIntArray )
119 typedef typename MEDCoupling::Traits<INT>::ArrayType INTARRAY;
120 if ( sizeof( med_int ) == sizeof( INT ))
121 return StaticCast< INTARRAY >( medIntArray );
123 INTARRAY* intArray = INTARRAY::New();
124 intArray->alloc( medIntArray->getNumberOfTuples(), medIntArray->getNumberOfComponents() );
125 intArray->copyStringInfoFrom( * medIntArray.operator->() );
126 std::copy( medIntArray->begin(), medIntArray->end(), intArray->getPointer() );
130 template< class INT >
131 MCAuto<DataArrayMedInt> ToMedIntArray(const std::vector<INT>& intVec )
133 DataArrayMedInt* medIntArray = DataArrayMedInt::New();
134 if ( sizeof( med_int ) == sizeof( INT ))
136 medIntArray->useArray( reinterpret_cast<const med_int*>(intVec.data()), /*owner=*/false, DeallocType::CPP_DEALLOC, intVec.size(), /*nbComp=*/1 );
140 medIntArray->alloc( intVec.size(), 1 );
141 std::copy( intVec.begin(), intVec.end(), medIntArray->getPointer() );
146 template< class INT >
147 med_int ToMedInt( INT i )
149 return static_cast< med_int >( i );
152 template< class INT >
153 INT FromMedInt( med_int mi )
155 return static_cast< INT >( mi );