From: Anthony Geay Date: Tue, 16 May 2017 06:46:00 +0000 (+0200) Subject: Biking along the template road X-Git-Tag: V8_4_0a1~49 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9132631b57f12deb523f6e2e0cfc98bdbe9424c8;p=tools%2Fmedcoupling.git Biking along the template road --- diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index df38605c5..22aefdc4a 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -45,10 +45,14 @@ extern med_geometry_type typmai3[34]; using namespace MEDCoupling; template class MEDCoupling::MEDFileField1TSTemplateWithoutSDA; +template class MEDCoupling::MEDFileField1TSTemplateWithoutSDA; template class MEDCoupling::MEDFileField1TSTemplateWithoutSDA; +template class MEDCoupling::MEDFileTemplateField1TS; +template class MEDCoupling::MEDFileTemplateField1TS; const char MEDFileField1TSWithoutSDA::TYPE_STR[]="FLOAT64"; const char MEDFileIntField1TSWithoutSDA::TYPE_STR[]="INT32"; +const char MEDFileFloatField1TSWithoutSDA::TYPE_STR[]="FLOAT32"; MEDFileGTKeeper::~MEDFileGTKeeper() { @@ -5796,7 +5800,7 @@ MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::New(const std::strin return new MEDFileIntField1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos); } -MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA():MEDFileField1TSTemplateWithoutSDA() +MEDFileIntField1TSWithoutSDA::MEDFileIntField1TSWithoutSDA() { } @@ -5817,10 +5821,9 @@ MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const MCAuto ret(new MEDFileField1TSWithoutSDA); ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this); ret->deepCpyLeavesFrom(*this); - const DataArrayInt *arr(_arr); - if(arr) + if(_arr.isNotNull()) { - MCAuto arr2(arr->convertToDblArr()); + MCAuto arr2(_arr->convertToDblArr()); ret->setArray(arr2); } return ret.retn(); @@ -5888,12 +5891,110 @@ MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const return ret.retn(); } -MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS() +//= MEDFileFloatField1TSWithoutSDA + +MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector& infos) +{ + return new MEDFileFloatField1TSWithoutSDA(fieldName,meshName,csit,iteration,order,infos); +} + +MEDFileFloatField1TSWithoutSDA::MEDFileFloatField1TSWithoutSDA() +{ +} + +MEDFileFloatField1TSWithoutSDA::MEDFileFloatField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, + const std::vector& infos):MEDFileField1TSTemplateWithoutSDA(fieldName,meshName,csit,iteration,order) +{ + DataArrayFloat *arr(getOrCreateAndGetArrayTemplate()); + arr->setInfoAndChangeNbOfCompo(infos); +} + +const char *MEDFileFloatField1TSWithoutSDA::getTypeStr() const +{ + return TYPE_STR; +} + +MEDFileField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::convertToDouble() const +{ + MCAuto ret(new MEDFileField1TSWithoutSDA); + ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this); + ret->deepCpyLeavesFrom(*this); + if(_arr.isNotNull()) + { + MCAuto arr2(_arr->convertToDblArr()); + ret->setArray(arr2); + } + return ret.retn(); +} + +/*! + * Returns a pointer to the underground DataArrayFloat instance and a + * sequence describing parameters of a support of each part of \a this field. The + * caller should not decrRef() the returned DataArrayFloat. This method allows for a + * direct access to the field values. This method is intended for the field lying on one + * mesh only. + * \param [in,out] entries - the sequence describing parameters of a support of each + * part of \a this field. Each item of this sequence consists of two parts. The + * first part describes a type of mesh entity and an id of discretization of a + * current field part. The second part describes a range of values [begin,end) + * within the returned array relating to the current field part. + * \return DataArrayFloat * - the pointer to the field values array. + * \throw If the number of underlying meshes is not equal to 1. + * \throw If no field values are available. + * \sa getUndergroundDataArray() + */ +DataArray *MEDFileFloatField1TSWithoutSDA::getUndergroundDataArrayExt(std::vector< std::pair,std::pair > >& entries) const +{ + return getUndergroundDataArrayFloatExt(entries); +} + +/*! + * Returns a pointer to the underground DataArrayFloat instance and a + * sequence describing parameters of a support of each part of \a this field. The + * caller should not decrRef() the returned DataArrayFloat. This method allows for a + * direct access to the field values. This method is intended for the field lying on one + * mesh only. + * \param [in,out] entries - the sequence describing parameters of a support of each + * part of \a this field. Each item of this sequence consists of two parts. The + * first part describes a type of mesh entity and an id of discretization of a + * current field part. The second part describes a range of values [begin,end) + * within the returned array relating to the current field part. + * \return DataArrayFloat * - the pointer to the field values array. + * \throw If the number of underlying meshes is not equal to 1. + * \throw If no field values are available. + * \sa getUndergroundDataArray() + */ +DataArrayFloat *MEDFileFloatField1TSWithoutSDA::getUndergroundDataArrayFloatExt(std::vector< std::pair,std::pair > >& entries) const { + if(_field_per_mesh.size()!=1) + throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : field lies on several meshes, this method has no sense !"); + if(_field_per_mesh[0]==0) + throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt : no field specified !"); + _field_per_mesh[0]->getUndergroundDataArrayExt(entries); + return getUndergroundDataArrayTemplate(); +} + +MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::shallowCpy() const +{ + MCAuto ret(new MEDFileFloatField1TSWithoutSDA(*this)); + ret->deepCpyLeavesFrom(*this); + return ret.retn(); +} + +MEDFileFloatField1TSWithoutSDA *MEDFileFloatField1TSWithoutSDA::deepCopy() const +{ + MCAuto ret(shallowCpy()); + if(_arr.isNotNull()) + ret->_arr=_arr->deepCopy(); + return ret.retn(); } //= MEDFileAnyTypeField1TS +MEDFileAnyTypeField1TS::MEDFileAnyTypeField1TS() +{ +} + MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_idt fid, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities) { med_field_type typcha; @@ -5914,6 +6015,11 @@ MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_i ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector()); break; } + case MED_NODE://6432 + { + ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector()); + break; + } default: { std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fid) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of the first field is not in [MED_FLOAT64, MED_INT32] !"; @@ -5951,8 +6057,11 @@ MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_i med_field_type typcha; std::vector infos; std::string dtunit,meshName; - int iii=-1; - int nbSteps=LocateField(fid,fieldName,iii,typcha,infos,dtunit,meshName); + int nbSteps(0); + { + int iii=-1; + nbSteps=LocateField(fid,fieldName,iii,typcha,infos,dtunit,meshName); + } MCAuto ret; switch(typcha) { @@ -5966,6 +6075,11 @@ MEDFileAnyTypeField1TSWithoutSDA *MEDFileAnyTypeField1TS::BuildContentFrom(med_i ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector()); break; } + case MED_NODE://6432 + { + ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector()); + break; + } default: { std::ostringstream oss; oss << "MEDFileAnyTypeField1TS::BuildContentFrom(fid,fieldName) : file \'" << FileNameFromFID(fid) << "\' contains field with name \'" << fieldName << "\' but the type of field is not in [MED_FLOAT64, MED_INT32] !"; @@ -6710,107 +6824,6 @@ int MEDFileAnyTypeField1TS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field //= MEDFileField1TS -/*! - * Returns a new instance of MEDFileField1TS holding data of the first time step of - * the first field that has been read from a specified MED file. - * \param [in] fileName - the name of the MED file to read. - * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller - * is to delete this field using decrRef() as it is no more needed. - * \throw If reading the file fails. - */ -MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, bool loadAll) -{ - MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); - return New(fid,loadAll); -} - -MEDFileField1TS *MEDFileField1TS::New(med_idt fid, bool loadAll) -{ - MCAuto ret(new MEDFileField1TS(fid,loadAll,0)); - ret->contentNotNull(); - return ret.retn(); -} - -/*! - * Returns a new instance of MEDFileField1TS holding data of the first time step of - * a given field that has been read from a specified MED file. - * \param [in] fileName - the name of the MED file to read. - * \param [in] fieldName - the name of the field to read. - * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller - * is to delete this field using decrRef() as it is no more needed. - * \throw If reading the file fails. - * \throw If there is no field named \a fieldName in the file. - */ -MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll) -{ - MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); - return New(fid,fieldName,loadAll); -} - -MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll) -{ - MCAuto ret(new MEDFileField1TS(fid,fieldName,loadAll,0)); - ret->contentNotNull(); - return ret.retn(); -} - -/*! - * Returns a new instance of MEDFileField1TS holding data of a given time step of - * a given field that has been read from a specified MED file. - * \param [in] fileName - the name of the MED file to read. - * \param [in] fieldName - the name of the field to read. - * \param [in] iteration - the iteration number of a required time step. - * \param [in] order - the iteration order number of required time step. - * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller - * is to delete this field using decrRef() as it is no more needed. - * \throw If reading the file fails. - * \throw If there is no field named \a fieldName in the file. - * \throw If the required time step is missing from the file. - */ -MEDFileField1TS *MEDFileField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll) -{ - MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); - return New(fid,fieldName,iteration,order,loadAll); -} - -MEDFileField1TS *MEDFileField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll) -{ - MCAuto ret(new MEDFileField1TS(fid,fieldName,iteration,order,loadAll,0)); - ret->contentNotNull(); - return ret.retn(); -} - -/*! - * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied. - * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this. - * - * Returns a new instance of MEDFileField1TS holding either a shallow copy - * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself. - * \warning this is a shallow copy constructor - * \param [in] other - a MEDFileField1TSWithoutSDA to copy. - * \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created. - * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller - * is to delete this field using decrRef() as it is no more needed. - */ -MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent) -{ - MCAuto ret(new MEDFileField1TS(other,shallowCopyOfContent)); - ret->contentNotNull(); - return ret.retn(); -} - -/*! - * Returns a new empty instance of MEDFileField1TS. - * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller - * is to delete this field using decrRef() as it is no more needed. - */ -MEDFileField1TS *MEDFileField1TS::New() -{ - MCAuto ret(new MEDFileField1TS); - ret->contentNotNull(); - return ret.retn(); -} - /*! * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied * following the given input policy. @@ -6840,28 +6853,6 @@ MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool isDeepCpyGlobs) const return ret.retn(); } -const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const -{ - const MEDFileAnyTypeField1TSWithoutSDA *pt(_content); - if(!pt) - throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is null !"); - const MEDFileField1TSWithoutSDA *ret=dynamic_cast(pt); - if(!ret) - throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !"); - return ret; -} - -MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() -{ - MEDFileAnyTypeField1TSWithoutSDA *pt(_content); - if(!pt) - throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is null !"); - MEDFileField1TSWithoutSDA *ret=dynamic_cast(pt); - if(!ret) - throw INTERP_KERNEL::Exception("MEDFileField1TS::contentNotNull : the non const content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !"); - return ret; -} - void MEDFileField1TS::SetDataArrayDoubleInField(MEDCouplingFieldDouble *f, MCAuto& arr) { if(!f) @@ -6938,21 +6929,21 @@ MEDFileField1TS *MEDFileField1TS::extractPart(const std::map(fid,loadAll,ms) { } catch(INTERP_KERNEL::Exception& e) { throw e; } MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms) -try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms) +try:MEDFileTemplateField1TS(fid,fieldName,loadAll,ms) { } catch(INTERP_KERNEL::Exception& e) { throw e; } MEDFileField1TS::MEDFileField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms) -try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms) +try:MEDFileTemplateField1TS(fid,fieldName,iteration,order,loadAll,ms) { } catch(INTERP_KERNEL::Exception& e) @@ -6965,17 +6956,12 @@ catch(INTERP_KERNEL::Exception& e) * \warning this is a shallow copy constructor */ MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent) -try:MEDFileAnyTypeField1TS(other,shallowCopyOfContent) +try:MEDFileTemplateField1TS(other,shallowCopyOfContent) { } catch(INTERP_KERNEL::Exception& e) { throw e; } -MEDFileField1TS::MEDFileField1TS() -{ - _content=new MEDFileField1TSWithoutSDA; -} - /*! * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance * method should be called (getFieldOnMeshAtLevel for example). @@ -7243,80 +7229,22 @@ std::vector< std::vector > MEDFileField1TS::getFieldSplitedBy //= MEDFileIntField1TS -MEDFileIntField1TS *MEDFileIntField1TS::New() -{ - MCAuto ret(new MEDFileIntField1TS); - ret->contentNotNull(); - return ret.retn(); -} - -MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, bool loadAll) -{ - MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); - return MEDFileIntField1TS::New(fid,loadAll); -} - -MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, bool loadAll) -{ - MCAuto ret(new MEDFileIntField1TS(fid,loadAll,0)); - ret->contentNotNull(); - return ret.retn(); -} - -MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll) -{ - MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); - return MEDFileIntField1TS::New(fid,fieldName,loadAll); -} - -MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll) -{ - MCAuto ret(new MEDFileIntField1TS(fid,fieldName,loadAll,0)); - ret->contentNotNull(); - return ret.retn(); -} - -MEDFileIntField1TS *MEDFileIntField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll) -{ - MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); - return MEDFileIntField1TS::New(fid,fieldName,iteration,order,loadAll); -} - -MEDFileIntField1TS *MEDFileIntField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll) -{ - MCAuto ret(new MEDFileIntField1TS(fid,fieldName,iteration,order,loadAll,0)); - ret->contentNotNull(); - return ret.retn(); -} - -MEDFileIntField1TS *MEDFileIntField1TS::New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent) -{ - MCAuto ret=new MEDFileIntField1TS(other,shallowCopyOfContent); - ret->contentNotNull(); - return ret.retn(); -} - -MEDFileIntField1TS::MEDFileIntField1TS() -{ - _content=new MEDFileIntField1TSWithoutSDA; -} - MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms) -try:MEDFileAnyTypeField1TS(fid,loadAll,ms) +try:MEDFileTemplateField1TS(fid,loadAll,ms) { } catch(INTERP_KERNEL::Exception& e) { throw e; } MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms) -try:MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms) +try:MEDFileTemplateField1TS(fid,fieldName,loadAll,ms) { } catch(INTERP_KERNEL::Exception& e) { throw e; } MEDFileIntField1TS::MEDFileIntField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms) -try:MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms) +try:MEDFileTemplateField1TS(fid,fieldName,iteration,order,loadAll,ms) { } catch(INTERP_KERNEL::Exception& e) @@ -7328,7 +7256,7 @@ catch(INTERP_KERNEL::Exception& e) * * \warning this is a shallow copy constructor */ -MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent) +MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent):MEDFileTemplateField1TS(other,shallowCopyOfContent) { } @@ -7415,15 +7343,15 @@ void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldInt *field, const contentNotNull()->setFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull()); } -const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const +DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto& arr) { - const MEDFileAnyTypeField1TSWithoutSDA *pt(_content); - if(!pt) - throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is null !"); - const MEDFileIntField1TSWithoutSDA *ret=dynamic_cast(pt); - if(!ret) - throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the content pointer is not null but it is not of type int32 ! Reason is maybe that the read field has not the type INT32 !"); - return ret; + if(arr.isNull()) + throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !"); + DataArrayInt *arrC(dynamic_cast((DataArray *)arr)); + if(!arrC) + throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !"); + arrC->incrRef(); + return arrC; } MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol) const @@ -7436,17 +7364,6 @@ MEDCouplingFieldInt *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, int m return ret2.retn(); } -DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto& arr) -{ - if(arr.isNull()) - throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !"); - DataArrayInt *arrC(dynamic_cast((DataArray *)arr)); - if(!arrC) - throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is not of type INT32 !"); - arrC->incrRef(); - return arrC; -} - MCAuto MEDFileIntField1TS::SetDataArrayDoubleInIntField(MEDCouplingFieldDouble *f, MCAuto& arr) { int t1,t2; @@ -7639,17 +7556,6 @@ DataArrayInt *MEDFileIntField1TS::getFieldWithProfile(TypeOfField type, int mesh return MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr); } -MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() -{ - MEDFileAnyTypeField1TSWithoutSDA *pt(_content); - if(!pt) - throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is null !"); - MEDFileIntField1TSWithoutSDA *ret=dynamic_cast(pt); - if(!ret) - throw INTERP_KERNEL::Exception("MEDFileIntField1TS::contentNotNull : the non const content pointer is not null but it is not of type int32 ! Reason is maybe that the read field has not the type INT32 !"); - return ret; -} - DataArrayInt *MEDFileIntField1TS::getUndergroundDataArray() const { return contentNotNull()->getUndergroundDataArrayTemplate(); diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index f2c3b324c..81136577f 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -746,6 +746,26 @@ namespace MEDCoupling MEDLOADER_EXPORT static const char TYPE_STR[]; }; + /*! + * SDA is for Shared Data Arrays such as profiles. + */ + class MEDFileFloatField1TSWithoutSDA : public MEDFileField1TSTemplateWithoutSDA + { + public: + MEDLOADER_EXPORT MEDFileFloatField1TSWithoutSDA(); + MEDLOADER_EXPORT static MEDFileFloatField1TSWithoutSDA *New(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector& infos); + MEDLOADER_EXPORT MEDFileFloatField1TSWithoutSDA *deepCopy() const; + MEDLOADER_EXPORT MEDFileFloatField1TSWithoutSDA *shallowCpy() const; + MEDLOADER_EXPORT const char *getTypeStr() const; + MEDLOADER_EXPORT DataArray *getUndergroundDataArrayExt(std::vector< std::pair,std::pair > >& entries) const; + MEDLOADER_EXPORT DataArrayFloat *getUndergroundDataArrayFloatExt(std::vector< std::pair,std::pair > >& entries) const; + MEDLOADER_EXPORT MEDFileField1TSWithoutSDA *convertToDouble() const; + protected: + MEDFileFloatField1TSWithoutSDA(const std::string& fieldName, const std::string& meshName, int csit, int iteration, int order, const std::vector& infos); + public: + MEDLOADER_EXPORT static const char TYPE_STR[]; + }; + /*! * User class. */ @@ -845,21 +865,37 @@ namespace MEDCoupling class MEDFileIntField1TS; + template + class MEDFileTemplateField1TS : public MEDFileAnyTypeField1TS + { + public: + MEDLOADER_EXPORT static typename MLFieldTraits::F1TSType *New(); + MEDLOADER_EXPORT static typename MLFieldTraits::F1TSType *New(const std::string& fileName, bool loadAll=true); + MEDLOADER_EXPORT static typename MLFieldTraits::F1TSType *New(med_idt fid, bool loadAll=true); + MEDLOADER_EXPORT static typename MLFieldTraits::F1TSType *New(DataArrayByte *db) { return BuildFromMemoryChunk::F1TSType>(db); } + MEDLOADER_EXPORT static typename MLFieldTraits::F1TSType *New(const std::string& fileName, const std::string& fieldName, bool loadAll=true); + MEDLOADER_EXPORT static typename MLFieldTraits::F1TSType *New(med_idt fid, const std::string& fieldName, bool loadAll=true); + MEDLOADER_EXPORT static typename MLFieldTraits::F1TSType *New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll=true); + MEDLOADER_EXPORT static typename MLFieldTraits::F1TSType *New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll=true); + MEDLOADER_EXPORT static typename MLFieldTraits::F1TSType *New(const typename MLFieldTraits::F1TSWSDAType& other, bool shallowCopyOfContent); + protected: + ~MEDFileTemplateField1TS() { } + MEDFileTemplateField1TS(); + MEDFileTemplateField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms):MEDFileAnyTypeField1TS(fid,loadAll,ms) { } + MEDFileTemplateField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms):MEDFileAnyTypeField1TS(fid,fieldName,loadAll,ms) { } + MEDFileTemplateField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms):MEDFileAnyTypeField1TS(fid,fieldName,iteration,order,loadAll,ms) { } + MEDFileTemplateField1TS(const typename MLFieldTraits::F1TSWSDAType& other, bool shallowCopyOfContent):MEDFileAnyTypeField1TS(other,shallowCopyOfContent) { } + const typename MLFieldTraits::F1TSWSDAType *contentNotNull() const; + typename MLFieldTraits::F1TSWSDAType *contentNotNull(); + }; + /*! * User class. */ - class MEDFileField1TS : public MEDFileAnyTypeField1TS + class MEDFileField1TS : public MEDFileTemplateField1TS { + friend class MEDFileTemplateField1TS; public: - MEDLOADER_EXPORT static MEDFileField1TS *New(const std::string& fileName, bool loadAll=true); - MEDLOADER_EXPORT static MEDFileField1TS *New(med_idt fid, bool loadAll=true); - MEDLOADER_EXPORT static MEDFileField1TS *New(DataArrayByte *db) { return BuildFromMemoryChunk(db); } - MEDLOADER_EXPORT static MEDFileField1TS *New(const std::string& fileName, const std::string& fieldName, bool loadAll=true); - MEDLOADER_EXPORT static MEDFileField1TS *New(med_idt fid, const std::string& fieldName, bool loadAll=true); - MEDLOADER_EXPORT static MEDFileField1TS *New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll=true); - MEDLOADER_EXPORT static MEDFileField1TS *New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll=true); - MEDLOADER_EXPORT static MEDFileField1TS *New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent); - MEDLOADER_EXPORT static MEDFileField1TS *New(); MEDLOADER_EXPORT MEDFileIntField1TS *convertToInt(bool isDeepCpyGlobs=true) const; // MEDLOADER_EXPORT MEDCouplingFieldDouble *field(const MEDFileMesh *mesh) const; @@ -887,29 +923,19 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDFileField1TS *extractPart(const std::map >& extractDef, MEDFileMesh *mm) const; private: med_field_type getMEDFileFieldType() const { return MED_FLOAT64; } - const MEDFileField1TSWithoutSDA *contentNotNull() const; - MEDFileField1TSWithoutSDA *contentNotNull(); private: ~MEDFileField1TS() { } MEDFileField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms); MEDFileField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms); MEDFileField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms); MEDFileField1TS(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent); - MEDFileField1TS(); + MEDFileField1TS() { } }; - class MEDFileIntField1TS : public MEDFileAnyTypeField1TS + class MEDFileIntField1TS : public MEDFileTemplateField1TS { + friend class MEDFileTemplateField1TS; public: - MEDLOADER_EXPORT static MEDFileIntField1TS *New(); - MEDLOADER_EXPORT static MEDFileIntField1TS *New(const std::string& fileName, bool loadAll=true); - MEDLOADER_EXPORT static MEDFileIntField1TS *New(med_idt fid, bool loadAll=true); - MEDLOADER_EXPORT static MEDFileIntField1TS *New(DataArrayByte *db) { return BuildFromMemoryChunk(db); } - MEDLOADER_EXPORT static MEDFileIntField1TS *New(const std::string& fileName, const std::string& fieldName, bool loadAll=true); - MEDLOADER_EXPORT static MEDFileIntField1TS *New(med_idt fid, const std::string& fieldName, bool loadAll=true); - MEDLOADER_EXPORT static MEDFileIntField1TS *New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll=true); - MEDLOADER_EXPORT static MEDFileIntField1TS *New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll=true); - MEDLOADER_EXPORT static MEDFileIntField1TS *New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent); MEDLOADER_EXPORT MEDFileField1TS *convertToDouble(bool isDeepCpyGlobs=true) const; MEDLOADER_EXPORT MEDFileIntField1TS *shallowCpy() const; // @@ -932,11 +958,9 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDFileIntField1TS *extractPart(const std::map >& extractDef, MEDFileMesh *mm) const; private: med_field_type getMEDFileFieldType() const { return MED_INT32; } - const MEDFileIntField1TSWithoutSDA *contentNotNull() const; - MEDFileIntField1TSWithoutSDA *contentNotNull(); private: ~MEDFileIntField1TS() { } - MEDFileIntField1TS(); + MEDFileIntField1TS() { } MEDFileIntField1TS(med_idt fid, bool loadAll, const MEDFileMeshes *ms); MEDFileIntField1TS(med_idt fid, const std::string& fieldName, bool loadAll, const MEDFileMeshes *ms); MEDFileIntField1TS(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll, const MEDFileMeshes *ms); diff --git a/src/MEDLoader/MEDFileField.txx b/src/MEDLoader/MEDFileField.txx index ae2b3a93a..639bc1ab9 100644 --- a/src/MEDLoader/MEDFileField.txx +++ b/src/MEDLoader/MEDFileField.txx @@ -167,6 +167,145 @@ namespace MEDCoupling start+=(*it).second.second-(*it).second.first; } } + + template + MEDFileTemplateField1TS::MEDFileTemplateField1TS() + { + _content=new typename MLFieldTraits::F1TSWSDAType; + } + + /*! + * Returns a new empty instance of MEDFileField1TS. + * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller + * is to delete this field using decrRef() as it is no more needed. + */ + template + typename MLFieldTraits::F1TSType *MEDFileTemplateField1TS::New() + { + MCAuto::F1TSType> ret(new typename MLFieldTraits::F1TSType); + ret->contentNotNull(); + return ret.retn(); + } + + /*! + * Returns a new instance of MEDFileField1TS holding data of the first time step of + * the first field that has been read from a specified MED file. + * \param [in] fileName - the name of the MED file to read. + * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller + * is to delete this field using decrRef() as it is no more needed. + * \throw If reading the file fails. + */ + template + typename MLFieldTraits::F1TSType *MEDFileTemplateField1TS::New(const std::string& fileName, bool loadAll) + { + MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); + return New(fid,loadAll); + } + + template + typename MLFieldTraits::F1TSType *MEDFileTemplateField1TS::New(med_idt fid, bool loadAll) + { + MCAuto::F1TSType> ret(new typename MLFieldTraits::F1TSType(fid,loadAll,0)); + ret->contentNotNull(); + return ret.retn(); + } + + /*! + * Returns a new instance of MEDFileField1TS holding data of the first time step of + * a given field that has been read from a specified MED file. + * \param [in] fileName - the name of the MED file to read. + * \param [in] fieldName - the name of the field to read. + * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller + * is to delete this field using decrRef() as it is no more needed. + * \throw If reading the file fails. + * \throw If there is no field named \a fieldName in the file. + */ + template + typename MLFieldTraits::F1TSType *MEDFileTemplateField1TS::New(const std::string& fileName, const std::string& fieldName, bool loadAll) + { + MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); + return New(fid,fieldName,loadAll); + } + + template + typename MLFieldTraits::F1TSType *MEDFileTemplateField1TS::New(med_idt fid, const std::string& fieldName, bool loadAll) + { + MCAuto::F1TSType> ret(new typename MLFieldTraits::F1TSType(fid,fieldName,loadAll,0)); + ret->contentNotNull(); + return ret.retn(); + } + + /*! + * Returns a new instance of MEDFileField1TS holding data of a given time step of + * a given field that has been read from a specified MED file. + * \param [in] fileName - the name of the MED file to read. + * \param [in] fieldName - the name of the field to read. + * \param [in] iteration - the iteration number of a required time step. + * \param [in] order - the iteration order number of required time step. + * \return MEDFileField1TS * - a new instance of MEDFileFieldMultiTS. The caller + * is to delete this field using decrRef() as it is no more needed. + * \throw If reading the file fails. + * \throw If there is no field named \a fieldName in the file. + * \throw If the required time step is missing from the file. + */ + template + typename MLFieldTraits::F1TSType *MEDFileTemplateField1TS::New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll) + { + MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); + return New(fid,fieldName,iteration,order,loadAll); + } + + template + typename MLFieldTraits::F1TSType *MEDFileTemplateField1TS::New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll) + { + MCAuto::F1TSType> ret(new typename MLFieldTraits::F1TSType(fid,fieldName,iteration,order,loadAll,0)); + ret->contentNotNull(); + return ret.retn(); + } + + /*! + * Returns a new instance of MEDFileField1TS. If \a shallowCopyOfContent is true the content of \a other is shallow copied. + * If \a shallowCopyOfContent is false, \a other is taken to be the content of \a this. + * + * Returns a new instance of MEDFileField1TS holding either a shallow copy + * of a given MEDFileField1TSWithoutSDA ( \a other ) or \a other itself. + * \warning this is a shallow copy constructor + * \param [in] other - a MEDFileField1TSWithoutSDA to copy. + * \param [in] shallowCopyOfContent - if \c true, a shallow copy of \a other is created. + * \return MEDFileField1TS * - a new instance of MEDFileField1TS. The caller + * is to delete this field using decrRef() as it is no more needed. + */ + template + typename MLFieldTraits::F1TSType *MEDFileTemplateField1TS::New(const typename MLFieldTraits::F1TSWSDAType& other, bool shallowCopyOfContent) + { + MCAuto::F1TSType> ret(new typename MLFieldTraits::F1TSType(other,shallowCopyOfContent)); + ret->contentNotNull(); + return ret.retn(); + } + + template + const typename MLFieldTraits::F1TSWSDAType *MEDFileTemplateField1TS::contentNotNull() const + { + const MEDFileAnyTypeField1TSWithoutSDA *pt(_content); + if(!pt) + throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS::contentNotNull : the content pointer is null !"); + const typename MLFieldTraits::F1TSWSDAType *ret(dynamic_cast::F1TSWSDAType *>(pt)); + if(!ret) + throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS::contentNotNull : the content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !"); + return ret; + } + + template + typename MLFieldTraits::F1TSWSDAType *MEDFileTemplateField1TS::contentNotNull() + { + MEDFileAnyTypeField1TSWithoutSDA *pt(_content); + if(!pt) + throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS::contentNotNull : the non const content pointer is null !"); + typename MLFieldTraits::F1TSWSDAType *ret(dynamic_cast::F1TSWSDAType *>(pt)); + if(!ret) + throw INTERP_KERNEL::Exception("MEDFileTemplateField1TS::contentNotNull : the non const content pointer is not null but it is not of type double ! Reason is maybe that the read field has not the type FLOAT64 !"); + return ret; + } } #endif diff --git a/src/MEDLoader/MEDLoaderTraits.hxx b/src/MEDLoader/MEDLoaderTraits.hxx index 03f246ac5..73f6a4e3f 100644 --- a/src/MEDLoader/MEDLoaderTraits.hxx +++ b/src/MEDLoader/MEDLoaderTraits.hxx @@ -37,6 +37,7 @@ namespace MEDCoupling class MEDFileIntField1TS; class MEDFileField1TSWithoutSDA; class MEDFileIntField1TSWithoutSDA; + class MEDFileFloatField1TSWithoutSDA; template<> struct MEDLOADER_EXPORT MLFieldTraits @@ -45,6 +46,14 @@ namespace MEDCoupling typedef MEDFileField1TS F1TSType; typedef MEDFileField1TSWithoutSDA F1TSWSDAType; }; + + template<> + struct MEDLOADER_EXPORT MLFieldTraits + { + //typedef MEDFileFloatFieldMultiTS FMTSType; + //typedef MEDFileFloatField1TS F1TSType; + typedef MEDFileFloatField1TSWithoutSDA F1TSWSDAType; + }; template<> struct MEDLOADER_EXPORT MLFieldTraits