X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingFieldT.txx;h=61e2aa1bf8ffd1fecb0775650d7eb00cafb4dca2;hb=b1681460da1d3c8e3a196e9b13410321587db207;hp=7f6819c18ec2fda9d5e32ac6b179582f8a59229a;hpb=1755dbe71b2fd46cd796464e8aa410d51e033b0d;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingFieldT.txx b/src/MEDCoupling/MEDCouplingFieldT.txx index 7f6819c18..61e2aa1bf 100644 --- a/src/MEDCoupling/MEDCouplingFieldT.txx +++ b/src/MEDCoupling/MEDCouplingFieldT.txx @@ -530,6 +530,133 @@ namespace MEDCoupling throw INTERP_KERNEL::Exception("const FieldT : Null type of time discr !"); return ret; } + + template + void MEDCouplingFieldT::getTinySerializationStrInformation(std::vector& tinyInfo) const + { + tinyInfo.clear(); + timeDiscrSafe()->getTinySerializationStrInformation(tinyInfo); + tinyInfo.push_back(_name); + tinyInfo.push_back(_desc); + tinyInfo.push_back(getTimeUnit()); + } + + /*! + * This method retrieves some critical values to resize and prepare remote instance. + * The first two elements returned in tinyInfo correspond to the parameters to give in constructor. + * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny. + */ + template + void MEDCouplingFieldT::getTinySerializationIntInformation(std::vector& tinyInfo) const + { + if(_type.isNull()) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !"); + tinyInfo.clear(); + tinyInfo.push_back((int)_type->getEnum()); + tinyInfo.push_back((int)timeDiscrSafe()->getEnum()); + tinyInfo.push_back((int)_nature); + timeDiscrSafe()->getTinySerializationIntInformation(tinyInfo); + std::vector tinyInfo2; + _type->getTinySerializationIntInformation(tinyInfo2); + tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end()); + tinyInfo.push_back((int)tinyInfo2.size()); + } + + /*! + * This method retrieves some critical values to resize and prepare remote instance. + * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny. + */ + template + void MEDCouplingFieldT::getTinySerializationDbleInformation(std::vector& tinyInfo) const + { + if(_type.isNull()) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !"); + tinyInfo.clear(); + timeDiscrSafe()->getTinySerializationDbleInformation(tinyInfo); + std::vector tinyInfo2; + _type->getTinySerializationDbleInformation(tinyInfo2); + tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end()); + tinyInfo.push_back((int)tinyInfo2.size());//very bad, lack of time to improve it + } + + /*! + * This method has to be called to the new instance filled by CORBA, MPI, File... + * @param tinyInfoI is the value retrieves from distant result of getTinySerializationIntInformation on source instance to be copied. + * @param dataInt out parameter. If not null the pointer is already owned by \a this after the call of this method. In this case no decrRef must be applied. + * @param arrays out parameter is a vector resized to the right size. The pointers in the vector is already owned by \a this after the call of this method. + * No decrRef must be applied to every instances in returned vector. + * \sa checkForUnserialization + */ + template + void MEDCouplingFieldT::resizeForUnserialization(const std::vector& tinyInfoI, DataArrayInt *&dataInt, std::vector::ArrayType *>& arrays) + { + if(_type.isNull()) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !"); + dataInt=0; + std::vector tinyInfoITmp(tinyInfoI); + int sz=tinyInfoITmp.back(); + tinyInfoITmp.pop_back(); + std::vector tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz); + std::vector tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end()); + timeDiscrSafe()->resizeForUnserialization(tinyInfoI2,arrays); + std::vector tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end()); + _type->resizeForUnserialization(tinyInfoITmp3,dataInt); + } + + /*! + * This method is extremely close to resizeForUnserialization except that here the arrays in \a dataInt and in \a arrays are attached in \a this + * after having checked that size is correct. This method is used in python pickeling context to avoid copy of data. + * \sa resizeForUnserialization + */ + template + void MEDCouplingFieldT::checkForUnserialization(const std::vector& tinyInfoI, const DataArrayInt *dataInt, const std::vector::ArrayType *>& arrays) + { + if(_type.isNull()) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !"); + std::vector tinyInfoITmp(tinyInfoI); + int sz=tinyInfoITmp.back(); + tinyInfoITmp.pop_back(); + std::vector tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz); + std::vector tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end()); + timeDiscrSafe()->checkForUnserialization(tinyInfoI2,arrays); + std::vector tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end()); + _type->checkForUnserialization(tinyInfoITmp3,dataInt); + } + + template + void MEDCouplingFieldT::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) + { + if(_type.isNull()) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !"); + std::vector tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end()); + // + std::vector tmp(tinyInfoD); + int sz=(int)tinyInfoD.back();//very bad, lack of time to improve it + tmp.pop_back(); + std::vector tmp1(tmp.begin(),tmp.end()-sz); + std::vector tmp2(tmp.end()-sz,tmp.end()); + // + timeDiscrSafe()->finishUnserialization(tinyInfoI2,tmp1,tinyInfoS); + _nature=(NatureOfField)tinyInfoI[2]; + _type->finishUnserialization(tmp2); + int nbOfElemS=(int)tinyInfoS.size(); + _name=tinyInfoS[nbOfElemS-3]; + _desc=tinyInfoS[nbOfElemS-2]; + setTimeUnit(tinyInfoS[nbOfElemS-1]); + } + + /*! + * Contrary to MEDCouplingPointSet class the returned arrays are \b not the responsabilities of the caller. + * The values returned must be consulted only in readonly mode. + */ + template + void MEDCouplingFieldT::serialize(DataArrayInt *&dataInt, std::vector::ArrayType *>& arrays) const + { + if(_type.isNull()) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform serialize !"); + timeDiscrSafe()->getArrays(arrays); + _type->getSerializationIntArray(dataInt); + } } #endif