From: Anthony Geay Date: Thu, 20 Dec 2018 09:08:20 +0000 (+0100) Subject: DataArrayInt64 is now instanciable X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9e5790dc8797cdda5b14017e30feffbd4db85cec;p=tools%2Fmedcoupling.git DataArrayInt64 is now instanciable --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 3d4d0d2a9..38c32cbb1 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -53,6 +53,8 @@ template class MEDCoupling::DataArrayIterator; template class MEDCoupling::DataArrayIterator; template class MEDCoupling::DataArrayDiscrete; template class MEDCoupling::DataArrayDiscreteSigned; +template class MEDCoupling::DataArrayDiscrete; +template class MEDCoupling::DataArrayDiscreteSigned; template class MEDCoupling::DataArrayTuple; template class MEDCoupling::DataArrayTuple; template class MEDCoupling::DataArrayTuple; @@ -948,10 +950,10 @@ void DataArrayDouble::reprQuickOverview(std::ostream& stream) const stream << "DataArrayDouble C++ instance at " << this << ". "; if(isAllocated()) { - int nbOfCompo=(int)_info_on_compo.size(); + std::size_t nbOfCompo(_info_on_compo.size()); if(nbOfCompo>=1) { - int nbOfTuples=getNumberOfTuples(); + std::size_t nbOfTuples(getNumberOfTuples()); stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl; reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR); } @@ -3729,81 +3731,6 @@ void DataArrayInt::writeVTK(std::ostream& ofs, int indent, const std::string& ty ofs << std::endl << idt << "\n"; } -void DataArrayInt::reprCppStream(const std::string& varName, std::ostream& stream) const -{ - int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents(); - const int *data=getConstPointer(); - stream << "DataArrayInt *" << varName << "=DataArrayInt::New();" << std::endl; - if(nbTuples*nbComp>=1) - { - stream << "const int " << varName << "Data[" << nbTuples*nbComp << "]={"; - std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator(stream,",")); - stream << data[nbTuples*nbComp-1] << "};" << std::endl; - stream << varName << "->useArray(" << varName << "Data,false,CPP_DEALLOC," << nbTuples << "," << nbComp << ");" << std::endl; - } - else - stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl; - stream << varName << "->setName(\"" << getName() << "\");" << std::endl; -} - -/*! - * Method that gives a quick overvien of \a this for python. - */ -void DataArrayInt::reprQuickOverview(std::ostream& stream) const -{ - static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300; - stream << "DataArrayInt C++ instance at " << this << ". "; - if(isAllocated()) - { - int nbOfCompo=(int)_info_on_compo.size(); - if(nbOfCompo>=1) - { - int nbOfTuples=getNumberOfTuples(); - stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl; - reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR); - } - else - stream << "Number of components : 0."; - } - else - stream << "*** No data allocated ****"; -} - -void DataArrayInt::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const -{ - const int *data=begin(); - int nbOfTuples=getNumberOfTuples(); - int nbOfCompo=(int)_info_on_compo.size(); - std::ostringstream oss2; oss2 << "["; - std::string oss2Str(oss2.str()); - bool isFinished=true; - for(int i=0;i1) - { - oss2 << "("; - for(int j=0;jbuildDA(nbOfTuples,nbOfCompo); } + +DataArrayInt64 *DataArrayInt64::deepCopy() const +{ + return new DataArrayInt64(*this); +} diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 0ecb0583b..74da75e29 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -246,7 +246,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void setIJSilent(int tupleId, int compoId, T newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; } MEDCOUPLING_EXPORT T *getPointer() { return _mem.getPointer(); declareAsNew(); } MEDCOUPLING_EXPORT void pack() const; - MEDCOUPLING_EXPORT bool isAllocated() const; + MEDCOUPLING_EXPORT bool isAllocated() const override; MEDCOUPLING_EXPORT void checkAllocated() const; MEDCOUPLING_EXPORT void desallocate(); MEDCOUPLING_EXPORT void reserve(std::size_t nbOfElems); @@ -542,6 +542,9 @@ namespace MEDCoupling MEDCOUPLING_EXPORT int getHashCode() const; MEDCOUPLING_EXPORT std::string repr() const; MEDCOUPLING_EXPORT std::string reprZip() const; + MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const; + MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; + MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const; protected: template void switchOnTupleAlg(T val, std::vector& vec, ALG algo) const; @@ -568,9 +571,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT DataArrayInt32 *deepCopy() const;//ok MEDCOUPLING_EXPORT DataArrayInt32 *buildNewEmptyInstance() const { return DataArrayInt32::New(); }//ok MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const std::string& type, const std::string& nameInFile, DataArrayByte *byteArr) const; - MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const; MEDCOUPLING_EXPORT void transformWithIndArr(const int *indArrBg, const int *indArrEnd); MEDCOUPLING_EXPORT void transformWithIndArr(const MapKeyVal& m); MEDCOUPLING_EXPORT DataArrayInt32 *transformWithIndArrR(const int *indArr2Bg, const int *indArrEnd) const; @@ -678,6 +678,15 @@ namespace MEDCoupling class DataArrayInt64 : public DataArrayDiscrete { friend class DataArrayDiscrete; + public: + MEDCOUPLING_EXPORT DataArrayInt64 *deepCopy() const; + MEDCOUPLING_EXPORT DataArrayInt64 *buildNewEmptyInstance() const { return DataArrayInt64::New(); }//ok + MEDCOUPLING_EXPORT DataArrayInt64 *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate::mySelectByTupleId(new2OldBg,new2OldEnd); } + MEDCOUPLING_EXPORT DataArrayInt64 *selectByTupleId(const DataArrayInt32& di) const { return DataArrayTemplate::mySelectByTupleId(di); } + MEDCOUPLING_EXPORT DataArrayInt64 *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); } + MEDCOUPLING_EXPORT DataArrayInt64 *keepSelectedComponents(const std::vector& compoIds) const { return DataArrayTemplate::myKeepSelectedComponents(compoIds); } + MEDCOUPLING_EXPORT DataArrayInt64 *selectByTupleIdSafeSlice(int bg, int end2, int step) const { return DataArrayTemplate::mySelectByTupleIdSafeSlice(bg,end2,step); } + MEDCOUPLING_EXPORT DataArrayInt64 *selectByTupleRanges(const std::vector >& ranges) const { return DataArrayTemplate::mySelectByTupleRanges(ranges); } private: ~DataArrayInt64() { } DataArrayInt64() { } diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index 0d2de8913..2c5fe1975 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -3446,7 +3446,7 @@ struct NotInRange template typename Traits::ArrayType *DataArrayDiscrete::New() { - return new typename Traits::ArrayType; + return nullptr;//new typename Traits::ArrayType; } /*! @@ -3472,7 +3472,8 @@ struct NotInRange template bool DataArrayDiscrete::isEqualWithoutConsideringStrAndOrder(const typename Traits::ArrayType& other) const { - MCAuto a(static_cast::ArrayType *>(this)->deepCopy()),b(other.deepCopy()); + MCAuto::ArrayType> a((static_cast::ArrayType *>(this))->deepCopy()); + MCAuto::ArrayType> b((static_cast::ArrayType *>(&other))->deepCopy()); a->sort(); b->sort(); return a->isEqualWithoutConsideringStr(*b); @@ -3596,7 +3597,7 @@ struct NotInRange const T *thisPt(this->begin()),*pt(partOfThis.begin()); MCAuto ret(DataArrayIdType::New()); ret->alloc(nbTuples,1); - T *retPt(ret->getPointer()); + mcIdType *retPt(ret->getPointer()); std::map m; for(std::size_t i=0;i + void DataArrayDiscrete::reprCppStream(const std::string& varName, std::ostream& stream) const + { + std::size_t nbTuples(DataArrayTemplate::getNumberOfTuples()),nbComp(DataArray::getNumberOfComponents()); + const T *data(DataArrayTemplate::getConstPointer()); + stream << Traits::ArrayTypeName << " *" << varName << "=" << Traits::ArrayTypeName << "::New();" << std::endl; + if(nbTuples*nbComp>=1) + { + stream << "const int " << varName << "Data[" << nbTuples*nbComp << "]={"; + std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator(stream,",")); + stream << data[nbTuples*nbComp-1] << "};" << std::endl; + stream << varName << "->useArray(" << varName << "Data,false,CPP_DEALLOC," << nbTuples << "," << nbComp << ");" << std::endl; + } + else + stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl; + stream << varName << "->setName(\"" << DataArray::getName() << "\");" << std::endl; + } + + /*! + * Method that gives a quick overvien of \a this for python. + */ + template + void DataArrayDiscrete::reprQuickOverview(std::ostream& stream) const + { + static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300; + stream << Traits::ArrayTypeName << " C++ instance at " << this << ". "; + if(DataArrayTemplate::isAllocated()) + { + std::size_t nbOfCompo(DataArray::getNumberOfComponents()); + if(nbOfCompo>=1) + { + std::size_t nbOfTuples(DataArrayTemplate::getNumberOfTuples()); + stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl; + reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR); + } + else + stream << "Number of components : 0."; + } + else + stream << "*** No data allocated ****"; + } + + template + void DataArrayDiscrete::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const + { + const T *data(DataArrayTemplate::begin()); + std::size_t nbOfTuples(DataArrayTemplate::getNumberOfTuples()),nbOfCompo(DataArray::getNumberOfComponents()); + std::ostringstream oss2; oss2 << "["; + std::string oss2Str(oss2.str()); + bool isFinished=true; + for(int i=0;i1) + { + oss2 << "("; + for(int j=0;j