From 70768c7ed8d5bdfac23d7d796fdbc76c1a732ea9 Mon Sep 17 00:00:00 2001 From: ageay Date: Mon, 18 Mar 2013 15:02:28 +0000 Subject: [PATCH] DataArrayChar, DataArrayByte, DataArrayAsciiChar + throw in the API for swig protection --- src/MEDCoupling/MEDCouplingMemArray.cxx | 146 +-- src/MEDCoupling/MEDCouplingMemArray.hxx | 310 ++++--- src/MEDCoupling/MEDCouplingMemArrayChar.cxx | 510 ++++++++--- src/MEDCoupling_Swig/MEDCouplingCommon.i | 968 ++++++++++++++++++-- src/MEDCoupling_Swig/MEDCouplingTypemaps.i | 26 + 5 files changed, 1558 insertions(+), 402 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index d5b137514..fc3e9e862 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -176,7 +176,7 @@ void DataArray::copyPartOfStringInfoFrom2(const std::vector& compoIds, cons setInfoOnComponent(compoIds[i],other.getInfoOnComponent((int)i).c_str()); } -bool DataArray::areInfoEqualsIfNotWhy(const DataArray& other, std::string& reason) const +bool DataArray::areInfoEqualsIfNotWhy(const DataArray& other, std::string& reason) const throw(INTERP_KERNEL::Exception) { std::ostringstream oss; if(_name!=other._name) @@ -209,13 +209,13 @@ bool DataArray::areInfoEqualsIfNotWhy(const DataArray& other, std::string& reaso * \param [in] other - another instance of DataArray to compare the textual data of. * \return bool - \a true if the textual information is same, \a false else. */ -bool DataArray::areInfoEquals(const DataArray& other) const +bool DataArray::areInfoEquals(const DataArray& other) const throw(INTERP_KERNEL::Exception) { std::string tmp; return areInfoEqualsIfNotWhy(other,tmp); } -void DataArray::reprWithoutNameStream(std::ostream& stream) const +void DataArray::reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) { stream << "Number of components : "<< getNumberOfComponents() << "\n"; stream << "Info of these components : "; @@ -247,7 +247,7 @@ void DataArray::setInfoOnComponents(const std::vector& info) throw( _info_on_compo=info; } -std::vector DataArray::getVarsOnComponent() const +std::vector DataArray::getVarsOnComponent() const throw(INTERP_KERNEL::Exception) { int nbOfCompo=(int)_info_on_compo.size(); std::vector ret(nbOfCompo); @@ -256,7 +256,7 @@ std::vector DataArray::getVarsOnComponent() const return ret; } -std::vector DataArray::getUnitsOnComponent() const +std::vector DataArray::getUnitsOnComponent() const throw(INTERP_KERNEL::Exception) { int nbOfCompo=(int)_info_on_compo.size(); std::vector ret(nbOfCompo); @@ -572,7 +572,7 @@ DataArrayDouble *DataArrayDouble::New() * in \ref MEDCouplingArrayBasicsTuplesAndCompo "DataArrays infos" for more information. * \return bool - \a true if the raw data is allocated, \a false else. */ -bool DataArrayDouble::isAllocated() const +bool DataArrayDouble::isAllocated() const throw(INTERP_KERNEL::Exception) { return getConstPointer()!=0; } @@ -657,7 +657,7 @@ bool DataArrayDouble::empty() const throw(INTERP_KERNEL::Exception) * \ref MEDCouplingArrayBasicsCopyDeep. * \return DataArrayDouble * - a new instance of DataArrayDouble. */ -DataArrayDouble *DataArrayDouble::deepCpy() const +DataArrayDouble *DataArrayDouble::deepCpy() const throw(INTERP_KERNEL::Exception) { return new DataArrayDouble(*this); } @@ -669,7 +669,7 @@ DataArrayDouble *DataArrayDouble::deepCpy() const * \return DataArrayDouble * - either a new instance of DataArrayDouble (if \a dCpy * == \a true) or \a this instance (if \a dCpy == \a false). */ -DataArrayDouble *DataArrayDouble::performCpy(bool dCpy) const +DataArrayDouble *DataArrayDouble::performCpy(bool dCpy) const throw(INTERP_KERNEL::Exception) { if(dCpy) return deepCpy(); @@ -800,7 +800,7 @@ void DataArrayDouble::pack() const throw(INTERP_KERNEL::Exception) * \param [in] nbOfCompo - number of components of data to allocate. * \throw If \a nbOfTuple < 0 or \a nbOfCompo < 0. */ -void DataArrayDouble::allocIfNecessary(int nbOfTuple, int nbOfCompo) +void DataArrayDouble::allocIfNecessary(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception) { if(isAllocated()) { @@ -995,14 +995,14 @@ bool DataArrayDouble::isMonotonic(bool increasing, double eps) const throw(INTER * DataArrayDouble. This text is shown when a DataArrayDouble is printed in Python. * \return std::string - text describing \a this DataArrayDouble. */ -std::string DataArrayDouble::repr() const +std::string DataArrayDouble::repr() const throw(INTERP_KERNEL::Exception) { std::ostringstream ret; reprStream(ret); return ret.str(); } -std::string DataArrayDouble::reprZip() const +std::string DataArrayDouble::reprZip() const throw(INTERP_KERNEL::Exception) { std::ostringstream ret; reprZipStream(ret); @@ -1019,33 +1019,33 @@ void DataArrayDouble::writeVTK(std::ostream& ofs, int indent, const char *nameIn ofs << std::endl << idt << "\n"; } -void DataArrayDouble::reprStream(std::ostream& stream) const +void DataArrayDouble::reprStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) { stream << "Name of double array : \"" << _name << "\"\n"; reprWithoutNameStream(stream); } -void DataArrayDouble::reprZipStream(std::ostream& stream) const +void DataArrayDouble::reprZipStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) { stream << "Name of double array : \"" << _name << "\"\n"; reprZipWithoutNameStream(stream); } -void DataArrayDouble::reprWithoutNameStream(std::ostream& stream) const +void DataArrayDouble::reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) { DataArray::reprWithoutNameStream(stream); stream.precision(17); _mem.repr(getNumberOfComponents(),stream); } -void DataArrayDouble::reprZipWithoutNameStream(std::ostream& stream) const +void DataArrayDouble::reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) { DataArray::reprWithoutNameStream(stream); stream.precision(17); _mem.reprZip(getNumberOfComponents(),stream); } -void DataArrayDouble::reprCppStream(const char *varName, std::ostream& stream) const +void DataArrayDouble::reprCppStream(const char *varName, std::ostream& stream) const throw(INTERP_KERNEL::Exception) { int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents(); const double *data=getConstPointer(); @@ -1072,7 +1072,7 @@ void DataArrayDouble::reprCppStream(const char *varName, std::ostream& stream) c * \param [out] reason In case of inequality returns the reason. * \sa DataArrayDouble::isEqual */ -bool DataArrayDouble::isEqualIfNotWhy(const DataArrayDouble& other, double prec, std::string& reason) const +bool DataArrayDouble::isEqualIfNotWhy(const DataArrayDouble& other, double prec, std::string& reason) const throw(INTERP_KERNEL::Exception) { if(!areInfoEqualsIfNotWhy(other,reason)) return false; @@ -1086,7 +1086,7 @@ bool DataArrayDouble::isEqualIfNotWhy(const DataArrayDouble& other, double prec, * \param [in] prec - precision value to compare numeric data of the arrays. * \return bool - \a true if the two arrays are equal, \a false else. */ -bool DataArrayDouble::isEqual(const DataArrayDouble& other, double prec) const +bool DataArrayDouble::isEqual(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception) { std::string tmp; return isEqualIfNotWhy(other,prec,tmp); @@ -1099,7 +1099,7 @@ bool DataArrayDouble::isEqual(const DataArrayDouble& other, double prec) const * \param [in] prec - precision value to compare numeric data of the arrays. * \return bool - \a true if the values of two arrays are equal, \a false else. */ -bool DataArrayDouble::isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const +bool DataArrayDouble::isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception) { std::string tmp; return _mem.isEqual(other._mem,prec,tmp); @@ -1184,7 +1184,7 @@ DataArrayDouble *DataArrayDouble::toNoInterlace() const throw(INTERP_KERNEL::Exc * \param [in] old2New - C array of length equal to \a this->getNumberOfTuples() * giving a new position for i-th old value. */ -void DataArrayDouble::renumberInPlace(const int *old2New) +void DataArrayDouble::renumberInPlace(const int *old2New) throw(INTERP_KERNEL::Exception) { checkAllocated(); int nbTuples=getNumberOfTuples(); @@ -1208,7 +1208,7 @@ void DataArrayDouble::renumberInPlace(const int *old2New) * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller * is to delete using decrRef() as it is no more needed. */ -void DataArrayDouble::renumberInPlaceR(const int *new2Old) +void DataArrayDouble::renumberInPlaceR(const int *new2Old) throw(INTERP_KERNEL::Exception) { checkAllocated(); int nbTuples=getNumberOfTuples(); @@ -1234,12 +1234,12 @@ void DataArrayDouble::renumberInPlaceR(const int *new2Old) * is to delete using decrRef() as it is no more needed. * \throw If \a this is not allocated. */ -DataArrayDouble *DataArrayDouble::renumber(const int *old2New) const +DataArrayDouble *DataArrayDouble::renumber(const int *old2New) const throw(INTERP_KERNEL::Exception) { checkAllocated(); int nbTuples=getNumberOfTuples(); int nbOfCompo=getNumberOfComponents(); - DataArrayDouble *ret=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); ret->alloc(nbTuples,nbOfCompo); ret->copyStringInfoFrom(*this); const double *iptr=getConstPointer(); @@ -1247,7 +1247,7 @@ DataArrayDouble *DataArrayDouble::renumber(const int *old2New) const for(int i=0;icopyStringInfoFrom(*this); - return ret; + return ret.retn(); } /*! @@ -1261,12 +1261,12 @@ DataArrayDouble *DataArrayDouble::renumber(const int *old2New) const * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller * is to delete using decrRef() as it is no more needed. */ -DataArrayDouble *DataArrayDouble::renumberR(const int *new2Old) const +DataArrayDouble *DataArrayDouble::renumberR(const int *new2Old) const throw(INTERP_KERNEL::Exception) { checkAllocated(); int nbTuples=getNumberOfTuples(); int nbOfCompo=getNumberOfComponents(); - DataArrayDouble *ret=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); ret->alloc(nbTuples,nbOfCompo); ret->copyStringInfoFrom(*this); const double *iptr=getConstPointer(); @@ -1274,7 +1274,7 @@ DataArrayDouble *DataArrayDouble::renumberR(const int *new2Old) const for(int i=0;icopyStringInfoFrom(*this); - return ret; + return ret.retn(); } /*! @@ -1290,12 +1290,12 @@ DataArrayDouble *DataArrayDouble::renumberR(const int *new2Old) const * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller * is to delete using decrRef() as it is no more needed. */ -DataArrayDouble *DataArrayDouble::renumberAndReduce(const int *old2New, int newNbOfTuple) const +DataArrayDouble *DataArrayDouble::renumberAndReduce(const int *old2New, int newNbOfTuple) const throw(INTERP_KERNEL::Exception) { checkAllocated(); int nbTuples=getNumberOfTuples(); int nbOfCompo=getNumberOfComponents(); - DataArrayDouble *ret=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); ret->alloc(newNbOfTuple,nbOfCompo); const double *iptr=getConstPointer(); double *optr=ret->getPointer(); @@ -1306,7 +1306,7 @@ DataArrayDouble *DataArrayDouble::renumberAndReduce(const int *old2New, int newN std::copy(iptr+i*nbOfCompo,iptr+(i+1)*nbOfCompo,optr+w*nbOfCompo); } ret->copyStringInfoFrom(*this); - return ret; + return ret.retn(); } /*! @@ -1530,7 +1530,7 @@ DataArrayDouble *DataArrayDouble::substr(int tupleIdBg, int tupleIdEnd) const th DataArrayDouble *DataArrayDouble::changeNbOfComponents(int newNbOfComp, double dftValue) const throw(INTERP_KERNEL::Exception) { checkAllocated(); - DataArrayDouble *ret=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); ret->alloc(getNumberOfTuples(),newNbOfComp); const double *oldc=getConstPointer(); double *nc=ret->getPointer(); @@ -1549,7 +1549,7 @@ DataArrayDouble *DataArrayDouble::changeNbOfComponents(int newNbOfComp, double d for(int i=0;isetInfoOnComponent(i,getInfoOnComponent(i).c_str()); ret->setName(getName().c_str()); - return ret; + return ret.retn(); } /*! @@ -2599,14 +2599,14 @@ void DataArrayDouble::SetArrayIn(DataArrayDouble *newArray, DataArrayDouble* &ar * \param [in] nbOfTuple - new number of tuples in \a this. * \param [in] nbOfCompo - new number of components in \a this. */ -void DataArrayDouble::useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) +void DataArrayDouble::useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception) { _info_on_compo.resize(nbOfCompo); _mem.useArray(array,ownership,type,nbOfTuple*nbOfCompo); declareAsNew(); } -void DataArrayDouble::useExternalArrayWithRWAccess(const double *array, int nbOfTuple, int nbOfCompo) +void DataArrayDouble::useExternalArrayWithRWAccess(const double *array, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception) { _info_on_compo.resize(nbOfCompo); _mem.useExternalArrayWithRWAccess(array,nbOfTuple*nbOfCompo); @@ -3900,7 +3900,7 @@ void DataArrayDouble::applyFuncFast64(const char *func) throw(INTERP_KERNEL::Exc declareAsNew(); } -DataArrayDoubleIterator *DataArrayDouble::iterator() +DataArrayDoubleIterator *DataArrayDouble::iterator() throw(INTERP_KERNEL::Exception) { return new DataArrayDoubleIterator(this); } @@ -3984,13 +3984,13 @@ DataArrayDouble *DataArrayDouble::Aggregate(const std::vectorgetNumberOfTuples(); } - DataArrayDouble *ret=DataArrayDouble::New(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); ret->alloc(nbt,nbOfComp); double *pt=ret->getPointer(); for(it=a.begin();it!=a.end();it++) pt=std::copy((*it)->getConstPointer(),(*it)->getConstPointer()+(*it)->getNbOfElems(),pt); ret->copyStringInfoFrom(*(a[0])); - return ret; + return ret.retn(); } /*! @@ -4917,7 +4917,7 @@ DataArrayDoubleIterator::~DataArrayDoubleIterator() _da->decrRef(); } -DataArrayDoubleTuple *DataArrayDoubleIterator::nextt() +DataArrayDoubleTuple *DataArrayDoubleIterator::nextt() throw(INTERP_KERNEL::Exception) { if(_tuple_id<_nb_tuple) { @@ -4935,7 +4935,7 @@ DataArrayDoubleTuple::DataArrayDoubleTuple(double *pt, int nbOfComp):_pt(pt),_nb } -std::string DataArrayDoubleTuple::repr() const +std::string DataArrayDoubleTuple::repr() const throw(INTERP_KERNEL::Exception) { std::ostringstream oss; oss.precision(17); oss << "("; for(int i=0;i<_nb_of_compo-1;i++) @@ -4987,7 +4987,7 @@ DataArrayInt *DataArrayInt::New() * in \ref MEDCouplingArrayBasicsTuplesAndCompo "DataArrays infos" for more information. * \return bool - \a true if the raw data is allocated, \a false else. */ -bool DataArrayInt::isAllocated() const +bool DataArrayInt::isAllocated() const throw(INTERP_KERNEL::Exception) { return getConstPointer()!=0; } @@ -5093,7 +5093,7 @@ bool DataArrayInt::empty() const throw(INTERP_KERNEL::Exception) * \ref MEDCouplingArrayBasicsCopyDeep. * \return DataArrayInt * - a new instance of DataArrayInt. */ -DataArrayInt *DataArrayInt::deepCpy() const +DataArrayInt *DataArrayInt::deepCpy() const throw(INTERP_KERNEL::Exception) { return new DataArrayInt(*this); } @@ -5105,7 +5105,7 @@ DataArrayInt *DataArrayInt::deepCpy() const * \return DataArrayInt * - either a new instance of DataArrayInt (if \a dCpy * == \a true) or \a this instance (if \a dCpy == \a false). */ -DataArrayInt *DataArrayInt::performCpy(bool dCpy) const +DataArrayInt *DataArrayInt::performCpy(bool dCpy) const throw(INTERP_KERNEL::Exception) { if(dCpy) return deepCpy(); @@ -5236,7 +5236,7 @@ void DataArrayInt::pack() const throw(INTERP_KERNEL::Exception) * \param [in] nbOfCompo - number of components of data to allocate. * \throw If \a nbOfTuple < 0 or \a nbOfCompo < 0. */ -void DataArrayInt::allocIfNecessary(int nbOfTuple, int nbOfCompo) +void DataArrayInt::allocIfNecessary(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception) { if(isAllocated()) { @@ -5313,14 +5313,14 @@ void DataArrayInt::iota(int init) throw(INTERP_KERNEL::Exception) * DataArrayInt. This text is shown when a DataArrayInt is printed in Python. * \return std::string - text describing \a this DataArrayInt. */ -std::string DataArrayInt::repr() const +std::string DataArrayInt::repr() const throw(INTERP_KERNEL::Exception) { std::ostringstream ret; reprStream(ret); return ret.str(); } -std::string DataArrayInt::reprZip() const +std::string DataArrayInt::reprZip() const throw(INTERP_KERNEL::Exception) { std::ostringstream ret; reprZipStream(ret); @@ -5337,31 +5337,31 @@ void DataArrayInt::writeVTK(std::ostream& ofs, int indent, const char *type, con ofs << std::endl << idt << "\n"; } -void DataArrayInt::reprStream(std::ostream& stream) const +void DataArrayInt::reprStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) { stream << "Name of int array : \"" << _name << "\"\n"; reprWithoutNameStream(stream); } -void DataArrayInt::reprZipStream(std::ostream& stream) const +void DataArrayInt::reprZipStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) { stream << "Name of int array : \"" << _name << "\"\n"; reprZipWithoutNameStream(stream); } -void DataArrayInt::reprWithoutNameStream(std::ostream& stream) const +void DataArrayInt::reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) { DataArray::reprWithoutNameStream(stream); _mem.repr(getNumberOfComponents(),stream); } -void DataArrayInt::reprZipWithoutNameStream(std::ostream& stream) const +void DataArrayInt::reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) { DataArray::reprWithoutNameStream(stream); _mem.reprZip(getNumberOfComponents(),stream); } -void DataArrayInt::reprCppStream(const char *varName, std::ostream& stream) const +void DataArrayInt::reprCppStream(const char *varName, std::ostream& stream) const throw(INTERP_KERNEL::Exception) { int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents(); const int *data=getConstPointer(); @@ -5633,7 +5633,7 @@ DataArrayInt *DataArrayInt::invertArrayN2O2O2N(int oldNbOfElem) const * \param [out] reason In case of inequality returns the reason. * \sa DataArrayInt::isEqual */ -bool DataArrayInt::isEqualIfNotWhy(const DataArrayInt& other, std::string& reason) const +bool DataArrayInt::isEqualIfNotWhy(const DataArrayInt& other, std::string& reason) const throw(INTERP_KERNEL::Exception) { if(!areInfoEqualsIfNotWhy(other,reason)) return false; @@ -5646,7 +5646,7 @@ bool DataArrayInt::isEqualIfNotWhy(const DataArrayInt& other, std::string& reaso * \param [in] other - an instance of DataArrayInt to compare with \a this one. * \return bool - \a true if the two arrays are equal, \a false else. */ -bool DataArrayInt::isEqual(const DataArrayInt& other) const +bool DataArrayInt::isEqual(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception) { std::string tmp; return isEqualIfNotWhy(other,tmp); @@ -5658,7 +5658,7 @@ bool DataArrayInt::isEqual(const DataArrayInt& other) const * \param [in] other - an instance of DataArrayInt to compare with \a this one. * \return bool - \a true if the values of two arrays are equal, \a false else. */ -bool DataArrayInt::isEqualWithoutConsideringStr(const DataArrayInt& other) const +bool DataArrayInt::isEqualWithoutConsideringStr(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception) { std::string tmp; return _mem.isEqual(other._mem,0,tmp); @@ -5879,14 +5879,14 @@ DataArrayInt *DataArrayInt::buildPermutationArr(const DataArrayInt& other) const * \param [in] nbOfTuple - new number of tuples in \a this. * \param [in] nbOfCompo - new number of components in \a this. */ -void DataArrayInt::useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) +void DataArrayInt::useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception) { _info_on_compo.resize(nbOfCompo); _mem.useArray(array,ownership,type,nbOfTuple*nbOfCompo); declareAsNew(); } -void DataArrayInt::useExternalArrayWithRWAccess(const int *array, int nbOfTuple, int nbOfCompo) +void DataArrayInt::useExternalArrayWithRWAccess(const int *array, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception) { _info_on_compo.resize(nbOfCompo); _mem.useExternalArrayWithRWAccess(array,nbOfTuple*nbOfCompo); @@ -5944,7 +5944,7 @@ DataArrayInt *DataArrayInt::toNoInterlace() const throw(INTERP_KERNEL::Exception * \param [in] old2New - C array of length equal to \a this->getNumberOfTuples() * giving a new position for i-th old value. */ -void DataArrayInt::renumberInPlace(const int *old2New) +void DataArrayInt::renumberInPlace(const int *old2New) throw(INTERP_KERNEL::Exception) { checkAllocated(); int nbTuples=getNumberOfTuples(); @@ -5968,7 +5968,7 @@ void DataArrayInt::renumberInPlace(const int *old2New) * \return DataArrayInt * - the new instance of DataArrayInt that the caller * is to delete using decrRef() as it is no more needed. */ -void DataArrayInt::renumberInPlaceR(const int *new2Old) +void DataArrayInt::renumberInPlaceR(const int *new2Old) throw(INTERP_KERNEL::Exception) { checkAllocated(); int nbTuples=getNumberOfTuples(); @@ -5994,12 +5994,12 @@ void DataArrayInt::renumberInPlaceR(const int *new2Old) * is to delete using decrRef() as it is no more needed. * \throw If \a this is not allocated. */ -DataArrayInt *DataArrayInt::renumber(const int *old2New) const +DataArrayInt *DataArrayInt::renumber(const int *old2New) const throw(INTERP_KERNEL::Exception) { checkAllocated(); int nbTuples=getNumberOfTuples(); int nbOfCompo=getNumberOfComponents(); - DataArrayInt *ret=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(nbTuples,nbOfCompo); ret->copyStringInfoFrom(*this); const int *iptr=getConstPointer(); @@ -6007,7 +6007,7 @@ DataArrayInt *DataArrayInt::renumber(const int *old2New) const for(int i=0;icopyStringInfoFrom(*this); - return ret; + return ret.retn(); } /*! @@ -6021,12 +6021,12 @@ DataArrayInt *DataArrayInt::renumber(const int *old2New) const * \return DataArrayInt * - the new instance of DataArrayInt that the caller * is to delete using decrRef() as it is no more needed. */ -DataArrayInt *DataArrayInt::renumberR(const int *new2Old) const +DataArrayInt *DataArrayInt::renumberR(const int *new2Old) const throw(INTERP_KERNEL::Exception) { checkAllocated(); int nbTuples=getNumberOfTuples(); int nbOfCompo=getNumberOfComponents(); - DataArrayInt *ret=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(nbTuples,nbOfCompo); ret->copyStringInfoFrom(*this); const int *iptr=getConstPointer(); @@ -6034,7 +6034,7 @@ DataArrayInt *DataArrayInt::renumberR(const int *new2Old) const for(int i=0;icopyStringInfoFrom(*this); - return ret; + return ret.retn(); } /*! @@ -6050,12 +6050,12 @@ DataArrayInt *DataArrayInt::renumberR(const int *new2Old) const * \return DataArrayInt * - the new instance of DataArrayInt that the caller * is to delete using decrRef() as it is no more needed. */ -DataArrayInt *DataArrayInt::renumberAndReduce(const int *old2New, int newNbOfTuple) const +DataArrayInt *DataArrayInt::renumberAndReduce(const int *old2New, int newNbOfTuple) const throw(INTERP_KERNEL::Exception) { checkAllocated(); int nbTuples=getNumberOfTuples(); int nbOfCompo=getNumberOfComponents(); - DataArrayInt *ret=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(newNbOfTuple,nbOfCompo); const int *iptr=getConstPointer(); int *optr=ret->getPointer(); @@ -6066,7 +6066,7 @@ DataArrayInt *DataArrayInt::renumberAndReduce(const int *old2New, int newNbOfTup std::copy(iptr+i*nbOfCompo,iptr+(i+1)*nbOfCompo,optr+w*nbOfCompo); } ret->copyStringInfoFrom(*this); - return ret; + return ret.retn(); } /*! @@ -6603,7 +6603,7 @@ void DataArrayInt::transpose() throw(INTERP_KERNEL::Exception) DataArrayInt *DataArrayInt::changeNbOfComponents(int newNbOfComp, int dftValue) const throw(INTERP_KERNEL::Exception) { checkAllocated(); - DataArrayInt *ret=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(getNumberOfTuples(),newNbOfComp); const int *oldc=getConstPointer(); int *nc=ret->getPointer(); @@ -6622,7 +6622,7 @@ DataArrayInt *DataArrayInt::changeNbOfComponents(int newNbOfComp, int dftValue) for(int i=0;isetInfoOnComponent(i,getInfoOnComponent(i).c_str()); ret->setName(getName().c_str()); - return ret; + return ret.retn(); } /*! @@ -7401,7 +7401,7 @@ void DataArrayInt::SetArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet) } } -DataArrayIntIterator *DataArrayInt::iterator() +DataArrayIntIterator *DataArrayInt::iterator() throw(INTERP_KERNEL::Exception) { return new DataArrayIntIterator(this); } @@ -7763,13 +7763,13 @@ DataArrayInt *DataArrayInt::Aggregate(const std::vector& a throw INTERP_KERNEL::Exception("DataArrayInt::Aggregate : Nb of components mismatch for array aggregation !"); nbt+=(*it)->getNumberOfTuples(); } - DataArrayInt *ret=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(nbt,nbOfComp); int *pt=ret->getPointer(); for(it=a.begin();it!=a.end();it++) pt=std::copy((*it)->getConstPointer(),(*it)->getConstPointer()+(*it)->getNbOfElems(),pt); ret->copyStringInfoFrom(*(a[0])); - return ret; + return ret.retn(); } /*! @@ -9688,7 +9688,7 @@ DataArrayIntIterator::~DataArrayIntIterator() _da->decrRef(); } -DataArrayIntTuple *DataArrayIntIterator::nextt() +DataArrayIntTuple *DataArrayIntIterator::nextt() throw(INTERP_KERNEL::Exception) { if(_tuple_id<_nb_tuple) { @@ -9705,7 +9705,7 @@ DataArrayIntTuple::DataArrayIntTuple(int *pt, int nbOfComp):_pt(pt),_nb_of_compo { } -std::string DataArrayIntTuple::repr() const +std::string DataArrayIntTuple::repr() const throw(INTERP_KERNEL::Exception) { std::ostringstream oss; oss << "("; for(int i=0;i<_nb_of_compo-1;i++) diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index def5aac44..4a65a62c6 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -105,23 +105,22 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void copyStringInfoFrom(const DataArray& other) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void copyPartOfStringInfoFrom(const DataArray& other, const std::vector& compoIds) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void copyPartOfStringInfoFrom2(const std::vector& compoIds, const DataArray& other) throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT bool areInfoEqualsIfNotWhy(const DataArray& other, std::string& reason) const; - MEDCOUPLING_EXPORT bool areInfoEquals(const DataArray& other) const; - MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const; + MEDCOUPLING_EXPORT bool areInfoEqualsIfNotWhy(const DataArray& other, std::string& reason) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT bool areInfoEquals(const DataArray& other) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::string cppRepr(const char *varName) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::string getName() const { return _name; } MEDCOUPLING_EXPORT const std::vector &getInfoOnComponents() const { return _info_on_compo; } MEDCOUPLING_EXPORT std::vector &getInfoOnComponents() { return _info_on_compo; } MEDCOUPLING_EXPORT void setInfoOnComponents(const std::vector& info) throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT std::vector getVarsOnComponent() const; - MEDCOUPLING_EXPORT std::vector getUnitsOnComponent() const; + MEDCOUPLING_EXPORT std::vector getVarsOnComponent() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT std::vector getUnitsOnComponent() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::string getInfoOnComponent(int i) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::string getVarOnComponent(int i) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::string getUnitOnComponent(int i) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getNumberOfComponents() const { return (int)_info_on_compo.size(); } - MEDCOUPLING_EXPORT virtual int getNumberOfTuples() const = 0; - MEDCOUPLING_EXPORT virtual int getNbOfElems() const = 0; + MEDCOUPLING_EXPORT virtual int getNumberOfTuples() const throw(INTERP_KERNEL::Exception) = 0; + MEDCOUPLING_EXPORT virtual int getNbOfElems() const throw(INTERP_KERNEL::Exception) = 0; MEDCOUPLING_EXPORT void checkNbOfTuples(int nbOfTuples, const char *msg) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkNbOfComps(int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkNbOfTuplesAndComp(const DataArray& other, const char *msg) const throw(INTERP_KERNEL::Exception); @@ -132,7 +131,11 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT static int GetPosOfItemGivenBESRelativeNoThrow(int value, int begin, int end, int step) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static std::string GetVarNameFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static std::string GetUnitFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT virtual void reprCppStream(const char *varName, std::ostream& stream) const = 0; + MEDCOUPLING_EXPORT virtual void reprStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) = 0; + MEDCOUPLING_EXPORT virtual void reprZipStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) = 0; + MEDCOUPLING_EXPORT virtual void reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT virtual void reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) = 0; + MEDCOUPLING_EXPORT virtual void reprCppStream(const char *varName, std::ostream& stream) const throw(INTERP_KERNEL::Exception) = 0; protected: DataArray() { } protected: @@ -155,25 +158,25 @@ namespace ParaMEDMEM { public: MEDCOUPLING_EXPORT static DataArrayDouble *New(); - MEDCOUPLING_EXPORT bool isAllocated() const; + MEDCOUPLING_EXPORT bool isAllocated() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkAllocated() const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT int getNumberOfTuples() const { return _info_on_compo.empty()?0:_mem.getNbOfElem()/getNumberOfComponents(); } - MEDCOUPLING_EXPORT int getNbOfElems() const { return _mem.getNbOfElem(); } + MEDCOUPLING_EXPORT int getNumberOfTuples() const throw(INTERP_KERNEL::Exception) { return _info_on_compo.empty()?0:_mem.getNbOfElem()/getNumberOfComponents(); } + MEDCOUPLING_EXPORT int getNbOfElems() const throw(INTERP_KERNEL::Exception) { return _mem.getNbOfElem(); } MEDCOUPLING_EXPORT std::size_t getHeapMemorySize() const; MEDCOUPLING_EXPORT void setInfoAndChangeNbOfCompo(const std::vector& info) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double doubleValue() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool empty() const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT DataArrayDouble *deepCpy() const; - MEDCOUPLING_EXPORT DataArrayDouble *performCpy(bool deepCpy) const; + MEDCOUPLING_EXPORT DataArrayDouble *deepCpy() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayDouble *performCpy(bool deepCpy) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void cpyFrom(const DataArrayDouble& other) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reserve(int nbOfElems) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void pushBackSilent(double val) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void pushBackValsSilent(const double *valsBg, const double *valsEnd) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double popBackSilent() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void pack() const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT int getNbOfElemAllocated() const { return _mem.getNbOfElemAllocated(); } + MEDCOUPLING_EXPORT int getNbOfElemAllocated() const throw(INTERP_KERNEL::Exception) { return _mem.getNbOfElemAllocated(); } MEDCOUPLING_EXPORT void alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void allocIfNecessary(int nbOfTuple, int nbOfCompo); + MEDCOUPLING_EXPORT void allocIfNecessary(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void fillWithZero() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void fillWithValue(double val) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void iota(double init=0.) throw(INTERP_KERNEL::Exception); @@ -182,26 +185,26 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void reverse() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT std::string repr() const; - MEDCOUPLING_EXPORT std::string reprZip() const; + MEDCOUPLING_EXPORT std::string repr() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT std::string reprZip() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const char *nameInFile) const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprCppStream(const char *varName, std::ostream& stream) const; - MEDCOUPLING_EXPORT bool isEqual(const DataArrayDouble& other, double prec) const; - MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayDouble& other, double prec, std::string& reason) const; - MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const; + MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprCppStream(const char *varName, std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT bool isEqual(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayDouble& other, double prec, std::string& reason) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *convertToIntArr() const; MEDCOUPLING_EXPORT DataArrayDouble *fromNoInterlace() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayDouble *toNoInterlace() const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void renumberInPlace(const int *old2New); - MEDCOUPLING_EXPORT void renumberInPlaceR(const int *new2Old); - MEDCOUPLING_EXPORT DataArrayDouble *renumber(const int *old2New) const; - MEDCOUPLING_EXPORT DataArrayDouble *renumberR(const int *new2Old) const; - MEDCOUPLING_EXPORT DataArrayDouble *renumberAndReduce(const int *old2New, int newNbOfTuple) const; + MEDCOUPLING_EXPORT void renumberInPlace(const int *old2New) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void renumberInPlaceR(const int *new2Old) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayDouble *renumber(const int *old2New) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayDouble *renumberR(const int *new2Old) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayDouble *renumberAndReduce(const int *old2New, int newNbOfTuple) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const; MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception); @@ -229,20 +232,20 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void setPartOfValuesAdv(const DataArrayDouble *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setContigPartOfSelectedValues(int tupleIdStart, const DataArrayDouble *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setContigPartOfSelectedValues2(int tupleIdStart, const DataArrayDouble *a, int bg, int end2, int step) throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void getTuple(int tupleId, double *res) const { std::copy(_mem.getConstPointerLoc(tupleId*((int)_info_on_compo.size())),_mem.getConstPointerLoc((tupleId+1)*((int)_info_on_compo.size())),res); } + MEDCOUPLING_EXPORT void getTuple(int tupleId, double *res) const throw(INTERP_KERNEL::Exception) { std::copy(_mem.getConstPointerLoc(tupleId*((int)_info_on_compo.size())),_mem.getConstPointerLoc((tupleId+1)*((int)_info_on_compo.size())),res); } MEDCOUPLING_EXPORT double getIJ(int tupleId, int compoId) const { return _mem[tupleId*((int)_info_on_compo.size())+compoId]; } MEDCOUPLING_EXPORT double back() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void setIJ(int tupleId, int compoId, double newVal) { _mem[tupleId*((int)_info_on_compo.size())+compoId]=newVal; declareAsNew(); } - MEDCOUPLING_EXPORT void setIJSilent(int tupleId, int compoId, double newVal) { _mem[tupleId*((int)_info_on_compo.size())+compoId]=newVal; } - MEDCOUPLING_EXPORT double *getPointer() { return _mem.getPointer(); } + MEDCOUPLING_EXPORT void setIJ(int tupleId, int compoId, double newVal) throw(INTERP_KERNEL::Exception) { _mem[tupleId*((int)_info_on_compo.size())+compoId]=newVal; declareAsNew(); } + MEDCOUPLING_EXPORT void setIJSilent(int tupleId, int compoId, double newVal) throw(INTERP_KERNEL::Exception) { _mem[tupleId*((int)_info_on_compo.size())+compoId]=newVal; } + MEDCOUPLING_EXPORT double *getPointer() throw(INTERP_KERNEL::Exception) { return _mem.getPointer(); } MEDCOUPLING_EXPORT static void SetArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet); - MEDCOUPLING_EXPORT const double *getConstPointer() const { return _mem.getConstPointer(); } - MEDCOUPLING_EXPORT DataArrayDoubleIterator *iterator(); - MEDCOUPLING_EXPORT const double *begin() const { return getConstPointer(); } - MEDCOUPLING_EXPORT const double *end() const { return getConstPointer()+getNbOfElems(); } - MEDCOUPLING_EXPORT void useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo); - MEDCOUPLING_EXPORT void useExternalArrayWithRWAccess(const double *array, int nbOfTuple, int nbOfCompo); + MEDCOUPLING_EXPORT const double *getConstPointer() const throw(INTERP_KERNEL::Exception) { return _mem.getConstPointer(); } + MEDCOUPLING_EXPORT DataArrayDoubleIterator *iterator() throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT const double *begin() const throw(INTERP_KERNEL::Exception) { return getConstPointer(); } + MEDCOUPLING_EXPORT const double *end() const throw(INTERP_KERNEL::Exception) { return getConstPointer()+getNbOfElems(); } + MEDCOUPLING_EXPORT void useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void useExternalArrayWithRWAccess(const double *array, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); template void insertAtTheEnd(InputIterator first, InputIterator last) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void writeOnPlace(int id, double element0, const double *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } @@ -334,7 +337,7 @@ namespace ParaMEDMEM public: DataArrayDoubleIterator(DataArrayDouble *da); ~DataArrayDoubleIterator(); - DataArrayDoubleTuple *nextt(); + DataArrayDoubleTuple *nextt() throw(INTERP_KERNEL::Exception); private: DataArrayDouble *_da; double *_pt; @@ -347,7 +350,7 @@ namespace ParaMEDMEM { public: DataArrayDoubleTuple(double *pt, int nbOfComp); - std::string repr() const; + std::string repr() const throw(INTERP_KERNEL::Exception); int getNumberOfCompo() const { return _nb_of_compo; } const double *getConstPointer() const { return _pt; } double *getPointer() { return _pt; } @@ -364,29 +367,29 @@ namespace ParaMEDMEM { public: MEDCOUPLING_EXPORT static DataArrayInt *New(); - MEDCOUPLING_EXPORT bool isAllocated() const; + MEDCOUPLING_EXPORT bool isAllocated() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkAllocated() const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT int getNumberOfTuples() const { return _info_on_compo.empty()?0:_mem.getNbOfElem()/getNumberOfComponents(); } - MEDCOUPLING_EXPORT int getNbOfElems() const { return _mem.getNbOfElem(); } + MEDCOUPLING_EXPORT int getNumberOfTuples() const throw(INTERP_KERNEL::Exception) { return _info_on_compo.empty()?0:_mem.getNbOfElem()/getNumberOfComponents(); } + MEDCOUPLING_EXPORT int getNbOfElems() const throw(INTERP_KERNEL::Exception) { return _mem.getNbOfElem(); } MEDCOUPLING_EXPORT std::size_t getHeapMemorySize() const; MEDCOUPLING_EXPORT void setInfoAndChangeNbOfCompo(const std::vector& info) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int intValue() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getHashCode() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool empty() const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT DataArrayInt *deepCpy() const; - MEDCOUPLING_EXPORT DataArrayInt *performCpy(bool deepCpy) const; + MEDCOUPLING_EXPORT DataArrayInt *deepCpy() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *performCpy(bool deepCpy) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void cpyFrom(const DataArrayInt& other) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reserve(int nbOfElems) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void pushBackSilent(int val) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void pushBackValsSilent(const int *valsBg, const int *valsEnd) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int popBackSilent() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void pack() const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT int getNbOfElemAllocated() const { return _mem.getNbOfElemAllocated(); } + MEDCOUPLING_EXPORT int getNbOfElemAllocated() const throw(INTERP_KERNEL::Exception) { return _mem.getNbOfElemAllocated(); } MEDCOUPLING_EXPORT void alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void allocIfNecessary(int nbOfTuple, int nbOfCompo); - MEDCOUPLING_EXPORT bool isEqual(const DataArrayInt& other) const; - MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayInt& other, std::string& reason) const; - MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayInt& other) const; + MEDCOUPLING_EXPORT void allocIfNecessary(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT bool isEqual(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayInt& other, std::string& reason) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStrAndOrder(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *buildPermutationArr(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void sort(bool asc=true) throw(INTERP_KERNEL::Exception); @@ -398,14 +401,14 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void fillWithZero() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void fillWithValue(int val) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void iota(int init=0) throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT std::string repr() const; - MEDCOUPLING_EXPORT std::string reprZip() const; + MEDCOUPLING_EXPORT std::string repr() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT std::string reprZip() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const char *type, const char *nameInFile) const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprCppStream(const char *varName, std::ostream& stream) const; + MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprCppStream(const char *varName, std::ostream& stream) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void transformWithIndArr(const int *indArrBg, const int *indArrEnd) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *transformWithIndArrR(const int *indArrBg, const int *indArrEnd) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void splitByValueRange(const int *arrBg, const int *arrEnd, @@ -417,11 +420,11 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayDouble *convertToDblArr() const; MEDCOUPLING_EXPORT DataArrayInt *fromNoInterlace() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *toNoInterlace() const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void renumberInPlace(const int *old2New); - MEDCOUPLING_EXPORT void renumberInPlaceR(const int *new2Old); - MEDCOUPLING_EXPORT DataArrayInt *renumber(const int *old2New) const; - MEDCOUPLING_EXPORT DataArrayInt *renumberR(const int *new2Old) const; - MEDCOUPLING_EXPORT DataArrayInt *renumberAndReduce(const int *old2NewBg, int newNbOfTuple) const; + MEDCOUPLING_EXPORT void renumberInPlace(const int *old2New) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void renumberInPlaceR(const int *new2Old) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *renumber(const int *old2New) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *renumberR(const int *new2Old) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *renumberAndReduce(const int *old2NewBg, int newNbOfTuple) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const; MEDCOUPLING_EXPORT DataArrayInt *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *selectByTupleId2(int bg, int end, int step) const throw(INTERP_KERNEL::Exception); @@ -450,18 +453,18 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void setPartOfValuesAdv(const DataArrayInt *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setContigPartOfSelectedValues(int tupleIdStart, const DataArrayInt*a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setContigPartOfSelectedValues2(int tupleIdStart, const DataArrayInt *a, int bg, int end2, int step) throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void getTuple(int tupleId, int *res) const { std::copy(_mem.getConstPointerLoc(tupleId*((int)_info_on_compo.size())),_mem.getConstPointerLoc((tupleId+1)*((int)_info_on_compo.size())),res); } - MEDCOUPLING_EXPORT int getIJ(int tupleId, int compoId) const { return _mem[tupleId*((int)_info_on_compo.size())+compoId]; } + MEDCOUPLING_EXPORT void getTuple(int tupleId, int *res) const throw(INTERP_KERNEL::Exception) { std::copy(_mem.getConstPointerLoc(tupleId*((int)_info_on_compo.size())),_mem.getConstPointerLoc((tupleId+1)*((int)_info_on_compo.size())),res); } + MEDCOUPLING_EXPORT int getIJ(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception) { return _mem[tupleId*((int)_info_on_compo.size())+compoId]; } MEDCOUPLING_EXPORT int getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int back() const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void setIJ(int tupleId, int compoId, int newVal) { _mem[tupleId*((int)_info_on_compo.size())+compoId]=newVal; declareAsNew(); } - MEDCOUPLING_EXPORT void setIJSilent(int tupleId, int compoId, int newVal) { _mem[tupleId*((int)_info_on_compo.size())+compoId]=newVal; } - MEDCOUPLING_EXPORT int *getPointer() { return _mem.getPointer(); } + MEDCOUPLING_EXPORT void setIJ(int tupleId, int compoId, int newVal) throw(INTERP_KERNEL::Exception) { _mem[tupleId*((int)_info_on_compo.size())+compoId]=newVal; declareAsNew(); } + MEDCOUPLING_EXPORT void setIJSilent(int tupleId, int compoId, int newVal) throw(INTERP_KERNEL::Exception) { _mem[tupleId*((int)_info_on_compo.size())+compoId]=newVal; } + MEDCOUPLING_EXPORT int *getPointer() throw(INTERP_KERNEL::Exception) { return _mem.getPointer(); } MEDCOUPLING_EXPORT static void SetArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet); - MEDCOUPLING_EXPORT const int *getConstPointer() const { return _mem.getConstPointer(); } - MEDCOUPLING_EXPORT DataArrayIntIterator *iterator(); - MEDCOUPLING_EXPORT const int *begin() const { return getConstPointer(); } - MEDCOUPLING_EXPORT const int *end() const { return getConstPointer()+getNbOfElems(); } + MEDCOUPLING_EXPORT const int *getConstPointer() const throw(INTERP_KERNEL::Exception) { return _mem.getConstPointer(); } + MEDCOUPLING_EXPORT DataArrayIntIterator *iterator() throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT const int *begin() const throw(INTERP_KERNEL::Exception) { return getConstPointer(); } + MEDCOUPLING_EXPORT const int *end() const throw(INTERP_KERNEL::Exception) { return getConstPointer()+getNbOfElems(); } MEDCOUPLING_EXPORT DataArrayInt *getIdsEqual(int val) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *getIdsNotEqual(int val) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *getIdsEqualList(const int *valsBg, const int *valsEnd) const throw(INTERP_KERNEL::Exception); @@ -511,8 +514,8 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *duplicateEachTupleNTimes(int nbTimes) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *getDifferentValues() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::vector partitionByDifferentValues(std::vector& differentIds) const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo); - MEDCOUPLING_EXPORT void useExternalArrayWithRWAccess(const int *array, int nbOfTuple, int nbOfCompo); + MEDCOUPLING_EXPORT void useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void useExternalArrayWithRWAccess(const int *array, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); template void insertAtTheEnd(InputIterator first, InputIterator last) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void writeOnPlace(int id, int element0, const int *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } @@ -548,7 +551,7 @@ namespace ParaMEDMEM public: DataArrayIntIterator(DataArrayInt *da); ~DataArrayIntIterator(); - DataArrayIntTuple *nextt(); + DataArrayIntTuple *nextt() throw(INTERP_KERNEL::Exception); private: DataArrayInt *_da; int *_pt; @@ -561,7 +564,7 @@ namespace ParaMEDMEM { public: DataArrayIntTuple(int *pt, int nbOfComp); - std::string repr() const; + std::string repr() const throw(INTERP_KERNEL::Exception); int getNumberOfCompo() const { return _nb_of_compo; } const int *getConstPointer() const { return _pt; } int *getPointer() { return _pt; } @@ -572,51 +575,41 @@ namespace ParaMEDMEM int _nb_of_compo; }; - class DataArrayCharIterator; - class DataArrayChar : public DataArray { public: - MEDCOUPLING_EXPORT static DataArrayChar *New(); - MEDCOUPLING_EXPORT bool isAllocated() const; + MEDCOUPLING_EXPORT virtual DataArrayChar *buildEmptySpecializedDAChar() const throw(INTERP_KERNEL::Exception) = 0; + MEDCOUPLING_EXPORT bool isAllocated() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkAllocated() const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT int getNumberOfTuples() const { return _info_on_compo.empty()?0:_mem.getNbOfElem()/getNumberOfComponents(); } - MEDCOUPLING_EXPORT int getNbOfElems() const { return _mem.getNbOfElem(); } + MEDCOUPLING_EXPORT int getNumberOfTuples() const throw(INTERP_KERNEL::Exception) { return _info_on_compo.empty()?0:_mem.getNbOfElem()/getNumberOfComponents(); } + MEDCOUPLING_EXPORT int getNbOfElems() const throw(INTERP_KERNEL::Exception) { return _mem.getNbOfElem(); } MEDCOUPLING_EXPORT std::size_t getHeapMemorySize() const; MEDCOUPLING_EXPORT void setInfoAndChangeNbOfCompo(const std::vector& info) throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT char charValue() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getHashCode() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool empty() const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT DataArrayChar *deepCpy() const; - MEDCOUPLING_EXPORT DataArrayChar *performCpy(bool deepCpy) const; MEDCOUPLING_EXPORT void cpyFrom(const DataArrayChar& other) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reserve(int nbOfElems) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void pushBackSilent(char val) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void pushBackValsSilent(const char *valsBg, const char *valsEnd) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT char popBackSilent() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void pack() const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT int getNbOfElemAllocated() const { return _mem.getNbOfElemAllocated(); } + MEDCOUPLING_EXPORT int getNbOfElemAllocated() const throw(INTERP_KERNEL::Exception) { return _mem.getNbOfElemAllocated(); } MEDCOUPLING_EXPORT void alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void allocIfNecessary(int nbOfTuple, int nbOfCompo); - MEDCOUPLING_EXPORT bool isEqual(const DataArrayChar& other) const; - MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const; - MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayChar& other) const; + MEDCOUPLING_EXPORT void allocIfNecessary(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT bool isEqual(const DataArrayChar& other) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT virtual bool isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayChar& other) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void fillWithZero() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void fillWithValue(char val) throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT std::string repr() const; - MEDCOUPLING_EXPORT std::string reprZip() const; - MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprCppStream(const char *varName, std::ostream& stream) const; + MEDCOUPLING_EXPORT std::string repr() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT std::string reprZip() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT DataArrayInt *convertToIntArr() const; - MEDCOUPLING_EXPORT void renumberInPlace(const int *old2New); - MEDCOUPLING_EXPORT void renumberInPlaceR(const int *new2Old); - MEDCOUPLING_EXPORT DataArrayChar *renumber(const int *old2New) const; - MEDCOUPLING_EXPORT DataArrayChar *renumberR(const int *new2Old) const; - MEDCOUPLING_EXPORT DataArrayChar *renumberAndReduce(const int *old2NewBg, int newNbOfTuple) const; + MEDCOUPLING_EXPORT DataArrayInt *convertToIntArr() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void renumberInPlace(const int *old2New) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void renumberInPlaceR(const int *new2Old) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayChar *renumber(const int *old2New) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayChar *renumberR(const int *new2Old) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayChar *renumberAndReduce(const int *old2NewBg, int newNbOfTuple) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayChar *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayChar *selectByTupleId2(int bg, int end, int step) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isUniform(char val) const throw(INTERP_KERNEL::Exception); @@ -641,15 +634,15 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void setIJSilent(int tupleId, int compoId, char newVal) { _mem[tupleId*((int)_info_on_compo.size())+compoId]=newVal; } MEDCOUPLING_EXPORT char *getPointer() { return _mem.getPointer(); } MEDCOUPLING_EXPORT const char *getConstPointer() const { return _mem.getConstPointer(); } - MEDCOUPLING_EXPORT DataArrayCharIterator *iterator(); - MEDCOUPLING_EXPORT const char *begin() const { return getConstPointer(); } - MEDCOUPLING_EXPORT const char *end() const { return getConstPointer()+getNbOfElems(); } + MEDCOUPLING_EXPORT const char *begin() const throw(INTERP_KERNEL::Exception) { return getConstPointer(); } + MEDCOUPLING_EXPORT const char *end() const throw(INTERP_KERNEL::Exception) { return getConstPointer()+getNbOfElems(); } MEDCOUPLING_EXPORT DataArrayInt *getIdsEqual(char val) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *getIdsNotEqual(char val) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int search(const std::vector& vals) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int locateTuple(const std::vector& tupl) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int locateValue(char value) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int locateValue(const std::vector& vals) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT bool presenceOfTuple(const std::vector& tupl) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool presenceOfValue(char value) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool presenceOfValue(const std::vector& vals) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT char getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception); @@ -661,46 +654,119 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT static DataArrayChar *Aggregate(const std::vector& arr) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static DataArrayChar *Meld(const DataArrayChar *a1, const DataArrayChar *a2) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static DataArrayChar *Meld(const std::vector& arr) throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void useArray(const char *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo); - MEDCOUPLING_EXPORT void useExternalArrayWithRWAccess(const char *array, int nbOfTuple, int nbOfCompo); + MEDCOUPLING_EXPORT void useArray(const char *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void useExternalArrayWithRWAccess(const char *array, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void updateTime() const { } public: //MEDCOUPLING_EXPORT void getTinySerializationIntInformation(std::vector& tinyInfo) const; //MEDCOUPLING_EXPORT void getTinySerializationStrInformation(std::vector& tinyInfo) const; //MEDCOUPLING_EXPORT bool resizeForUnserialization(const std::vector& tinyInfoI); //MEDCOUPLING_EXPORT void finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoS); - private: + protected: DataArrayChar() { } - private: + protected: MemArray _mem; }; + + class DataArrayByteIterator; + + class DataArrayByte : public DataArrayChar + { + public: + MEDCOUPLING_EXPORT static DataArrayByte *New(); + MEDCOUPLING_EXPORT DataArrayChar *buildEmptySpecializedDAChar() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayByteIterator *iterator(); + MEDCOUPLING_EXPORT DataArrayByte *deepCpy() const; + MEDCOUPLING_EXPORT DataArrayByte *performCpy(bool deepCpy) const; + MEDCOUPLING_EXPORT char byteValue() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprCppStream(const char *varName, std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const throw(INTERP_KERNEL::Exception); + private: + DataArrayByte() { } + }; + + class DataArrayByteTuple; + + class MEDCOUPLING_EXPORT DataArrayByteIterator + { + public: + DataArrayByteIterator(DataArrayByte *da); + ~DataArrayByteIterator(); + DataArrayByteTuple *nextt() throw(INTERP_KERNEL::Exception); + private: + DataArrayByte *_da; + char *_pt; + int _tuple_id; + int _nb_comp; + int _nb_tuple; + }; + + class MEDCOUPLING_EXPORT DataArrayByteTuple + { + public: + DataArrayByteTuple(char *pt, int nbOfComp); + std::string repr() const throw(INTERP_KERNEL::Exception); + int getNumberOfCompo() const { return _nb_of_compo; } + const char *getConstPointer() const { return _pt; } + char *getPointer() { return _pt; } + char byteValue() const throw(INTERP_KERNEL::Exception); + DataArrayByte *buildDAByte(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception); + private: + char *_pt; + int _nb_of_compo; + }; + + class DataArrayAsciiCharIterator; + + class DataArrayAsciiChar : public DataArrayChar + { + public: + MEDCOUPLING_EXPORT static DataArrayAsciiChar *New(); + MEDCOUPLING_EXPORT DataArrayChar *buildEmptySpecializedDAChar() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayAsciiCharIterator *iterator(); + MEDCOUPLING_EXPORT DataArrayAsciiChar *deepCpy() const; + MEDCOUPLING_EXPORT DataArrayAsciiChar *performCpy(bool deepCpy) const; + MEDCOUPLING_EXPORT char asciiCharValue() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void reprCppStream(const char *varName, std::ostream& stream) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const throw(INTERP_KERNEL::Exception); + private: + DataArrayAsciiChar() { } + }; - class DataArrayCharTuple; + class DataArrayAsciiCharTuple; - class MEDCOUPLING_EXPORT DataArrayCharIterator + class MEDCOUPLING_EXPORT DataArrayAsciiCharIterator { public: - DataArrayCharIterator(DataArrayChar *da); - ~DataArrayCharIterator(); - DataArrayCharTuple *nextt(); + DataArrayAsciiCharIterator(DataArrayAsciiChar *da); + ~DataArrayAsciiCharIterator(); + DataArrayAsciiCharTuple *nextt() throw(INTERP_KERNEL::Exception); private: - DataArrayChar *_da; + DataArrayAsciiChar *_da; char *_pt; int _tuple_id; int _nb_comp; int _nb_tuple; }; - class MEDCOUPLING_EXPORT DataArrayCharTuple + class MEDCOUPLING_EXPORT DataArrayAsciiCharTuple { public: - DataArrayCharTuple(char *pt, int nbOfComp); - std::string repr() const; + DataArrayAsciiCharTuple(char *pt, int nbOfComp); + std::string repr() const throw(INTERP_KERNEL::Exception); int getNumberOfCompo() const { return _nb_of_compo; } const char *getConstPointer() const { return _pt; } char *getPointer() { return _pt; } - char charValue() const throw(INTERP_KERNEL::Exception); - DataArrayChar *buildDAChar(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception); + char asciiCharValue() const throw(INTERP_KERNEL::Exception); + DataArrayAsciiChar *buildDAAsciiChar(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception); private: char *_pt; int _nb_of_compo; diff --git a/src/MEDCoupling/MEDCouplingMemArrayChar.cxx b/src/MEDCoupling/MEDCouplingMemArrayChar.cxx index c4c9596e4..40265f5d7 100644 --- a/src/MEDCoupling/MEDCouplingMemArrayChar.cxx +++ b/src/MEDCoupling/MEDCouplingMemArrayChar.cxx @@ -30,21 +30,12 @@ using namespace ParaMEDMEM; -/*! - * Returns a new instance of DataArrayChar. The caller is to delete this array - * using decrRef() as it is no more needed. - */ -DataArrayChar *DataArrayChar::New() -{ - return new DataArrayChar; -} - /*! * Checks if raw data is allocated. Read more on the raw data * in \ref MEDCouplingArrayBasicsTuplesAndCompo "DataArrays infos" for more information. * \return bool - \a true if the raw data is allocated, \a false else. */ -bool DataArrayChar::isAllocated() const +bool DataArrayChar::isAllocated() const throw(INTERP_KERNEL::Exception) { return getConstPointer()!=0; } @@ -91,27 +82,6 @@ void DataArrayChar::setInfoAndChangeNbOfCompo(const std::vector& in _info_on_compo=info; } -/*! - * Returns the only one value in \a this, if and only if number of elements - * (nb of tuples * nb of components) is equal to 1, and that \a this is allocated. - * \return double - the sole value stored in \a this array. - * \throw If at least one of conditions stated above is not fulfilled. - */ -char DataArrayChar::charValue() const throw(INTERP_KERNEL::Exception) -{ - if(isAllocated()) - { - if(getNbOfElems()==1) - { - return *getConstPointer(); - } - else - throw INTERP_KERNEL::Exception("DataArrayChar::charValue : DataArrayChar instance is allocated but number of elements is not equal to 1 !"); - } - else - throw INTERP_KERNEL::Exception("DataArrayChar::charValue : DataArrayChar instance is not allocated !"); -} - /*! * Returns an integer value characterizing \a this array, which is useful for a quick * comparison of many instances of DataArrayInt. @@ -144,34 +114,6 @@ bool DataArrayChar::empty() const throw(INTERP_KERNEL::Exception) return getNumberOfTuples()==0; } -/*! - * Returns a full copy of \a this. For more info on copying data arrays see - * \ref MEDCouplingArrayBasicsCopyDeep. - * \return DataArrayChar * - a new instance of DataArrayChar. - */ -DataArrayChar *DataArrayChar::deepCpy() const -{ - return new DataArrayChar(*this); -} - -/*! - * Returns either a \a deep or \a shallow copy of this array. For more info see - * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow. - * \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one. - * \return DataArrayChar * - either a new instance of DataArrayChar (if \a dCpy - * == \a true) or \a this instance (if \a dCpy == \a false). - */ -DataArrayChar *DataArrayChar::performCpy(bool dCpy) const -{ - if(dCpy) - return deepCpy(); - else - { - incrRef(); - return const_cast(this); - } -} - /*! * Copies all the data from another DataArrayChar. For more info see * \ref MEDCouplingArrayBasicsCopyDeepAssign. @@ -292,7 +234,7 @@ void DataArrayChar::pack() const throw(INTERP_KERNEL::Exception) * \param [in] nbOfCompo - number of components of data to allocate. * \throw If \a nbOfTuple < 0 or \a nbOfCompo < 0. */ -void DataArrayChar::allocIfNecessary(int nbOfTuple, int nbOfCompo) +void DataArrayChar::allocIfNecessary(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception) { if(isAllocated()) { @@ -326,7 +268,7 @@ void DataArrayChar::alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exc * \param [in] other - an instance of DataArrayChar to compare with \a this one. * \return bool - \a true if the two arrays are equal, \a false else. */ -bool DataArrayChar::isEqual(const DataArrayChar& other) const +bool DataArrayChar::isEqual(const DataArrayChar& other) const throw(INTERP_KERNEL::Exception) { std::string tmp; return isEqualIfNotWhy(other,tmp); @@ -340,7 +282,7 @@ bool DataArrayChar::isEqual(const DataArrayChar& other) const * \param [out] reason In case of inequality returns the reason. * \sa DataArrayChar::isEqual */ -bool DataArrayChar::isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const +bool DataArrayChar::isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const throw(INTERP_KERNEL::Exception) { if(!areInfoEqualsIfNotWhy(other,reason)) return false; @@ -353,7 +295,7 @@ bool DataArrayChar::isEqualIfNotWhy(const DataArrayChar& other, std::string& rea * \param [in] other - an instance of DataArrayChar to compare with \a this one. * \return bool - \a true if the values of two arrays are equal, \a false else. */ -bool DataArrayChar::isEqualWithoutConsideringStr(const DataArrayChar& other) const +bool DataArrayChar::isEqualWithoutConsideringStr(const DataArrayChar& other) const throw(INTERP_KERNEL::Exception) { std::string tmp; return _mem.isEqual(other._mem,0,tmp); @@ -389,61 +331,20 @@ void DataArrayChar::fillWithValue(char val) throw(INTERP_KERNEL::Exception) * DataArrayChar. This text is shown when a DataArrayChar is printed in Python. * \return std::string - text describing \a this DataArrayChar. */ -std::string DataArrayChar::repr() const +std::string DataArrayChar::repr() const throw(INTERP_KERNEL::Exception) { std::ostringstream ret; reprStream(ret); return ret.str(); } -std::string DataArrayChar::reprZip() const +std::string DataArrayChar::reprZip() const throw(INTERP_KERNEL::Exception) { std::ostringstream ret; reprZipStream(ret); return ret.str(); } -void DataArrayChar::reprStream(std::ostream& stream) const -{ - stream << "Name of char array : \"" << _name << "\"\n"; - reprWithoutNameStream(stream); -} - -void DataArrayChar::reprZipStream(std::ostream& stream) const -{ - stream << "Name of char array : \"" << _name << "\"\n"; - reprZipWithoutNameStream(stream); -} - -void DataArrayChar::reprWithoutNameStream(std::ostream& stream) const -{ - DataArray::reprWithoutNameStream(stream); - _mem.repr(getNumberOfComponents(),stream); -} - -void DataArrayChar::reprZipWithoutNameStream(std::ostream& stream) const -{ - DataArray::reprWithoutNameStream(stream); - _mem.reprZip(getNumberOfComponents(),stream); -} - -void DataArrayChar::reprCppStream(const char *varName, std::ostream& stream) const -{ - int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents(); - const char *data=getConstPointer(); - stream << "DataArrayChar *" << varName << "=DataArrayChar::New();" << std::endl; - if(nbTuples*nbComp>=1) - { - stream << "const char " << 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; -} - /*! * Changes number of tuples in the array. If the new number of tuples is smaller * than the current number the array is truncated, otherwise the array is extended. @@ -462,7 +363,7 @@ void DataArrayChar::reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception) * array to the new one. * \return DataArrayInt * - the new instance of DataArrayChar. */ -DataArrayInt *DataArrayChar::convertToIntArr() const +DataArrayInt *DataArrayChar::convertToIntArr() const throw(INTERP_KERNEL::Exception) { checkAllocated(); DataArrayInt *ret=DataArrayInt::New(); @@ -484,7 +385,7 @@ DataArrayInt *DataArrayChar::convertToIntArr() const * \param [in] old2New - C array of length equal to \a this->getNumberOfTuples() * giving a new position for i-th old value. */ -void DataArrayChar::renumberInPlace(const int *old2New) +void DataArrayChar::renumberInPlace(const int *old2New) throw(INTERP_KERNEL::Exception) { checkAllocated(); int nbTuples=getNumberOfTuples(); @@ -506,7 +407,7 @@ void DataArrayChar::renumberInPlace(const int *old2New) * \param [in] new2Old - C array of length equal to \a this->getNumberOfTuples() * giving a previous position of i-th new value. */ -void DataArrayChar::renumberInPlaceR(const int *new2Old) +void DataArrayChar::renumberInPlaceR(const int *new2Old) throw(INTERP_KERNEL::Exception) { checkAllocated(); int nbTuples=getNumberOfTuples(); @@ -532,12 +433,12 @@ void DataArrayChar::renumberInPlaceR(const int *new2Old) * is to delete using decrRef() as it is no more needed. * \throw If \a this is not allocated. */ -DataArrayChar *DataArrayChar::renumber(const int *old2New) const +DataArrayChar *DataArrayChar::renumber(const int *old2New) const throw(INTERP_KERNEL::Exception) { checkAllocated(); int nbTuples=getNumberOfTuples(); int nbOfCompo=getNumberOfComponents(); - DataArrayChar *ret=DataArrayChar::New(); + MEDCouplingAutoRefCountObjectPtr ret=buildEmptySpecializedDAChar(); ret->alloc(nbTuples,nbOfCompo); ret->copyStringInfoFrom(*this); const char *iptr=getConstPointer(); @@ -545,7 +446,7 @@ DataArrayChar *DataArrayChar::renumber(const int *old2New) const for(int i=0;icopyStringInfoFrom(*this); - return ret; + return ret.retn(); } /*! @@ -559,12 +460,12 @@ DataArrayChar *DataArrayChar::renumber(const int *old2New) const * \return DataArrayChar * - the new instance of DataArrayChar that the caller * is to delete using decrRef() as it is no more needed. */ -DataArrayChar *DataArrayChar::renumberR(const int *new2Old) const +DataArrayChar *DataArrayChar::renumberR(const int *new2Old) const throw(INTERP_KERNEL::Exception) { checkAllocated(); int nbTuples=getNumberOfTuples(); int nbOfCompo=getNumberOfComponents(); - DataArrayChar *ret=DataArrayChar::New(); + MEDCouplingAutoRefCountObjectPtr ret=buildEmptySpecializedDAChar(); ret->alloc(nbTuples,nbOfCompo); ret->copyStringInfoFrom(*this); const char *iptr=getConstPointer(); @@ -572,7 +473,7 @@ DataArrayChar *DataArrayChar::renumberR(const int *new2Old) const for(int i=0;icopyStringInfoFrom(*this); - return ret; + return ret.retn(); } /*! @@ -588,12 +489,12 @@ DataArrayChar *DataArrayChar::renumberR(const int *new2Old) const * \return DataArrayChar * - the new instance of DataArrayChar that the caller * is to delete using decrRef() as it is no more needed. */ -DataArrayChar *DataArrayChar::renumberAndReduce(const int *old2New, int newNbOfTuple) const +DataArrayChar *DataArrayChar::renumberAndReduce(const int *old2New, int newNbOfTuple) const throw(INTERP_KERNEL::Exception) { checkAllocated(); int nbTuples=getNumberOfTuples(); int nbOfCompo=getNumberOfComponents(); - DataArrayChar *ret=DataArrayChar::New(); + MEDCouplingAutoRefCountObjectPtr ret=buildEmptySpecializedDAChar(); ret->alloc(newNbOfTuple,nbOfCompo); const char *iptr=getConstPointer(); char *optr=ret->getPointer(); @@ -604,7 +505,7 @@ DataArrayChar *DataArrayChar::renumberAndReduce(const int *old2New, int newNbOfT std::copy(iptr+i*nbOfCompo,iptr+(i+1)*nbOfCompo,optr+w*nbOfCompo); } ret->copyStringInfoFrom(*this); - return ret; + return ret.retn(); } /*! @@ -629,7 +530,7 @@ DataArrayChar *DataArrayChar::renumberAndReduce(const int *old2New, int newNbOfT DataArrayChar *DataArrayChar::selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception) { checkAllocated(); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayChar::New(); + MEDCouplingAutoRefCountObjectPtr ret=buildEmptySpecializedDAChar(); int nbComp=getNumberOfComponents(); int oldNbOfTuples=getNumberOfTuples(); ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp); @@ -665,7 +566,7 @@ DataArrayChar *DataArrayChar::selectByTupleIdSafe(const int *new2OldBg, const in DataArrayChar *DataArrayChar::selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception) { checkAllocated(); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayChar::New(); + MEDCouplingAutoRefCountObjectPtr ret=buildEmptySpecializedDAChar(); int nbComp=getNumberOfComponents(); int newNbOfTuples=GetNumberOfItemGivenBES(bg,end2,step,"DataArrayInt::selectByTupleId2 : "); ret->alloc(newNbOfTuples,nbComp); @@ -733,7 +634,7 @@ void DataArrayChar::rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception) DataArrayChar *DataArrayChar::changeNbOfComponents(int newNbOfComp, char dftValue) const throw(INTERP_KERNEL::Exception) { checkAllocated(); - DataArrayChar *ret=DataArrayChar::New(); + MEDCouplingAutoRefCountObjectPtr ret=buildEmptySpecializedDAChar(); ret->alloc(getNumberOfTuples(),newNbOfComp); const char *oldc=getConstPointer(); char *nc=ret->getPointer(); @@ -752,7 +653,7 @@ DataArrayChar *DataArrayChar::changeNbOfComponents(int newNbOfComp, char dftValu for(int i=0;isetInfoOnComponent(i,getInfoOnComponent(i).c_str()); ret->setName(getName().c_str()); - return ret; + return ret.retn(); } /*! @@ -773,7 +674,7 @@ DataArrayChar *DataArrayChar::changeNbOfComponents(int newNbOfComp, char dftValu DataArrayChar *DataArrayChar::keepSelectedComponents(const std::vector& compoIds) const throw(INTERP_KERNEL::Exception) { checkAllocated(); - MEDCouplingAutoRefCountObjectPtr ret(DataArrayChar::New()); + MEDCouplingAutoRefCountObjectPtr ret(buildEmptySpecializedDAChar()); int newNbOfCompo=(int)compoIds.size(); int oldNbOfCompo=getNumberOfComponents(); for(std::vector::const_iterator it=compoIds.begin();it!=compoIds.end();it++) @@ -1365,11 +1266,6 @@ char DataArrayChar::back() const throw(INTERP_KERNEL::Exception) return *(getConstPointer()+nbOfTuples-1); } -DataArrayCharIterator *DataArrayChar::iterator() -{ - return new DataArrayCharIterator(this); -} - /*! * Creates a new DataArrayChar containing IDs (indices) of tuples holding value equal to a * given one. @@ -1475,6 +1371,19 @@ int DataArrayChar::locateTuple(const std::vector& tupl) const throw(INTERP return -1; } +/*! + * This method is an extension of DataArrayChar::presenceOfValue method because this method works for DataArrayChar with + * any number of components excepted 0 (an INTERP_KERNEL::Exception is thrown in this case). + * This method searches in \b this is there is a tuple that matched the input parameter \b tupl. + * This method throws an INTERP_KERNEL::Exception if the number of components in \b this mismatches with the size of + * the input vector. An INTERP_KERNEL::Exception is thrown too if \b this is not allocated. + * \sa DataArrayChar::locateTuple + */ +bool DataArrayChar::presenceOfTuple(const std::vector& tupl) const throw(INTERP_KERNEL::Exception) +{ + return locateTuple(tupl)!=-1; +} + /*! * Returns \a true if a given value is present within \a this one-dimensional array. * \param [in] value - the value to find within \a this array. @@ -1684,13 +1593,13 @@ DataArrayChar *DataArrayChar::Aggregate(const std::vector throw INTERP_KERNEL::Exception("DataArrayChar::Aggregate : Nb of components mismatch for array aggregation !"); nbt+=(*it)->getNumberOfTuples(); } - DataArrayChar *ret=DataArrayChar::New(); + MEDCouplingAutoRefCountObjectPtr ret=a[0]->buildEmptySpecializedDAChar(); ret->alloc(nbt,nbOfComp); char *pt=ret->getPointer(); for(it=a.begin();it!=a.end();it++) pt=std::copy((*it)->getConstPointer(),(*it)->getConstPointer()+(*it)->getNbOfElems(),pt); ret->copyStringInfoFrom(*(a[0])); - return ret; + return ret.retn(); } /*! @@ -1756,7 +1665,7 @@ DataArrayChar *DataArrayChar::Meld(const std::vector& arr pts[i]=(*it)->getConstPointer(); } int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0); - DataArrayChar *ret=DataArrayChar::New(); + DataArrayChar *ret=a[0]->buildEmptySpecializedDAChar(); ret->alloc(nbOfTuples,totalNbOfComp); char *retPtr=ret->getPointer(); for(int i=0;i& arr * \param [in] nbOfTuple - new number of tuples in \a this. * \param [in] nbOfCompo - new number of components in \a this. */ -void DataArrayChar::useArray(const char *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) +void DataArrayChar::useArray(const char *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception) { _info_on_compo.resize(nbOfCompo); _mem.useArray(array,ownership,type,nbOfTuple*nbOfCompo); declareAsNew(); } -void DataArrayChar::useExternalArrayWithRWAccess(const char *array, int nbOfTuple, int nbOfCompo) +void DataArrayChar::useExternalArrayWithRWAccess(const char *array, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception) { _info_on_compo.resize(nbOfCompo); _mem.useExternalArrayWithRWAccess(array,nbOfTuple*nbOfCompo); declareAsNew(); } -DataArrayCharIterator::DataArrayCharIterator(DataArrayChar *da):_da(da),_pt(0),_tuple_id(0),_nb_comp(0),_nb_tuple(0) +/*! + * Returns a new instance of DataArrayByte. The caller is to delete this array + * using decrRef() as it is no more needed. + */ +DataArrayByte *DataArrayByte::New() +{ + return new DataArrayByte; +} + +DataArrayByteIterator *DataArrayByte::iterator() +{ + return new DataArrayByteIterator(this); +} + +/*! + * Returns a full copy of \a this. For more info on copying data arrays see + * \ref MEDCouplingArrayBasicsCopyDeep. + * \return DataArrayByte * - a new instance of DataArrayByte. + */ +DataArrayByte *DataArrayByte::deepCpy() const +{ + return new DataArrayByte(*this); +} + +/*! + * Returns either a \a deep or \a shallow copy of this array. For more info see + * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow. + * \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one. + * \return DataArrayByte * - either a new instance of DataArrayByte (if \a dCpy + * == \a true) or \a this instance (if \a dCpy == \a false). + */ +DataArrayByte *DataArrayByte::performCpy(bool dCpy) const +{ + if(dCpy) + return deepCpy(); + else + { + incrRef(); + return const_cast(this); + } +} + +/*! + * Returns the only one value in \a this, if and only if number of elements + * (nb of tuples * nb of components) is equal to 1, and that \a this is allocated. + * \return double - the sole value stored in \a this array. + * \throw If at least one of conditions stated above is not fulfilled. + */ +char DataArrayByte::byteValue() const throw(INTERP_KERNEL::Exception) +{ + if(isAllocated()) + { + if(getNbOfElems()==1) + { + return *getConstPointer(); + } + else + throw INTERP_KERNEL::Exception("DataArrayByte::byteValue : DataArrayByte instance is allocated but number of elements is not equal to 1 !"); + } + else + throw INTERP_KERNEL::Exception("DataArrayByte::byteValue : DataArrayByte instance is not allocated !"); +} + +DataArrayChar *DataArrayByte::buildEmptySpecializedDAChar() const throw(INTERP_KERNEL::Exception) +{ + return DataArrayByte::New(); +} + +void DataArrayByte::reprStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) +{ + stream << "Name of byte array : \"" << _name << "\"\n"; + reprWithoutNameStream(stream); +} + +void DataArrayByte::reprZipStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) +{ + stream << "Name of byte array : \"" << _name << "\"\n"; + reprZipWithoutNameStream(stream); +} + +void DataArrayByte::reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) +{ + DataArray::reprWithoutNameStream(stream); + _mem.repr(getNumberOfComponents(),stream); +} + +void DataArrayByte::reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) +{ + DataArray::reprWithoutNameStream(stream); + _mem.reprZip(getNumberOfComponents(),stream); +} + +void DataArrayByte::reprCppStream(const char *varName, std::ostream& stream) const throw(INTERP_KERNEL::Exception) +{ + int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents(); + const char *data=getConstPointer(); + stream << "DataArrayByte *" << varName << "=DataArrayByte::New();" << std::endl; + if(nbTuples*nbComp>=1) + { + stream << "const char " << 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; +} + +bool DataArrayByte::isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const throw(INTERP_KERNEL::Exception) +{ + const DataArrayByte *otherC=dynamic_cast(&other); + if(!otherC) + { reason="this is of type DataArrayByte whereas other is not a DataArrayByte instance"; return false; } + return DataArrayChar::isEqualIfNotWhy(other,reason); +} + +DataArrayByteIterator::DataArrayByteIterator(DataArrayByte *da):_da(da),_pt(0),_tuple_id(0),_nb_comp(0),_nb_tuple(0) +{ + if(_da) + { + _da->incrRef(); + if(_da->isAllocated()) + { + _nb_comp=da->getNumberOfComponents(); + _nb_tuple=da->getNumberOfTuples(); + _pt=da->getPointer(); + } + } +} + +DataArrayByteIterator::~DataArrayByteIterator() +{ + if(_da) + _da->decrRef(); +} + +DataArrayByteTuple *DataArrayByteIterator::nextt() throw(INTERP_KERNEL::Exception) +{ + if(_tuple_id<_nb_tuple) + { + _tuple_id++; + DataArrayByteTuple *ret=new DataArrayByteTuple(_pt,_nb_comp); + _pt+=_nb_comp; + return ret; + } + else + return 0; +} + +DataArrayByteTuple::DataArrayByteTuple(char *pt, int nbOfComp):_pt(pt),_nb_of_compo(nbOfComp) +{ +} + +std::string DataArrayByteTuple::repr() const throw(INTERP_KERNEL::Exception) +{ + std::ostringstream oss; oss << "("; + for(int i=0;i<_nb_of_compo-1;i++) + oss << _pt[i] << ", "; + oss << _pt[_nb_of_compo-1] << ")"; + return oss.str(); +} + +char DataArrayByteTuple::byteValue() const throw(INTERP_KERNEL::Exception) +{ + if(_nb_of_compo==1) + return *_pt; + throw INTERP_KERNEL::Exception("DataArrayByteTuple::byteValue : DataArrayByteTuple instance has not exactly 1 component -> Not possible to convert it into an character !"); +} + +/*! + * This method returns a newly allocated instance the caller should dealed with by a ParaMEDMEM::DataArrayByte::decrRef. + * This method performs \b no copy of data. The content is only referenced using ParaMEDMEM::DataArrayByte::useArray with ownership set to \b false. + * This method throws an INTERP_KERNEL::Exception is it is impossible to match sizes of \b this that is too say \b nbOfCompo=this->_nb_of_elem and \bnbOfTuples==1 or + * \b nbOfCompo=1 and \bnbOfTuples==this->_nb_of_elem. + */ +DataArrayByte *DataArrayByteTuple::buildDAByte(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception) +{ + if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1)) + { + DataArrayByte *ret=DataArrayByte::New(); + ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo); + return ret; + } + else + { + std::ostringstream oss; oss << "DataArrayByteTuple::buildDAByte : unable to build a requested DataArrayByte instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo; + oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } +} + +/*! + * Returns a new instance of DataArrayAsciiChar. The caller is to delete this array + * using decrRef() as it is no more needed. + */ +DataArrayAsciiChar *DataArrayAsciiChar::New() +{ + return new DataArrayAsciiChar; +} + +DataArrayAsciiCharIterator *DataArrayAsciiChar::iterator() +{ + return new DataArrayAsciiCharIterator(this); +} + +/*! + * Returns a full copy of \a this. For more info on copying data arrays see + * \ref MEDCouplingArrayBasicsCopyDeep. + * \return DataArrayAsciiChar * - a new instance of DataArrayAsciiChar. + */ +DataArrayAsciiChar *DataArrayAsciiChar::deepCpy() const +{ + return new DataArrayAsciiChar(*this); +} + +/*! + * Returns either a \a deep or \a shallow copy of this array. For more info see + * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow. + * \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one. + * \return DataArrayAsciiChar * - either a new instance of DataArrayAsciiChar (if \a dCpy + * == \a true) or \a this instance (if \a dCpy == \a false). + */ +DataArrayAsciiChar *DataArrayAsciiChar::performCpy(bool dCpy) const +{ + if(dCpy) + return deepCpy(); + else + { + incrRef(); + return const_cast(this); + } +} + +/*! + * Returns the only one value in \a this, if and only if number of elements + * (nb of tuples * nb of components) is equal to 1, and that \a this is allocated. + * \return double - the sole value stored in \a this array. + * \throw If at least one of conditions stated above is not fulfilled. + */ +char DataArrayAsciiChar::asciiCharValue() const throw(INTERP_KERNEL::Exception) +{ + if(isAllocated()) + { + if(getNbOfElems()==1) + { + return *getConstPointer(); + } + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::asciiCharValue : DataArrayAsciiChar instance is allocated but number of elements is not equal to 1 !"); + } + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::asciiCharValue : DataArrayAsciiChar instance is not allocated !"); +} + +DataArrayChar *DataArrayAsciiChar::buildEmptySpecializedDAChar() const throw(INTERP_KERNEL::Exception) +{ + return DataArrayAsciiChar::New(); +} + +void DataArrayAsciiChar::reprStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) +{ + stream << "Name of ASCII char array : \"" << _name << "\"\n"; + reprWithoutNameStream(stream); +} + +void DataArrayAsciiChar::reprZipStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) +{ + stream << "Name of ASCII char array : \"" << _name << "\"\n"; + reprZipWithoutNameStream(stream); +} + +void DataArrayAsciiChar::reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) +{ + DataArray::reprWithoutNameStream(stream); + _mem.repr(getNumberOfComponents(),stream); +} + +void DataArrayAsciiChar::reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) +{ + DataArray::reprWithoutNameStream(stream); + _mem.reprZip(getNumberOfComponents(),stream); +} + +void DataArrayAsciiChar::reprCppStream(const char *varName, std::ostream& stream) const throw(INTERP_KERNEL::Exception) +{ + int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents(); + const char *data=getConstPointer(); + stream << "DataArrayAsciiChar *" << varName << "=DataArrayAsciiChar::New();" << std::endl; + if(nbTuples*nbComp>=1) + { + stream << "const char " << 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; +} + +bool DataArrayAsciiChar::isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const throw(INTERP_KERNEL::Exception) +{ + const DataArrayAsciiChar *otherC=dynamic_cast(&other); + if(!otherC) + { reason="this is of type DataArrayAsciiChar whereas other is not a DataArrayAsciiChar instance"; return false; } + return DataArrayChar::isEqualIfNotWhy(other,reason); +} + +DataArrayAsciiCharIterator::DataArrayAsciiCharIterator(DataArrayAsciiChar *da):_da(da),_pt(0),_tuple_id(0),_nb_comp(0),_nb_tuple(0) { if(_da) { @@ -1812,18 +2030,18 @@ DataArrayCharIterator::DataArrayCharIterator(DataArrayChar *da):_da(da),_pt(0),_ } } -DataArrayCharIterator::~DataArrayCharIterator() +DataArrayAsciiCharIterator::~DataArrayAsciiCharIterator() { if(_da) _da->decrRef(); } -DataArrayCharTuple *DataArrayCharIterator::nextt() +DataArrayAsciiCharTuple *DataArrayAsciiCharIterator::nextt() throw(INTERP_KERNEL::Exception) { if(_tuple_id<_nb_tuple) { _tuple_id++; - DataArrayCharTuple *ret=new DataArrayCharTuple(_pt,_nb_comp); + DataArrayAsciiCharTuple *ret=new DataArrayAsciiCharTuple(_pt,_nb_comp); _pt+=_nb_comp; return ret; } @@ -1831,11 +2049,11 @@ DataArrayCharTuple *DataArrayCharIterator::nextt() return 0; } -DataArrayCharTuple::DataArrayCharTuple(char *pt, int nbOfComp):_pt(pt),_nb_of_compo(nbOfComp) +DataArrayAsciiCharTuple::DataArrayAsciiCharTuple(char *pt, int nbOfComp):_pt(pt),_nb_of_compo(nbOfComp) { } -std::string DataArrayCharTuple::repr() const +std::string DataArrayAsciiCharTuple::repr() const throw(INTERP_KERNEL::Exception) { std::ostringstream oss; oss << "("; for(int i=0;i<_nb_of_compo-1;i++) @@ -1844,30 +2062,30 @@ std::string DataArrayCharTuple::repr() const return oss.str(); } -char DataArrayCharTuple::charValue() const throw(INTERP_KERNEL::Exception) +char DataArrayAsciiCharTuple::asciiCharValue() const throw(INTERP_KERNEL::Exception) { if(_nb_of_compo==1) return *_pt; - throw INTERP_KERNEL::Exception("DataArrayCharTuple::charValue : DataArrayCharTuple instance has not exactly 1 component -> Not possible to convert it into an character !"); + throw INTERP_KERNEL::Exception("DataArrayAsciiCharTuple::asciiCharValue : DataArrayAsciiCharTuple instance has not exactly 1 component -> Not possible to convert it into an character !"); } /*! - * This method returns a newly allocated instance the caller should dealed with by a ParaMEDMEM::DataArrayChar::decrRef. - * This method performs \b no copy of data. The content is only referenced using ParaMEDMEM::DataArrayChar::useArray with ownership set to \b false. + * This method returns a newly allocated instance the caller should dealed with by a ParaMEDMEM::DataArrayAsciiChar::decrRef. + * This method performs \b no copy of data. The content is only referenced using ParaMEDMEM::DataArrayAsciiChar::useArray with ownership set to \b false. * This method throws an INTERP_KERNEL::Exception is it is impossible to match sizes of \b this that is too say \b nbOfCompo=this->_nb_of_elem and \bnbOfTuples==1 or * \b nbOfCompo=1 and \bnbOfTuples==this->_nb_of_elem. */ -DataArrayChar *DataArrayCharTuple::buildDAChar(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception) +DataArrayAsciiChar *DataArrayAsciiCharTuple::buildDAAsciiChar(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception) { if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1)) { - DataArrayChar *ret=DataArrayChar::New(); + DataArrayAsciiChar *ret=DataArrayAsciiChar::New(); ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo); return ret; } else { - std::ostringstream oss; oss << "DataArrayCharTuple::buildDAChar : unable to build a requested DataArrayChar instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo; + std::ostringstream oss; oss << "DataArrayAsciiCharTuple::buildDAAsciiChar : unable to build a requested DataArrayAsciiChar instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo; oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 905d2d15e..513a3822d 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -76,6 +76,11 @@ using namespace INTERP_KERNEL; $result=convertMultiFields($1,$owner); } +%typemap(out) ParaMEDMEM::DataArrayChar* +{ + $result=convertDataArrayChar($1,$owner); +} + #ifdef WITH_NUMPY2 %init %{ import_array(); %} #endif @@ -199,6 +204,28 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayInt::__mod__; %newobject ParaMEDMEM::DataArrayInt::__rmod__; %newobject ParaMEDMEM::DataArrayIntTuple::buildDAInt; +%newobject ParaMEDMEM::DataArrayChar::convertToIntArr; +%newobject ParaMEDMEM::DataArrayChar::renumber; +%newobject ParaMEDMEM::DataArrayChar::renumberR; +%newobject ParaMEDMEM::DataArrayChar::renumberAndReduce; +%newobject ParaMEDMEM::DataArrayChar::selectByTupleIdSafe; +%newobject ParaMEDMEM::DataArrayChar::selectByTupleId2; +%newobject ParaMEDMEM::DataArrayChar::changeNbOfComponents; +%newobject ParaMEDMEM::DataArrayChar::keepSelectedComponents; +%newobject ParaMEDMEM::DataArrayChar::getIdsEqual; +%newobject ParaMEDMEM::DataArrayChar::getIdsNotEqual; +%newobject ParaMEDMEM::DataArrayChar::Aggregate; +%newobject ParaMEDMEM::DataArrayChar::Meld; +%newobject ParaMEDMEM::DataArrayByte::New; +%newobject ParaMEDMEM::DataArrayByte::__iter__; +%newobject ParaMEDMEM::DataArrayByte::deepCpy; +%newobject ParaMEDMEM::DataArrayByte::performCpy; +%newobject ParaMEDMEM::DataArrayByteTuple::buildDAByte; +%newobject ParaMEDMEM::DataArrayAsciiChar::New; +%newobject ParaMEDMEM::DataArrayAsciiChar::__iter__; +%newobject ParaMEDMEM::DataArrayAsciiChar::deepCpy; +%newobject ParaMEDMEM::DataArrayAsciiChar::performCpy; +%newobject ParaMEDMEM::DataArrayAsciiCharTuple::buildDAAsciiChar; %newobject ParaMEDMEM::DataArrayDouble::New; %newobject ParaMEDMEM::DataArrayDouble::__iter__; %newobject ParaMEDMEM::DataArrayDouble::convertToIntArr; @@ -367,6 +394,12 @@ using namespace INTERP_KERNEL; %ignore ParaMEDMEM::DataArrayIntIterator::nextt; %ignore ParaMEDMEM::DataArrayIntTuple::repr; %ignore ParaMEDMEM::DataArrayIntTuple::intValue; +%ignore ParaMEDMEM::DataArrayByteIterator::nextt; +%ignore ParaMEDMEM::DataArrayByteTuple::repr; +%ignore ParaMEDMEM::DataArrayByteTuple::byteValue; +%ignore ParaMEDMEM::DataArrayAsciiCharIterator::nextt; +%ignore ParaMEDMEM::DataArrayAsciiCharTuple::repr; +%ignore ParaMEDMEM::DataArrayAsciiCharTuple::asciiCharValue; %ignore ParaMEDMEM::DataArrayDoubleIterator::nextt; %ignore ParaMEDMEM::DataArrayDoubleTuple::repr; %ignore ParaMEDMEM::DataArrayDoubleTuple::doubleValue; @@ -875,69 +908,877 @@ namespace ParaMEDMEM static MEDCouplingMesh *MergeMeshes(PyObject *li) throw(INTERP_KERNEL::Exception) { - std::vector tmp; - convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__MEDCouplingMesh,"MEDCouplingMesh",tmp); - return MEDCouplingMesh::MergeMeshes(tmp); + std::vector tmp; + convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__MEDCouplingMesh,"MEDCouplingMesh",tmp); + return MEDCouplingMesh::MergeMeshes(tmp); + } + } + }; +} + +%extend ParaMEDMEM::DataArray +{ + PyObject *getInfoOnComponents() const throw(INTERP_KERNEL::Exception) + { + const std::vector& comps=self->getInfoOnComponents(); + PyObject *ret=PyList_New((int)comps.size()); + for(int i=0;i<(int)comps.size();i++) + PyList_SetItem(ret,i,PyString_FromString(comps[i].c_str())); + return ret; + } + + void copyPartOfStringInfoFrom(const DataArray& other, PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyToNewIntArr3(li,tmp); + self->copyPartOfStringInfoFrom(other,tmp); + } + + void copyPartOfStringInfoFrom2(PyObject *li, const DataArray& other) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyToNewIntArr3(li,tmp); + self->copyPartOfStringInfoFrom2(tmp,other); + } +} + +%extend ParaMEDMEM::DataArrayInt +{ + void pushBackValsSilent(PyObject *li) throw(INTERP_KERNEL::Exception) + { + int szArr,sw,iTypppArr; + std::vector stdvecTyyppArr; + const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); + self->pushBackValsSilent(tmp,tmp+szArr); + } + + PyObject *partitionByDifferentValues() const throw(INTERP_KERNEL::Exception) + { + std::vector ret1; + std::vector ret0=self->partitionByDifferentValues(ret1); + std::size_t sz=ret0.size(); + PyObject *pyRet=PyTuple_New(2); + PyObject *pyRet0=PyList_New((int)sz); + PyObject *pyRet1=PyList_New((int)sz); + for(std::size_t i=0;iisAllocated()) + { + return self->getNumberOfTuples(); + } + else + { + throw INTERP_KERNEL::Exception("DataArrayChar::__len__ : Instance is NOT allocated !"); + } + } + + PyObject *isEqualIfNotWhy(const DataArrayChar& other) const throw(INTERP_KERNEL::Exception) + { + std::string ret1; + bool ret0=self->isEqualIfNotWhy(other,ret1); + PyObject *ret=PyTuple_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyTuple_SetItem(ret,0,ret0Py); + PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str())); + return ret; + } + + void renumberInPlace(PyObject *li) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + self->renumberInPlace(tmp); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + self->renumberInPlace(da2->getConstPointer()); + } + } + + void renumberInPlaceR(PyObject *li) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + self->renumberInPlaceR(tmp); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + self->renumberInPlaceR(da2->getConstPointer()); + } + } + + DataArrayChar *renumber(PyObject *li) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumber(tmp); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumber(da2->getConstPointer()); + } + } + + DataArrayChar *renumberR(PyObject *li) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumberR(tmp); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumberR(da2->getConstPointer()); + } + } + + DataArrayChar *renumberAndReduce(PyObject *li, int newNbOfTuple) throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumberAndReduce(tmp,newNbOfTuple); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + int size=self->getNumberOfTuples(); + if(size!=self->getNumberOfTuples()) + { + throw INTERP_KERNEL::Exception("Invalid list length ! Must be equal to number of tuples !"); + } + return self->renumberAndReduce(da2->getConstPointer(),newNbOfTuple); + } + } + + DataArrayChar *selectByTupleIdSafe(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + return self->selectByTupleIdSafe(tmp,tmp+size); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + return self->selectByTupleIdSafe(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); + } + } + + DataArrayChar *keepSelectedComponents(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertPyToNewIntArr3(li,tmp); + return self->keepSelectedComponents(tmp); + } + + static DataArrayChar *Aggregate(PyObject *dachs) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertFromPyObjVectorOfObj(dachs,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,"DataArrayChar",tmp); + return DataArrayChar::Aggregate(tmp); + } + + static DataArrayChar *Meld(PyObject *dachs) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertFromPyObjVectorOfObj(dachs,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,"DataArrayChar",tmp); + return DataArrayChar::Meld(tmp); + } +} + +%extend ParaMEDMEM::DataArrayByteTuple +{ + std::string __str__() const + { + return self->repr(); + } + + char __int__() const throw(INTERP_KERNEL::Exception) + { + return self->byteValue(); + } + + DataArrayByte *buildDAByte() + { + return self->buildDAByte(1,self->getNumberOfCompo()); + } +} + +%extend ParaMEDMEM::DataArrayByteIterator +{ + PyObject *next() + { + DataArrayByteTuple *ret=self->nextt(); + if(ret) + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayByteTuple,SWIG_POINTER_OWN | 0); + else + { + PyErr_SetString(PyExc_StopIteration,"No more data."); + return 0; + } + } +} + +%extend ParaMEDMEM::DataArrayByte +{ + DataArrayByte() throw(INTERP_KERNEL::Exception) + { + return DataArrayByte::New(); + } + + static DataArrayByte *New(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) + { + const char *msg="ParaMEDMEM::DataArrayByte::New : Available API are : \n-DataArrayByte.New()\n--DataArrayByte.New([1,3,4])\n-DataArrayByte.New([1,3,4],3)\n-DataArrayByte.New([1,3,4,5],2,2)\n-DataArrayByte.New(5)\n-DataArrayByte.New(5,2) !"; + if(PyList_Check(elt0) || PyTuple_Check(elt0)) + { + if(nbOfTuples) + { + if(PyInt_Check(nbOfTuples)) + { + int nbOfTuples1=PyInt_AS_LONG(nbOfTuples); + if(nbOfTuples1<0) + throw INTERP_KERNEL::Exception("DataArrayByte::New : should be a positive set of allocated memory !"); + if(nbOfComp) + { + if(PyInt_Check(nbOfComp)) + {//DataArrayByte.New([1,3,4,5],2,2) + int nbOfCompo=PyInt_AS_LONG(nbOfComp); + if(nbOfCompo<0) + throw INTERP_KERNEL::Exception("DataArrayByte::New : should be a positive number of components !"); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayByte::New(); + std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,nbOfCompo); + ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); + ret->incrRef(); + return ret; + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {//DataArrayByte.New([1,3,4],3) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayByte::New(); + int tmpp1=-1; + std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,tmpp1); + ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); + ret->incrRef(); + return ret; + } + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {// DataArrayByte.New([1,3,4]) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayByte::New(); + int tmpp1=-1,tmpp2=-1; + std::vector tmp=fillArrayWithPyListInt2(elt0,tmpp1,tmpp2); + ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); + ret->incrRef(); + return ret; + } + } + else if(PyInt_Check(elt0)) + { + int nbOfTuples1=PyInt_AS_LONG(elt0); + if(nbOfTuples1<0) + throw INTERP_KERNEL::Exception("DataArrayByte::New : should be a positive set of allocated memory !"); + if(nbOfTuples) + { + if(!nbOfComp) + { + if(PyInt_Check(nbOfTuples)) + {//DataArrayByte.New(5,2) + int nbOfCompo=PyInt_AS_LONG(nbOfTuples); + if(nbOfCompo<0) + throw INTERP_KERNEL::Exception("DataArrayByte::New : should be a positive number of components !"); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayByte::New(); + ret->alloc(nbOfTuples1,nbOfCompo); + ret->incrRef(); + return ret; + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {//DataArrayByte.New(5) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayByte::New(); + ret->alloc(nbOfTuples1,1); + ret->incrRef(); + return ret; + } + } + else + throw INTERP_KERNEL::Exception(msg); + } + + DataArrayByte(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) + { + return ParaMEDMEM_DataArrayByte_New__SWIG_1(elt0,nbOfTuples,nbOfComp); + } + + int __int__() const throw(INTERP_KERNEL::Exception) + { + return (int) self->byteValue(); + } + + DataArrayByteIterator *__iter__() throw(INTERP_KERNEL::Exception) + { + return self->iterator(); + } + + int getIJ(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception) + { + return (int)self->getIJ(tupleId,compoId); + } + + int getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception) + { + return (int)self->getIJSafe(tupleId,compoId); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->repr(); + } + + PyObject *toStrList() const throw(INTERP_KERNEL::Exception) + { + const char *vals=self->getConstPointer(); + int nbOfComp=self->getNumberOfComponents(); + int nbOfTuples=self->getNumberOfTuples(); + return convertCharArrToPyListOfTuple(vals,nbOfComp,nbOfTuples); + } + + bool presenceOfTuple(PyObject *tupl) const throw(INTERP_KERNEL::Exception) + { + int sz=-1,sw=-1; + int ival=-1; std::vector ivval; + const int *pt=convertObjToPossibleCpp1_Safe(tupl,sw,sz,ival,ivval); + std::vector vals(sz); + std::copy(pt,pt+sz,vals.begin()); + return self->presenceOfTuple(vals); + } + + bool presenceOfValue(PyObject *vals) const throw(INTERP_KERNEL::Exception) + { + int sz=-1,sw=-1; + int ival=-1; std::vector ivval; + const int *pt=convertObjToPossibleCpp1_Safe(vals,sw,sz,ival,ivval); + std::vector vals2(sz); + std::copy(pt,pt+sz,vals2.begin()); + return self->presenceOfValue(vals2); + } + + int locateValue(PyObject *vals) const throw(INTERP_KERNEL::Exception) + { + int sz=-1,sw=-1; + int ival=-1; std::vector ivval; + const int *pt=convertObjToPossibleCpp1_Safe(vals,sw,sz,ival,ivval); + std::vector vals2(sz); + std::copy(pt,pt+sz,vals2.begin()); + return self->locateValue(vals2); + } + + int locateTuple(PyObject *tupl) const throw(INTERP_KERNEL::Exception) + { + int sz=-1,sw=-1; + int ival=-1; std::vector ivval; + const int *pt=convertObjToPossibleCpp1_Safe(tupl,sw,sz,ival,ivval); + std::vector vals(sz); + std::copy(pt,pt+sz,vals.begin()); + return self->locateTuple(vals); + } + + int search(PyObject *strOrListOfInt) const throw(INTERP_KERNEL::Exception) + { + int sz=-1,sw=-1; + int ival=-1; std::vector ivval; + const int *pt=convertObjToPossibleCpp1_Safe(strOrListOfInt,sw,sz,ival,ivval); + std::vector vals(sz); + std::copy(pt,pt+sz,vals.begin()); + return self->search(vals); + } + + PyObject *getTuple(int tupleId) throw(INTERP_KERNEL::Exception) + { + int sz=self->getNumberOfComponents(); + INTERP_KERNEL::AutoPtr tmp=new char[sz]; + self->getTuple(tupleId,tmp); + PyObject *ret=PyTuple_New(sz); + for(int i=0;igetMaxValue(tmp); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyInt_FromLong(r1)); + PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); + return ret; + } + + PyObject *getMinValue() const throw(INTERP_KERNEL::Exception) + { + int tmp; + int r1=(int)self->getMinValue(tmp); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyInt_FromLong(r1)); + PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); + return ret; + } + + int index(PyObject *obj) const throw(INTERP_KERNEL::Exception) + { + int nbOfCompo=self->getNumberOfComponents(); + switch(nbOfCompo) + { + case 1: + { + if(PyInt_Check(obj)) + { + int val=(int)PyInt_AS_LONG(obj); + return self->locateValue(val); + } + else + throw INTERP_KERNEL::Exception("DataArrayByte::index : 'this' contains one component and trying to find an element which is not an integer !"); + } + default: + return ParaMEDMEM_DataArrayByte_locateTuple(self,obj); + } + } + + bool __contains__(PyObject *obj) const throw(INTERP_KERNEL::Exception) + { + int nbOfCompo=self->getNumberOfComponents(); + switch(nbOfCompo) + { + case 0: + return false; + case 1: + { + if(PyInt_Check(obj)) + { + int val=(int)PyInt_AS_LONG(obj); + return self->presenceOfValue(val); + } + else + throw INTERP_KERNEL::Exception("DataArrayByte::__contains__ : 'this' contains one component and trying to find an element which is not an integer !"); } + default: + return ParaMEDMEM_DataArrayByte_presenceOfTuple(self,obj); } - }; + } } -%extend ParaMEDMEM::DataArray +%extend ParaMEDMEM::DataArrayAsciiCharTuple { - PyObject *getInfoOnComponents() const throw(INTERP_KERNEL::Exception) - { - const std::vector& comps=self->getInfoOnComponents(); - PyObject *ret=PyList_New((int)comps.size()); - for(int i=0;i<(int)comps.size();i++) - PyList_SetItem(ret,i,PyString_FromString(comps[i].c_str())); - return ret; - } - - void copyPartOfStringInfoFrom(const DataArray& other, PyObject *li) throw(INTERP_KERNEL::Exception) + std::string __str__() const { - std::vector tmp; - convertPyToNewIntArr3(li,tmp); - self->copyPartOfStringInfoFrom(other,tmp); + return self->repr(); } - void copyPartOfStringInfoFrom2(PyObject *li, const DataArray& other) throw(INTERP_KERNEL::Exception) + DataArrayAsciiChar *buildDAAsciiChar() { - std::vector tmp; - convertPyToNewIntArr3(li,tmp); - self->copyPartOfStringInfoFrom2(tmp,other); + return self->buildDAAsciiChar(1,self->getNumberOfCompo()); } } -%extend ParaMEDMEM::DataArrayInt +%extend ParaMEDMEM::DataArrayAsciiCharIterator { - void pushBackValsSilent(PyObject *li) throw(INTERP_KERNEL::Exception) - { - int szArr,sw,iTypppArr; - std::vector stdvecTyyppArr; - const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); - self->pushBackValsSilent(tmp,tmp+szArr); - } - - PyObject *partitionByDifferentValues() const throw(INTERP_KERNEL::Exception) + PyObject *next() { - std::vector ret1; - std::vector ret0=self->partitionByDifferentValues(ret1); - std::size_t sz=ret0.size(); - PyObject *pyRet=PyTuple_New(2); - PyObject *pyRet0=PyList_New((int)sz); - PyObject *pyRet1=PyList_New((int)sz); - for(std::size_t i=0;inextt(); + if(ret) + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiCharTuple,SWIG_POINTER_OWN | 0); + else { - PyList_SetItem(pyRet0,i,SWIG_NewPointerObj(SWIG_as_voidptr(ret0[i]),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyList_SetItem(pyRet1,i,PyInt_FromLong(ret1[i])); + PyErr_SetString(PyExc_StopIteration,"No more data."); + return 0; } - PyTuple_SetItem(pyRet,0,pyRet0); - PyTuple_SetItem(pyRet,1,pyRet1); - return pyRet; } } +%extend ParaMEDMEM::DataArrayAsciiChar +{ + DataArrayAsciiChar() throw(INTERP_KERNEL::Exception) + { + return DataArrayAsciiChar::New(); + } + + static DataArrayAsciiChar *New(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) + { + const char *msg="ParaMEDMEM::DataArrayAsciiChar::New : Available API are : \n-DataArrayAsciiChar.New()\n--DataArrayAsciiChar.New([1,3,4])\n-DataArrayAsciiChar.New([1,3,4],3)\n-DataArrayAsciiChar.New([1,3,4,5],2,2)\n-DataArrayAsciiChar.New(5)\n-DataArrayAsciiChar.New(5,2) !"; + if(PyList_Check(elt0) || PyTuple_Check(elt0)) + { + if(nbOfTuples) + { + if(PyInt_Check(nbOfTuples)) + { + int nbOfTuples1=PyInt_AS_LONG(nbOfTuples); + if(nbOfTuples1<0) + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::New : should be a positive set of allocated memory !"); + if(nbOfComp) + { + if(PyInt_Check(nbOfComp)) + {//DataArrayAsciiChar.New([1,3,4,5],2,2) + int nbOfCompo=PyInt_AS_LONG(nbOfComp); + if(nbOfCompo<0) + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::New : should be a positive number of components !"); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayAsciiChar::New(); + std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,nbOfCompo); + ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); + ret->incrRef(); + return ret; + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {//DataArrayAsciiChar.New([1,3,4],3) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayAsciiChar::New(); + int tmpp1=-1; + std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,tmpp1); + ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); + ret->incrRef(); + return ret; + } + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {// DataArrayAsciiChar.New([1,3,4]) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayAsciiChar::New(); + int tmpp1=-1,tmpp2=-1; + std::vector tmp=fillArrayWithPyListInt2(elt0,tmpp1,tmpp2); + ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); + ret->incrRef(); + return ret; + } + } + else if(PyInt_Check(elt0)) + { + int nbOfTuples1=PyInt_AS_LONG(elt0); + if(nbOfTuples1<0) + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::New : should be a positive set of allocated memory !"); + if(nbOfTuples) + { + if(!nbOfComp) + { + if(PyInt_Check(nbOfTuples)) + {//DataArrayAsciiChar.New(5,2) + int nbOfCompo=PyInt_AS_LONG(nbOfTuples); + if(nbOfCompo<0) + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::New : should be a positive number of components !"); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayAsciiChar::New(); + ret->alloc(nbOfTuples1,nbOfCompo); + ret->incrRef(); + return ret; + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {//DataArrayAsciiChar.New(5) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayAsciiChar::New(); + ret->alloc(nbOfTuples1,1); + ret->incrRef(); + return ret; + } + } + else + throw INTERP_KERNEL::Exception(msg); + } + + DataArrayAsciiChar(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) + { + return ParaMEDMEM_DataArrayAsciiChar_New__SWIG_1(elt0,nbOfTuples,nbOfComp); + } + + DataArrayAsciiCharIterator *__iter__() throw(INTERP_KERNEL::Exception) + { + return self->iterator(); + } + + std::string getIJ(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception) + { + char tmp[2]; tmp[1]='\0'; + tmp[0]=self->getIJ(tupleId,compoId); + return std::string(tmp); + } + + std::string getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception) + { + char tmp[2]; tmp[1]='\0'; + tmp[0]=self->getIJSafe(tupleId,compoId); + return std::string(tmp); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->repr(); + } + + PyObject *toStrList() const throw(INTERP_KERNEL::Exception) + { + const char *vals=self->getConstPointer(); + int nbOfComp=self->getNumberOfComponents(); + int nbOfTuples=self->getNumberOfTuples(); + return convertCharArrToPyListOfTuple(vals,nbOfComp,nbOfTuples); + } + + bool presenceOfTuple(PyObject *tupl) const throw(INTERP_KERNEL::Exception) + { + if(PyString_Check(tupl)) + { + Py_ssize_t sz=PyString_Size(tupl); + std::vector vals(sz); + std::copy(PyString_AsString(tupl),PyString_AsString(tupl)+sz,vals.begin()); + return self->presenceOfTuple(vals); + } + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::presenceOfTuple : only strings in input supported !"); + } + + bool presenceOfValue(PyObject *vals) const throw(INTERP_KERNEL::Exception) + { + if(PyString_Check(vals)) + { + Py_ssize_t sz=PyString_Size(vals); + std::vector vals2(sz); + std::copy(PyString_AsString(vals),PyString_AsString(vals)+sz,vals2.begin()); + return self->presenceOfValue(vals2); + } + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::presenceOfValue : only strings in input supported !"); + } + + int locateValue(PyObject *vals) const throw(INTERP_KERNEL::Exception) + { + if(PyString_Check(vals)) + { + Py_ssize_t sz=PyString_Size(vals); + std::vector vals2(sz); + std::copy(PyString_AsString(vals),PyString_AsString(vals)+sz,vals2.begin()); + return self->locateValue(vals2); + } + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::locateValue : only strings in input supported !"); + } + + int locateTuple(PyObject *tupl) const throw(INTERP_KERNEL::Exception) + { + if(PyString_Check(tupl)) + { + Py_ssize_t sz=PyString_Size(tupl); + std::vector vals(sz); + std::copy(PyString_AsString(tupl),PyString_AsString(tupl)+sz,vals.begin()); + return self->locateTuple(vals); + } + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::locateTuple : only strings in input supported !"); + } + + int search(PyObject *strOrListOfInt) const throw(INTERP_KERNEL::Exception) + { + if(PyString_Check(strOrListOfInt)) + { + Py_ssize_t sz=PyString_Size(strOrListOfInt); + std::vector vals(sz); + std::copy(PyString_AsString(strOrListOfInt),PyString_AsString(strOrListOfInt)+sz,vals.begin()); + return self->search(vals); + } + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::search : only strings in input supported !"); + } + + PyObject *getTuple(int tupleId) throw(INTERP_KERNEL::Exception) + { + int sz=self->getNumberOfComponents(); + INTERP_KERNEL::AutoPtr tmp=new char[sz+1]; tmp[sz]='\0'; + self->getTuple(tupleId,tmp); + return PyString_FromString(tmp); + } + + PyObject *getMaxValue() const throw(INTERP_KERNEL::Exception) + { + int tmp; + char tmp2[2]; tmp2[1]='\0'; + tmp2[0]=self->getMaxValue(tmp); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyString_FromString(tmp2)); + PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); + return ret; + } + + PyObject *getMinValue() const throw(INTERP_KERNEL::Exception) + { + int tmp; + char tmp2[2]; tmp2[1]='\0'; + tmp2[0]=self->getMinValue(tmp); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyString_FromString(tmp2)); + PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); + return ret; + } + + int index(PyObject *obj) const throw(INTERP_KERNEL::Exception) + { + int nbOfCompo=self->getNumberOfComponents(); + switch(nbOfCompo) + { + case 1: + { + if(PyString_Check(obj)) + { + Py_ssize_t sz=PyString_Size(obj); + char *pt=PyString_AsString(obj); + if(sz==1) + return self->locateValue(pt[0]); + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::index : 'this' contains one component and trying to find a string with size different from 1 !"); + } + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::index : 'this' contains one component and trying to find an element which is not an integer !"); + } + default: + return ParaMEDMEM_DataArrayAsciiChar_locateTuple(self,obj); + } + } + + bool __contains__(PyObject *obj) const throw(INTERP_KERNEL::Exception) + { + int nbOfCompo=self->getNumberOfComponents(); + switch(nbOfCompo) + { + case 0: + return false; + case 1: + { + if(PyString_Check(obj)) + { + Py_ssize_t sz=PyString_Size(obj); + char *pt=PyString_AsString(obj); + if(sz==1) + return self->presenceOfValue(pt[0]); + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::__contains__ : 'this' contains one component and trying to find a string with size different from 1 !"); + } + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::__contains__ : 'this' contains one component and trying to find an element which is not an integer !"); + } + default: + return ParaMEDMEM_DataArrayAsciiChar_presenceOfTuple(self,obj); + } + } +} + %extend ParaMEDMEM::MEDCouplingFieldDiscretization { MEDCouplingFieldDiscretization *clonePart(PyObject *li) @@ -964,6 +1805,11 @@ namespace ParaMEDMEM %ignore ParaMEDMEM::DataArrayInt::partitionByDifferentValues; %ignore ParaMEDMEM::MEDCouplingFieldDiscretizationPerCell::getArrayOfDiscIds; %ignore ParaMEDMEM::MEDCouplingFieldDiscretization::clonePart; +%ignore ParaMEDMEM::DataArrayChar::getIJ; +%ignore ParaMEDMEM::DataArrayChar::getIJSafe; +%ignore ParaMEDMEM::DataArrayChar::search; +%ignore ParaMEDMEM::DataArrayChar::locateValue; +%ignore ParaMEDMEM::DataArrayChar::presenceOfValue; %include "MEDCouplingMemArray.hxx" %include "NormalizedUnstructuredMesh.hxx" @@ -1287,12 +2133,12 @@ namespace ParaMEDMEM INTERP_KERNEL::NormalizedCellType getType() const; %extend { - std::string __str__() const + std::string __str__() const throw(INTERP_KERNEL::Exception) { return self->repr(); } - PyObject *getAllConn() const + PyObject *getAllConn() const throw(INTERP_KERNEL::Exception) { int ret2; const int *r=self->getAllConn(ret2); @@ -1444,7 +2290,7 @@ namespace ParaMEDMEM return self->simpleRepr(); } - MEDCouplingUMeshCellIterator *__iter__() + MEDCouplingUMeshCellIterator *__iter__() throw(INTERP_KERNEL::Exception) { return self->cellIterator(); } @@ -2600,7 +3446,7 @@ namespace ParaMEDMEM %extend ParaMEDMEM::DataArrayDoubleTuple { - std::string __str__() const + std::string __str__() const throw(INTERP_KERNEL::Exception) { return self->repr(); } @@ -2973,7 +3819,7 @@ namespace ParaMEDMEM self->pushBackValsSilent(tmp,tmp+nbTuples); } - std::string __str__() const + std::string __str__() const throw(INTERP_KERNEL::Exception) { return self->repr(); } @@ -3046,9 +3892,9 @@ namespace ParaMEDMEM throw INTERP_KERNEL::Exception(msg); } - PyObject *getValues() throw(INTERP_KERNEL::Exception) + PyObject *getValues() const throw(INTERP_KERNEL::Exception) { - const double *vals=self->getPointer(); + const double *vals=self->getConstPointer(); return convertDblArrToPyList(vals,self->getNbOfElems()); } @@ -3064,9 +3910,9 @@ namespace ParaMEDMEM return ret; } - PyObject *getValuesAsTuple() throw(INTERP_KERNEL::Exception) + PyObject *getValuesAsTuple() const throw(INTERP_KERNEL::Exception) { - const double *vals=self->getPointer(); + const double *vals=self->getConstPointer(); int nbOfComp=self->getNumberOfComponents(); int nbOfTuples=self->getNumberOfTuples(); return convertDblArrToPyListOfTuple(vals,nbOfComp,nbOfTuples); @@ -4337,7 +5183,7 @@ namespace ParaMEDMEM %extend ParaMEDMEM::DataArrayIntTuple { - std::string __str__() const + std::string __str__() const throw(INTERP_KERNEL::Exception) { return self->repr(); } @@ -4347,7 +5193,7 @@ namespace ParaMEDMEM return self->intValue(); } - DataArrayInt *buildDAInt() + DataArrayInt *buildDAInt() throw(INTERP_KERNEL::Exception) { return self->buildDAInt(1,self->getNumberOfCompo()); } @@ -4724,7 +5570,7 @@ namespace ParaMEDMEM return ParaMEDMEM_DataArrayInt_New__SWIG_1(elt0,nbOfTuples,nbOfComp); } - std::string __str__() const + std::string __str__() const throw(INTERP_KERNEL::Exception) { return self->repr(); } @@ -4819,9 +5665,9 @@ namespace ParaMEDMEM throw INTERP_KERNEL::Exception(msg); } - PyObject *getValues() throw(INTERP_KERNEL::Exception) + PyObject *getValues() const throw(INTERP_KERNEL::Exception) { - const int *vals=self->getPointer(); + const int *vals=self->getConstPointer(); return convertIntArrToPyList(vals,self->getNbOfElems()); } @@ -4837,9 +5683,9 @@ namespace ParaMEDMEM return ret; } - PyObject *getValuesAsTuple() throw(INTERP_KERNEL::Exception) + PyObject *getValuesAsTuple() const throw(INTERP_KERNEL::Exception) { - const int *vals=self->getPointer(); + const int *vals=self->getConstPointer(); int nbOfComp=self->getNumberOfComponents(); int nbOfTuples=self->getNumberOfTuples(); return convertIntArrToPyListOfTuple(vals,nbOfComp,nbOfTuples); @@ -7240,7 +8086,7 @@ namespace ParaMEDMEM std::vector getHotSpotsTime() const; %extend { - std::string __str__() const + std::string __str__() const throw(INTERP_KERNEL::Exception) { std::ostringstream oss; self->appendRepr(oss); diff --git a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i index 7a1a8eb01..bcbe12ec6 100644 --- a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i @@ -17,6 +17,8 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +#include "InterpKernelAutoPtr.hxx" + #ifdef WITH_NUMPY2 #include #endif @@ -55,6 +57,18 @@ static PyObject *convertFieldDiscretization(ParaMEDMEM::MEDCouplingFieldDiscreti return ret; } +static PyObject *convertDataArrayChar(ParaMEDMEM::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception) +{ + PyObject *ret=0; + if(dynamic_cast(dac)) + ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner); + if(dynamic_cast(dac)) + ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner); + if(!ret) + throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !"); + return ret; +} + static PyObject* convertMultiFields(ParaMEDMEM::MEDCouplingMultiFields *mfs, int owner) throw(INTERP_KERNEL::Exception) { PyObject *ret=0; @@ -506,6 +520,18 @@ static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, return ret; } +static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception) +{ + PyObject *ret=PyList_New(nbOfTuples); + INTERP_KERNEL::AutoPtr tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0'; + for(int i=0;i