From: vsr Date: Tue, 19 Mar 2013 16:28:32 +0000 (+0000) Subject: Merge from V6_main 19/03/2013 X-Git-Tag: V7_1_0~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b08d2ffff57c24207d37d1a5c850df2852490b9a;p=modules%2Fmed.git Merge from V6_main 19/03/2013 --- diff --git a/doc/doxygen/fakesources/MEDCouplingMemArray.C b/doc/doxygen/fakesources/MEDCouplingMemArray.C index 977a3a15b..24654aca1 100644 --- a/doc/doxygen/fakesources/MEDCouplingMemArray.C +++ b/doc/doxygen/fakesources/MEDCouplingMemArray.C @@ -1,12 +1,7 @@ -// This file contains some code used for +// This file contains some code used only for // 1) generation of documentation for inline methods of array classes // 2) grouping all methods into 3 lists" "Basic API", "Advanced API" and "Others..." -/* class ParaMEDMEM::DataArray - * @defgroup basic_api Basic API - * @defgroup adv_api Advanced API - */ - namespace ParaMEDMEM { /*! @@ -290,7 +285,6 @@ DataArrayDouble::back() const; DataArrayDouble::getIJSafe(int tupleId, int compoId) const; DataArrayDouble::setIJ(int tupleId, int compoId, double newVal); DataArrayDouble::setIJSilent(int tupleId, int compoId, double newVal); -DataArrayDouble::useExternalArrayWithRWAccess(const double* array, int nbOfTuple, int nbOfCompo); DataArrayDouble::writeOnPlace(int id, double element0, const double* others, int sizeOfOthers); DataArrayDouble::checkNoNullValues() const; DataArrayDouble::getMinMaxPerComponent(double* bounds) const; @@ -385,6 +379,7 @@ DataArrayDouble::getConstPointer() const; DataArrayDouble::begin() const; DataArrayDouble::end() const; DataArrayDouble::useArray(const double* array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo); +DataArrayDouble::useExternalArrayWithRWAccess(const double* array, int nbOfTuple, int nbOfCompo); DataArrayDouble::insertAtTheEnd(InputIterator first, InputIterator last); DataArrayDouble::computeBBoxPerTuple(double epsilon=0.0) const; DataArrayDouble::computeTupleIdsNearTuples(const DataArrayDouble* other, double eps, DataArrayInt *& c, DataArrayInt *& cI) const; diff --git a/doc/doxygen/fakesources/MEDCouplingPointSet.C b/doc/doxygen/fakesources/MEDCouplingPointSet.C new file mode 100644 index 000000000..b68734d38 --- /dev/null +++ b/doc/doxygen/fakesources/MEDCouplingPointSet.C @@ -0,0 +1,30 @@ +// This file contains some code used only for +// * generation of documentation for inline methods of MEDCouplingPointSet + +namespace ParaMEDMEM +{ + + /*! + * Tries to use a coordinates array of \a other mesh for \a this one. If all nodes + * of \a this mesh coincide, within a specified precision, with some nodes of \a + * other mesh, then \a this mesh refers to the coordinates array of the \a other mesh, + * i.e. \a this->_coords = \a other._coords. Otherwise an exception is thrown and \a + * this remains unchanged. + * \param [in] other - the other mesh. + * \param [in] epsilon - the precision to compare node coordinates of the two meshes. + * \throw If the coordinates array of \a this is not set. + * \throw If the coordinates array of \a other is not set. + * \throw If not all nodes of \a this mesh are present in the \a other mesh. + */ + void MEDCouplingPointSet::tryToShareSameCoordsPermute(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception) {} + + //! This method returns directly the array in \a this \b without incrementing ref counter. The pointer is dealed by the mesh. The caller should not deal (decrRef) with this pointer + const DataArrayDouble *MEDCouplingPointSet::getCoords() const { return _coords; } + + //! This method returns directly the array in \a this \b without incrementing ref counter. The pointer is dealed by the mesh. The caller should not deal (decrRef) with this pointer + DataArrayDouble *MEDCouplingPointSet::getCoords() { return _coords; } + + + //! size of returned tinyInfo must be always the same. + void MEDCouplingPointSet::getTinySerializationInformation(std::vector& tinyInfoD, std::vector& tinyInfo, std::vector& littleStrings) const {} +} diff --git a/doc/doxygen/medcouplingexamples.doxy b/doc/doxygen/medcouplingexamples.doxy index bd0ee8f68..a049bca48 100644 --- a/doc/doxygen/medcouplingexamples.doxy +++ b/doc/doxygen/medcouplingexamples.doxy @@ -1,15 +1,128 @@ /*! -\page medcouplingcppexamples

MEDCoupling C++ examples

+\page medcouplingcppexamples MEDCoupling C++ examples -\anchor cpp_mcdataarrayint_ +\anchor cpp_mcpointset_

-\snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayInt_ -\snippet MEDCouplingExamplesTest.py PySnippet_DataArrayInt_ -\snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_ +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_ +\snippet MEDCouplingExamplesTest.py PySnippet_MEDCouplingPointSet_ +\snippet MEDCouplingExamplesTest.py Snippet_MEDCouplingPointSet_ +\anchor cpp_mcpointset_scale +

Scaling the mesh

+ +First, we create a 2D mesh with 4 nodes and no cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_scale_1 +Then we scale it by a factor of 2 with a center (0.,0.). +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_scale_2 +Finally we check that all node coordinates have changed by more than 0.9. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_scale_3 + + + + +\anchor cpp_mcpointset_translate +

Translating the mesh

+ +First, we create a 2D mesh with 4 nodes and no cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_translate_1 +Then we translate it by a vector (1.,1.). +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_translate_2 +Finally we check that all node coordinates have changed by more than 0.9. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_translate_3 + + + +\anchor cpp_mcpointset_rotate +

Rotating the mesh

+ +First, we create a 2D mesh with 4 nodes and no cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_rotate_1 +Then we rotate it around a point (0.,0.) by 90 degrees clockwise. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_rotate_2 +Next, we make a 3D mesh from the 2D one and rotate it around the Z axis by 90 degrees +counter-clockwise. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_rotate_3 +Finally we transform the mesh back to 2D space and check that all nodes get back to the +initial location. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_rotate_4 + +\anchor cpp_mcpointset_getBoundingBox +

Getting a minimum box bounding nodes

+ +First, we create a 3D mesh with 2 nodes, so that the first one has minimal coordinates and +the second one has maximal coordinates. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_getBoundingBox_1 +Now we get a bounding box enclosing these nodes. This bounding box should contain +coordinates of our two nodes (but in "no interlace" mode), as the nodes coincide with +points returned by the bounding box. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_getBoundingBox_2 + + +\anchor cpp_mcpointset_getnodeidsnearpoint +

Getting nodes close to a point

+ +The following code creates a 2D \ref ParaMEDMEM::MEDCouplingUMesh +"MEDCouplingUMesh" with 5 nodes and no cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_1 +Now we define an array of coordinates of a point close to nodes #0, #2 and #4. + +Thus we expect that +\ref ParaMEDMEM::MEDCouplingPointSet::getNodeIdsNearPoint "getNodeIdsNearPoint()" that +we are going to use, +if called with \b eps = 0.003, would return ids of nodes #0, #2 and #4. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_2 + + +\anchor cpp_mcpointset_getnodeidsnearpoints +

Getting nodes close to some points

+ +The following code creates a 2D \ref ParaMEDMEM::MEDCouplingUMesh +"MEDCouplingUMesh" with 7 nodes and no cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_1 +Now we define an array of coordinates of 3 points near which we want to find nodes of the mesh. +- Point #0 is at distance 0.001 from the node #1. +- Point #1 is rather far from all nodes. +- Point #2 is close to nodes #3, #4 and #5. + +Thus we expect that +\ref ParaMEDMEM::MEDCouplingPointSet::getNodeIdsNearPoints "getNodeIdsNearPoints()" that +we are going to use, +if called with \b eps = 0.003, would return ids of close nodes #1, #3, #4 and #5. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_2 +\b idsIndex returns [0, 1, 1, 4] which means that: +- Point #0 is close to 1 (== \b idsIndex[1] - \b idsIndex[0]) node whose id is +\b ids[ \b idsIndex[ 0 ]]. +- Point #1 is close to 0 (== \b idsIndex[2] - \b idsIndex[1]) nodes. +- Point #2 is close to 3 (== \b idsIndex[3] - \b idsIndex[2]) nodes whose ids are +\b ids[ \b idsIndex[ 2 ]], \b ids[ \b idsIndex[ 2 ] + 1 ] and \b ids[ \b idsIndex[ 2 ] + 2 ]. + + +\anchor cpp_mcpointset_findcommonnodes +

Finding coincident nodes

+ +First, we create a mesh with 6 nodes, of which two nodes (#3 and #4) are fully coincident +and 3 nodes (#0, #2 and #5) have distance less than 0.004 between them. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_findCommonNodes_1 +Then, we use \ref ParaMEDMEM::MEDCouplingPointSet::findCommonNodes() "findCommonNodes()" to find +coincident nodes, and check that (1) calling +\ref ParaMEDMEM::MEDCouplingPointSet::findCommonNodes() "findCommonNodes()" with \b prec +== 1e-13 finds the two fully coincident nodes only and (2) +\ref ParaMEDMEM::MEDCouplingPointSet::findCommonNodes() "findCommonNodes"(0.004) finds 5 +equal nodes. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_findCommonNodes_2 + +\anchor cpp_mcpointset_getcoordinatesofnode +

Getting coordinates of a node

+ +The following code creates a 2D \ref ParaMEDMEM::MEDCouplingUMesh +"MEDCouplingUMesh" with 3 nodes and no cells. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_1 +Here we get coordinates of the second node and check its two coordinates. +\snippet MEDCouplingExamplesTest.cxx CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_2 + \anchor cpp_mcdataarrayint_getTuple

Getting a tuple of DataArrayInt

diff --git a/src/MEDCoupling/CMakeLists.txt b/src/MEDCoupling/CMakeLists.txt index a8d57ffb9..23e624b5a 100644 --- a/src/MEDCoupling/CMakeLists.txt +++ b/src/MEDCoupling/CMakeLists.txt @@ -34,6 +34,7 @@ SET(medcoupling_SOURCES MEDCouplingFieldDouble.cxx MEDCouplingUMesh.cxx MEDCouplingMemArray.cxx + MEDCouplingMemArrayChar.cxx MEDCouplingTimeLabel.cxx MEDCouplingCMesh.cxx MEDCouplingCurveLinearMesh.cxx diff --git a/src/MEDCoupling/MEDCouplingField.cxx b/src/MEDCoupling/MEDCouplingField.cxx index 527ff74e4..4d75b20eb 100644 --- a/src/MEDCoupling/MEDCouplingField.cxx +++ b/src/MEDCoupling/MEDCouplingField.cxx @@ -45,7 +45,7 @@ bool MEDCouplingField::isEqualIfNotWhy(const MEDCouplingField *other, double mes } if(_nature!=other->_nature) { - oss << "Field nature differ : this nature = \"" << MEDCouplingNatureOfField::getRepr(_nature) << "\" and other nature = \"" << MEDCouplingNatureOfField::getRepr(other->_nature) << "\" !"; + oss << "Field nature differ : this nature = \"" << MEDCouplingNatureOfField::GetRepr(_nature) << "\" and other nature = \"" << MEDCouplingNatureOfField::GetRepr(other->_nature) << "\" !"; reason=oss.str(); return false; } diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index fd0cb1740..95206301a 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -214,7 +214,7 @@ std::string MEDCouplingFieldDouble::simpleRepr() const ret << "Description of field is : \"" << getDescription() << "\"\n"; ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; - ret << "FieldDouble nature of field is : " << MEDCouplingNatureOfField::getRepr(_nature) << "\n"; + ret << "FieldDouble nature of field is : " << MEDCouplingNatureOfField::GetRepr(_nature) << "\n"; if(getArray()) { int nbOfCompo=getArray()->getNumberOfComponents(); diff --git a/src/MEDCoupling/MEDCouplingFieldTemplate.cxx b/src/MEDCoupling/MEDCouplingFieldTemplate.cxx index a94b6700a..e15615a90 100644 --- a/src/MEDCoupling/MEDCouplingFieldTemplate.cxx +++ b/src/MEDCoupling/MEDCouplingFieldTemplate.cxx @@ -62,7 +62,7 @@ std::string MEDCouplingFieldTemplate::simpleRepr() const ret << "FieldTemplate with name : \"" << getName() << "\"\n"; ret << "Description of field is : \"" << getDescription() << "\"\n"; ret << "FieldTemplate space discretization is : " << _type->getStringRepr() << "\n"; - ret << "FieldTemplate nature of field is : " << MEDCouplingNatureOfField::getRepr(_nature) << "\n"; + ret << "FieldTemplate nature of field is : " << MEDCouplingNatureOfField::GetRepr(_nature) << "\n"; if(_mesh) ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr(); else diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 1e87420cc..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(); @@ -1063,7 +1063,16 @@ void DataArrayDouble::reprCppStream(const char *varName, std::ostream& stream) c stream << varName << "->setName(\"" << getName() << "\");" << std::endl; } -bool DataArrayDouble::isEqualIfNotWhy(const DataArrayDouble& other, double prec, std::string& reason) const +/*! + * Equivalent to DataArrayDouble::isEqual except that if false the reason of + * mismatch is given. + * + * \param [in] other the instance to be compared with \a this + * \param [in] prec the precision to compare numeric data of the arrays. + * \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 throw(INTERP_KERNEL::Exception) { if(!areInfoEqualsIfNotWhy(other,reason)) return false; @@ -1077,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); @@ -1090,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); @@ -1175,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(); @@ -1199,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(); @@ -1225,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(); @@ -1238,7 +1247,7 @@ DataArrayDouble *DataArrayDouble::renumber(const int *old2New) const for(int i=0;icopyStringInfoFrom(*this); - return ret; + return ret.retn(); } /*! @@ -1252,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(); @@ -1265,7 +1274,7 @@ DataArrayDouble *DataArrayDouble::renumberR(const int *new2Old) const for(int i=0;icopyStringInfoFrom(*this); - return ret; + return ret.retn(); } /*! @@ -1281,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(); @@ -1297,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(); } /*! @@ -1521,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(); @@ -1540,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(); } /*! @@ -1678,7 +1687,6 @@ void DataArrayDouble::meldWith(const DataArrayDouble *other) throw(INTERP_KERNEL * [ \a commIndex[1], \a commIndex[2] ). \a commIndex->getNumberOfTuples()-1 * gives the number of groups of coincident tuples. * \throw If \a this is not allocated. - * \throw If \a this and \a other arrays have different number of tuples. * \throw If the number of components is not in [1,2,3]. * * \ref cpp_mcdataarraydouble_findcommontuples "Here is a C++ example". @@ -2591,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); @@ -3892,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); } @@ -3917,15 +3925,12 @@ DataArrayInt *DataArrayDouble::getIdsInRange(double vmin, double vmax) const thr if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayDouble::getIdsInRange : this must have exactly one component !"); const double *cptr=getConstPointer(); - std::vector res; + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(0,1); int nbOfTuples=getNumberOfTuples(); for(int i=0;i=vmin && *cptr<=vmax) - res.push_back(i); - DataArrayInt *ret=DataArrayInt::New(); - ret->alloc((int)res.size(),1); - std::copy(res.begin(),res.end(),ret->getPointer()); - return ret; + ret->pushBackSilent(i); + return ret.retn(); } /*! @@ -3979,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(); } /*! @@ -4912,7 +4917,7 @@ DataArrayDoubleIterator::~DataArrayDoubleIterator() _da->decrRef(); } -DataArrayDoubleTuple *DataArrayDoubleIterator::nextt() +DataArrayDoubleTuple *DataArrayDoubleIterator::nextt() throw(INTERP_KERNEL::Exception) { if(_tuple_id<_nb_tuple) { @@ -4930,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++) @@ -4982,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; } @@ -5088,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); } @@ -5100,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(); @@ -5231,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()) { @@ -5308,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); @@ -5332,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(); @@ -5559,9 +5564,8 @@ DataArrayInt *DataArrayInt::transformWithIndArrR(const int *indArrBg, const int * The caller is to delete this result array using decrRef() as it is no more * needed. * - * \ref cpp_mcdataarrayint_invertarrayo2n2n2o "Here is a C++ example". - * - * \ref py_mcdataarrayint_invertarrayo2n2n2o "Here is a Python example". + * \ref cpp_mcdataarrayint_invertarrayo2n2n2o "Here is a C++ example".
+ * \ref py_mcdataarrayint_invertarrayo2n2n2o "Here is a Python example". */ DataArrayInt *DataArrayInt::invertArrayO2N2N2O(int newNbOfElem) const { @@ -5621,7 +5625,15 @@ DataArrayInt *DataArrayInt::invertArrayN2O2O2N(int oldNbOfElem) const return ret.retn(); } -bool DataArrayInt::isEqualIfNotWhy(const DataArrayInt& other, std::string& reason) const +/*! + * Equivalent to DataArrayInt::isEqual except that if false the reason of + * mismatch is given. + * + * \param [in] other the instance to be compared with \a this + * \param [out] reason In case of inequality returns the reason. + * \sa DataArrayInt::isEqual + */ +bool DataArrayInt::isEqualIfNotWhy(const DataArrayInt& other, std::string& reason) const throw(INTERP_KERNEL::Exception) { if(!areInfoEqualsIfNotWhy(other,reason)) return false; @@ -5634,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); @@ -5646,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); @@ -5867,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); @@ -5932,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(); @@ -5956,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(); @@ -5982,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(); @@ -5995,7 +6007,7 @@ DataArrayInt *DataArrayInt::renumber(const int *old2New) const for(int i=0;icopyStringInfoFrom(*this); - return ret; + return ret.retn(); } /*! @@ -6009,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(); @@ -6022,7 +6034,7 @@ DataArrayInt *DataArrayInt::renumberR(const int *new2Old) const for(int i=0;icopyStringInfoFrom(*this); - return ret; + return ret.retn(); } /*! @@ -6038,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(); @@ -6054,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(); } /*! @@ -6591,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(); @@ -6610,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(); } /*! @@ -7389,7 +7401,7 @@ void DataArrayInt::SetArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet) } } -DataArrayIntIterator *DataArrayInt::iterator() +DataArrayIntIterator *DataArrayInt::iterator() throw(INTERP_KERNEL::Exception) { return new DataArrayIntIterator(this); } @@ -7751,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(); } /*! @@ -7980,15 +7992,12 @@ DataArrayInt *DataArrayInt::getIdsInRange(int vmin, int vmax) const throw(INTERP if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayInt::getIdsInRange : this must have exactly one component !"); const int *cptr=getConstPointer(); - std::vector res; + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(0,1); int nbOfTuples=getNumberOfTuples(); for(int i=0;i=vmin && *cptralloc((int)res.size(),1); - std::copy(res.begin(),res.end(),ret->getPointer()); - return ret; + ret->pushBackSilent(i); + return ret.retn(); } /*! @@ -9679,7 +9688,7 @@ DataArrayIntIterator::~DataArrayIntIterator() _da->decrRef(); } -DataArrayIntTuple *DataArrayIntIterator::nextt() +DataArrayIntTuple *DataArrayIntIterator::nextt() throw(INTERP_KERNEL::Exception) { if(_tuple_id<_nb_tuple) { @@ -9696,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 7f52b8ff0..00c5d4e43 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -68,6 +68,7 @@ namespace ParaMEDMEM T& operator[](int id) { return _pointer.getPointer()[id]; } bool isEqual(const MemArray& other, T prec, std::string& reason) const; void repr(int sl, std::ostream& stream) const; + bool reprHeader(int sl, std::ostream& stream) const; void reprZip(int sl, std::ostream& stream) const; void fillWithValue(const T& val); T *fromNoInterlace(int nbOfComp) const; @@ -105,23 +106,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 +132,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 +159,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 +186,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 +233,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 +338,7 @@ namespace ParaMEDMEM public: DataArrayDoubleIterator(DataArrayDouble *da); ~DataArrayDoubleIterator(); - DataArrayDoubleTuple *nextt(); + DataArrayDoubleTuple *nextt() throw(INTERP_KERNEL::Exception); private: DataArrayDouble *_da; double *_pt; @@ -347,7 +351,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 +368,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 +402,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 +421,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 +454,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 +515,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); - void MEDCOUPLING_EXPORT 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 +552,7 @@ namespace ParaMEDMEM public: DataArrayIntIterator(DataArrayInt *da); ~DataArrayIntIterator(); - DataArrayIntTuple *nextt(); + DataArrayIntTuple *nextt() throw(INTERP_KERNEL::Exception); private: DataArrayInt *_da; int *_pt; @@ -561,7 +565,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,6 +576,207 @@ namespace ParaMEDMEM int _nb_of_compo; }; + class DataArrayChar : public DataArray + { + public: + 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 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 getHashCode() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT bool empty() const throw(INTERP_KERNEL::Exception); + 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 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) 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 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 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); + MEDCOUPLING_EXPORT void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayChar *changeNbOfComponents(int newNbOfComp, char dftValue) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayChar *keepSelectedComponents(const std::vector& compoIds) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void meldWith(const DataArrayChar *other) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void setPartOfValues1(const DataArrayChar *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare=true) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void setPartOfValuesSimple1(char a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void setPartOfValues2(const DataArrayChar *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare=true) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void setPartOfValuesSimple2(char a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void setPartOfValues3(const DataArrayChar *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare=true) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void setPartOfValuesSimple3(char a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void setPartOfValues4(const DataArrayChar *a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp, bool strictCompoCompare=true) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void setPartOfValuesSimple4(char a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void setPartOfValuesAdv(const DataArrayChar *a, const DataArrayChar *tuplesSelec) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void getTuple(int tupleId, char *res) const { std::copy(_mem.getConstPointerLoc(tupleId*((int)_info_on_compo.size())),_mem.getConstPointerLoc((tupleId+1)*((int)_info_on_compo.size())),res); } + MEDCOUPLING_EXPORT char getIJ(int tupleId, int compoId) const { return _mem[tupleId*((int)_info_on_compo.size())+compoId]; } + MEDCOUPLING_EXPORT char getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT char back() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void setIJ(int tupleId, int compoId, char newVal) { _mem[tupleId*((int)_info_on_compo.size())+compoId]=newVal; declareAsNew(); } + 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 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); + MEDCOUPLING_EXPORT char getMaxValueInArray() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT char getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT char getMinValueInArray() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *getIdsInRange(char vmin, char vmax) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static DataArrayChar *Aggregate(const DataArrayChar *a1, const DataArrayChar *a2); + 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) 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); + protected: + DataArrayChar() { } + 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 static DataArrayAsciiChar *New(const std::string& st) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static DataArrayAsciiChar *New(const std::vector& vst, char defaultChar) throw(INTERP_KERNEL::Exception); + 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() { } + DataArrayAsciiChar(const std::string& st) throw(INTERP_KERNEL::Exception); + DataArrayAsciiChar(const std::vector& vst, char defaultChar) throw(INTERP_KERNEL::Exception); + }; + + class DataArrayAsciiCharTuple; + + class MEDCOUPLING_EXPORT DataArrayAsciiCharIterator + { + public: + DataArrayAsciiCharIterator(DataArrayAsciiChar *da); + ~DataArrayAsciiCharIterator(); + DataArrayAsciiCharTuple *nextt() throw(INTERP_KERNEL::Exception); + private: + DataArrayAsciiChar *_da; + char *_pt; + int _tuple_id; + int _nb_comp; + int _nb_tuple; + }; + + class MEDCOUPLING_EXPORT DataArrayAsciiCharTuple + { + public: + 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 asciiCharValue() const throw(INTERP_KERNEL::Exception); + DataArrayAsciiChar *buildDAAsciiChar(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception); + private: + char *_pt; + int _nb_of_compo; + }; + template void DataArrayDouble::insertAtTheEnd(InputIterator first, InputIterator last) throw(INTERP_KERNEL::Exception) { diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index 35404431b..5dddb27b6 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -167,12 +167,13 @@ namespace ParaMEDMEM } return true; } - + /*! * \param [in] sl is typically the number of components + * \return True if a not null pointer is present, False if not. */ template - void MemArray::repr(int sl, std::ostream& stream) const + bool MemArray::reprHeader(int sl, std::ostream& stream) const { stream << "Number of tuples : "; if(!_pointer.isNull()) @@ -186,9 +187,21 @@ namespace ParaMEDMEM stream << "No data"; stream << "\n"; stream << "Data content :\n"; - const T *data=getConstPointer(); - if(!_pointer.isNull()) + bool ret=!_pointer.isNull(); + if(!ret) + stream << "No data !\n"; + return ret; + } + + /*! + * \param [in] sl is typically the number of components + */ + template + void MemArray::repr(int sl, std::ostream& stream) const + { + if(reprHeader(sl,stream)) { + const T *data=getConstPointer(); if(_nb_of_elem!=0 && sl!=0) { int nbOfTuples=_nb_of_elem/sl; @@ -203,8 +216,6 @@ namespace ParaMEDMEM else stream << "Empty Data\n"; } - else - stream << "No data !\n"; } /*! diff --git a/src/MEDCoupling/MEDCouplingMemArrayChar.cxx b/src/MEDCoupling/MEDCouplingMemArrayChar.cxx new file mode 100644 index 000000000..e52d0cafa --- /dev/null +++ b/src/MEDCoupling/MEDCouplingMemArrayChar.cxx @@ -0,0 +1,2172 @@ +// Copyright (C) 2007-2012 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (CEA/DEN) + +#include "MEDCouplingMemArray.txx" +#include "MEDCouplingAutoRefCountObjectPtr.hxx" + +#include +#include +#include +#include +#include +#include + +using namespace ParaMEDMEM; + +/*! + * 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 throw(INTERP_KERNEL::Exception) +{ + return getConstPointer()!=0; +} + +/*! + * Checks if raw data is allocated and throws an exception if it is not the case. + * \throw If the raw data is not allocated. + */ +void DataArrayChar::checkAllocated() const throw(INTERP_KERNEL::Exception) +{ + if(!isAllocated()) + throw INTERP_KERNEL::Exception("DataArrayChar::checkAllocated : Array is defined but not allocated ! Call alloc or setValues method first !"); +} + +std::size_t DataArrayChar::getHeapMemorySize() const +{ + std::size_t sz=(std::size_t)_mem.getNbOfElemAllocated(); + return DataArray::getHeapMemorySize()+sz; +} + +/*! + * Sets information on all components. This method can change number of components + * at certain conditions; if the conditions are not respected, an exception is thrown. + * The number of components can be changed provided that \a this is not allocated. + * + * To know more on format of the component information see + * \ref MEDCouplingArrayBasicsCompoName "DataArrays infos". + * \param [in] info - a vector of component infos. + * \throw If \a this->getNumberOfComponents() != \a info.size() && \a this->isAllocated() + */ +void DataArrayChar::setInfoAndChangeNbOfCompo(const std::vector& info) throw(INTERP_KERNEL::Exception) +{ + if(getNumberOfComponents()!=(int)info.size()) + { + if(!isAllocated()) + _info_on_compo=info; + else + { + std::ostringstream oss; oss << "DataArrayChar::setInfoAndChangeNbOfCompo : input is of size " << info.size() << " whereas number of components is equal to " << getNumberOfComponents() << " and this is already allocated !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + else + _info_on_compo=info; +} + +/*! + * Returns an integer value characterizing \a this array, which is useful for a quick + * comparison of many instances of DataArrayInt. + * \return int - the hash value. + * \throw If \a this is not allocated. + */ +int DataArrayChar::getHashCode() const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + int nbOfElems=getNbOfElems(); + int ret=nbOfElems*65536; + int delta=3; + if(nbOfElems>48) + delta=nbOfElems/8; + int ret0=0; + const char *pt=begin(); + for(int i=0;ialloc(getNumberOfTuples(),getNumberOfComponents()); + int nbOfVals=getNbOfElems(); + const char *src=getConstPointer(); + int *dest=ret->getPointer(); + std::copy(src,src+nbOfVals,dest); + ret->copyStringInfoFrom(*this); + return ret; +} + +/*! + * Permutes values of \a this array as required by \a old2New array. The values are + * permuted so that \c new[ \a old2New[ i ]] = \c old[ i ]. Number of tuples remains + * the same as in \this one. + * If a permutation reduction is needed, substr() or selectByTupleId() should be used. + * For more info on renumbering see \ref MEDCouplingArrayRenumbering. + * \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) throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + int nbTuples=getNumberOfTuples(); + int nbOfCompo=getNumberOfComponents(); + char *tmp=new char[nbTuples*nbOfCompo]; + const char *iptr=getConstPointer(); + for(int i=0;igetNumberOfTuples() + * giving a previous position of i-th new value. + */ +void DataArrayChar::renumberInPlaceR(const int *new2Old) throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + int nbTuples=getNumberOfTuples(); + int nbOfCompo=getNumberOfComponents(); + char *tmp=new char[nbTuples*nbOfCompo]; + const char *iptr=getConstPointer(); + for(int i=0;igetNumberOfTuples() + * giving a new position for i-th old value. + * \return DataArrayChar * - the new instance of DataArrayChar that the caller + * 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 throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + int nbTuples=getNumberOfTuples(); + int nbOfCompo=getNumberOfComponents(); + MEDCouplingAutoRefCountObjectPtr ret=buildEmptySpecializedDAChar(); + ret->alloc(nbTuples,nbOfCompo); + ret->copyStringInfoFrom(*this); + const char *iptr=getConstPointer(); + char *optr=ret->getPointer(); + for(int i=0;icopyStringInfoFrom(*this); + return ret.retn(); +} + +/*! + * Returns a copy of \a this array with values permuted as required by \a new2Old array. + * The values are permuted so that \c new[ i ] = \c old[ \a new2Old[ i ]]. Number of + * tuples in the result array remains the same as in \this one. + * If a permutation reduction is needed, substr() or selectByTupleId() should be used. + * For more info on renumbering see \ref MEDCouplingArrayRenumbering. + * \param [in] new2Old - C array of length equal to \a this->getNumberOfTuples() + * giving a previous position of i-th new value. + * \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 throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + int nbTuples=getNumberOfTuples(); + int nbOfCompo=getNumberOfComponents(); + MEDCouplingAutoRefCountObjectPtr ret=buildEmptySpecializedDAChar(); + ret->alloc(nbTuples,nbOfCompo); + ret->copyStringInfoFrom(*this); + const char *iptr=getConstPointer(); + char *optr=ret->getPointer(); + for(int i=0;icopyStringInfoFrom(*this); + return ret.retn(); +} + +/*! + * Returns a shorten and permuted copy of \a this array. The new DataArrayChar is + * of size \a newNbOfTuple and it's values are permuted as required by \a old2New array. + * The values are permuted so that \c new[ \a old2New[ i ]] = \c old[ i ] for all + * \a old2New[ i ] >= 0. In other words every i-th tuple in \a this array, for which + * \a old2New[ i ] is negative, is missing from the result array. + * For more info on renumbering see \ref MEDCouplingArrayRenumbering. + * \param [in] old2New - C array of length equal to \a this->getNumberOfTuples() + * giving a new position for i-th old tuple and giving negative position for + * for i-th old tuple that should be omitted. + * \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 throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + int nbTuples=getNumberOfTuples(); + int nbOfCompo=getNumberOfComponents(); + MEDCouplingAutoRefCountObjectPtr ret=buildEmptySpecializedDAChar(); + ret->alloc(newNbOfTuple,nbOfCompo); + const char *iptr=getConstPointer(); + char *optr=ret->getPointer(); + for(int i=0;i=0) + std::copy(iptr+i*nbOfCompo,iptr+(i+1)*nbOfCompo,optr+w*nbOfCompo); + } + ret->copyStringInfoFrom(*this); + return ret.retn(); +} + +/*! + * Returns a shorten and permuted copy of \a this array. The new DataArrayChar is + * of size \a new2OldEnd - \a new2OldBg and it's values are permuted as required by + * \a new2OldBg array. + * The values are permuted so that \c new[ i ] = \c old[ \a new2OldBg[ i ]]. + * This method is equivalent to renumberAndReduce() except that convention in input is + * \c new2old and \b not \c old2new. + * This method is equivalent to selectByTupleId() except that it prevents coping data + * from behind the end of \a this array. + * For more info on renumbering see \ref MEDCouplingArrayRenumbering. + * \param [in] new2OldBg - pointer to the beginning of a permutation array that gives a + * tuple index in \a this array to fill the i-th tuple in the new array. + * \param [in] new2OldEnd - specifies the end of the permutation array that starts at + * \a new2OldBg, so that pointer to a tuple index (\a pi) varies as this: + * \a new2OldBg <= \a pi < \a new2OldEnd. + * \return DataArrayChar * - the new instance of DataArrayChar that the caller + * is to delete using decrRef() as it is no more needed. + * \throw If \a new2OldEnd - \a new2OldBg > \a this->getNumberOfTuples(). + */ +DataArrayChar *DataArrayChar::selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + MEDCouplingAutoRefCountObjectPtr ret=buildEmptySpecializedDAChar(); + int nbComp=getNumberOfComponents(); + int oldNbOfTuples=getNumberOfTuples(); + ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp); + ret->copyStringInfoFrom(*this); + char *pt=ret->getPointer(); + const char *srcPt=getConstPointer(); + int i=0; + for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++) + if(*w>=0 && *wgetNumberOfTuples) !"); + ret->copyStringInfoFrom(*this); + return ret.retn(); +} + +/*! + * Returns a shorten copy of \a this array. The new DataArrayChar contains every + * (\a bg + \c i * \a step)-th tuple of \a this array located before the \a end2-th + * tuple. Indices of the selected tuples are the same as ones returned by the Python + * command \c range( \a bg, \a end2, \a step ). + * This method is equivalent to selectByTupleIdSafe() except that the input array is + * not constructed explicitly. + * For more info on renumbering see \ref MEDCouplingArrayRenumbering. + * \param [in] bg - index of the first tuple to copy from \a this array. + * \param [in] end2 - index of the tuple before which the tuples to copy are located. + * \param [in] step - index increment to get index of the next tuple to copy. + * \return DataArrayChar * - the new instance of DataArrayChar that the caller + * is to delete using decrRef() as it is no more needed. + * \throw If (\a end2 < \a bg) or (\a step <= 0). + * \sa DataArrayChar::substr. + */ +DataArrayChar *DataArrayChar::selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + MEDCouplingAutoRefCountObjectPtr ret=buildEmptySpecializedDAChar(); + int nbComp=getNumberOfComponents(); + int newNbOfTuples=GetNumberOfItemGivenBES(bg,end2,step,"DataArrayInt::selectByTupleId2 : "); + ret->alloc(newNbOfTuples,nbComp); + char *pt=ret->getPointer(); + const char *srcPt=getConstPointer()+bg*nbComp; + for(int i=0;icopyStringInfoFrom(*this); + return ret.retn(); +} + +/*! + * Checks if all values in \a this array are equal to \a val. + * \param [in] val - value to check equality of array values to. + * \return bool - \a true if all values are \a val. + * \throw If \a this is not allocated. + * \throw If \a this->getNumberOfComponents() != 1 + */ +bool DataArrayChar::isUniform(char val) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayChar::isUniform : must be applied on DataArrayChar with only one component, you can call 'rearrange' method before !"); + int nbOfTuples=getNumberOfTuples(); + const char *w=getConstPointer(); + const char *end2=w+nbOfTuples; + for(;w!=end2;w++) + if(*w!=val) + return false; + return true; +} + +/*! + * Changes the number of components within \a this array so that its raw data **does + * not** change, instead splitting this data into tuples changes. + * \param [in] newNbOfComp - number of components for \a this array to have. + * \throw If \a this is not allocated + * \throw If getNbOfElems() % \a newNbOfCompo != 0. + * \warning This method erases all (name and unit) component info set before! + */ +void DataArrayChar::rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + int nbOfElems=getNbOfElems(); + if(nbOfElems%newNbOfCompo!=0) + throw INTERP_KERNEL::Exception("DataArrayChar::rearrange : nbOfElems%newNbOfCompo!=0 !"); + _info_on_compo.clear(); + _info_on_compo.resize(newNbOfCompo); + declareAsNew(); +} + +/*! + * Returns a shorten or extended copy of \a this array. If \a newNbOfComp is less + * than \a this->getNumberOfComponents() then the result array is shorten as each tuple + * is truncated to have \a newNbOfComp components, keeping first components. If \a + * newNbOfComp is more than \a this->getNumberOfComponents() then the result array is + * expanded as each tuple is populated with \a dftValue to have \a newNbOfComp + * components. + * \param [in] newNbOfComp - number of components for the new array to have. + * \param [in] dftValue - value assigned to new values added to the new array. + * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller + * is to delete using decrRef() as it is no more needed. + * \throw If \a this is not allocated. + */ +DataArrayChar *DataArrayChar::changeNbOfComponents(int newNbOfComp, char dftValue) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + MEDCouplingAutoRefCountObjectPtr ret=buildEmptySpecializedDAChar(); + ret->alloc(getNumberOfTuples(),newNbOfComp); + const char *oldc=getConstPointer(); + char *nc=ret->getPointer(); + int nbOfTuples=getNumberOfTuples(); + int oldNbOfComp=getNumberOfComponents(); + int dim=std::min(oldNbOfComp,newNbOfComp); + for(int i=0;isetName(getName().c_str()); + for(int i=0;isetInfoOnComponent(i,getInfoOnComponent(i).c_str()); + ret->setName(getName().c_str()); + return ret.retn(); +} + +/*! + * Returns a copy of \a this array composed of selected components. + * The new DataArrayChar has the same number of tuples but includes components + * specified by \a compoIds parameter. So that getNbOfElems() of the result array + * can be either less, same or more than \a this->getNbOfElems(). + * \param [in] compoIds - sequence of zero based indices of components to include + * into the new array. + * \return DataArrayChar * - the new instance of DataArrayChar that the caller + * is to delete using decrRef() as it is no more needed. + * \throw If \a this is not allocated. + * \throw If a component index (\a i) is not valid: + * \a i < 0 || \a i >= \a this->getNumberOfComponents(). + * + * \ref cpp_mcdataarrayint_keepselectedcomponents "Here is a Python example". + */ +DataArrayChar *DataArrayChar::keepSelectedComponents(const std::vector& compoIds) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + MEDCouplingAutoRefCountObjectPtr ret(buildEmptySpecializedDAChar()); + int newNbOfCompo=(int)compoIds.size(); + int oldNbOfCompo=getNumberOfComponents(); + for(std::vector::const_iterator it=compoIds.begin();it!=compoIds.end();it++) + DataArray::CheckValueInRange(oldNbOfCompo,(*it),"keepSelectedComponents invalid requested component"); + int nbOfTuples=getNumberOfTuples(); + ret->alloc(nbOfTuples,newNbOfCompo); + ret->copyPartOfStringInfoFrom(*this,compoIds); + const char *oldc=getConstPointer(); + char *nc=ret->getPointer(); + for(int i=0;icheckAllocated(); + int nbOfTuples=getNumberOfTuples(); + if(nbOfTuples!=other->getNumberOfTuples()) + throw INTERP_KERNEL::Exception("DataArrayChar::meldWith : mismatch of number of tuples !"); + int nbOfComp1=getNumberOfComponents(); + int nbOfComp2=other->getNumberOfComponents(); + char *newArr=new char[nbOfTuples*(nbOfComp1+nbOfComp2)]; + char *w=newArr; + const char *inp1=getConstPointer(); + const char *inp2=other->getConstPointer(); + for(int i=0;i compIds(nbOfComp2); + for(int i=0;igetNumberOfComponents() + * must be equal to the number of columns to assign to, else an + * exception is thrown; if \a false, then it is only required that \a + * a->getNbOfElems() equals to number of values to assign to (this condition + * must be respected even if \a strictCompoCompare is \a true). The number of + * values to assign to is given by following Python expression: + * \a nbTargetValues = + * \c len(\c range(\a bgTuples,\a endTuples,\a stepTuples)) * + * \c len(\c range(\a bgComp,\a endComp,\a stepComp)). + * \throw If \a a is NULL. + * \throw If \a a is not allocated. + * \throw If \a this is not allocated. + * \throw If parameters specifying tuples and components to assign to do not give a + * non-empty range of increasing indices. + * \throw If \a a->getNbOfElems() != \a nbTargetValues. + * \throw If \a strictCompoCompare == \a true && \a a->getNumberOfComponents() != + * \c len(\c range(\a bgComp,\a endComp,\a stepComp)). + * + * \ref cpp_mcdataarrayint_setpartofvalues1 "Here is a Python example". + */ +void DataArrayChar::setPartOfValues1(const DataArrayChar *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception) +{ + if(!a) + throw INTERP_KERNEL::Exception("DataArrayChar::setPartOfValues1 : DataArrayChar pointer in input is NULL !"); + const char msg[]="DataArrayChar::setPartOfValues1"; + checkAllocated(); + a->checkAllocated(); + int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg); + int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg); + int nbComp=getNumberOfComponents(); + int nbOfTuples=getNumberOfTuples(); + DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value"); + DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value"); + bool assignTech=true; + if(a->getNbOfElems()==newNbOfTuples*newNbOfComp) + { + if(strictCompoCompare) + a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg); + } + else + { + a->checkNbOfTuplesAndComp(1,newNbOfComp,msg); + assignTech=false; + } + char *pt=getPointer()+bgTuples*nbComp+bgComp; + const char *srcPt=a->getConstPointer(); + if(assignTech) + { + for(int i=0;igetNbOfElems() equals to number of values to assign to, then every value + * of \a a is assigned to its own location within \a this array. + * - If \a a includes one tuple, then all values of \a a are assigned to the specified + * components of every specified tuple of \a this array. In this mode it is required + * that \a a->getNumberOfComponents() equals to the number of specified components. + * + * \param [in] a - the array to copy values from. + * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to + * assign values of \a a to. + * \param [in] endTuples - specifies the end of the array \a bgTuples, so that + * pointer to a tuple index (pi) varies as this: + * \a bgTuples <= \a pi < \a endTuples. + * \param [in] bgComp - pointer to an array of component indices of \a this array to + * assign values of \a a to. + * \param [in] endComp - specifies the end of the array \a bgTuples, so that + * pointer to a component index (pi) varies as this: + * \a bgComp <= \a pi < \a endComp. + * \param [in] strictCompoCompare - this parameter is checked only if the + * *mode of usage* is the first; if it is \a true (default), + * then \a a->getNumberOfComponents() must be equal + * to the number of specified columns, else this is not required. + * \throw If \a a is NULL. + * \throw If \a a is not allocated. + * \throw If \a this is not allocated. + * \throw If any index of tuple/component given by bgTuples / bgComp is + * out of a valid range for \a this array. + * \throw In the first *mode of usage*, if strictCompoCompare == true and + * if a->getNumberOfComponents() != (endComp - bgComp) . + * \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or + * a->getNumberOfComponents() != (endComp - bgComp). + * + * \ref cpp_mcdataarrayint_setpartofvalues2 "Here is a Python example". + */ +void DataArrayChar::setPartOfValues2(const DataArrayChar *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception) +{ + if(!a) + throw INTERP_KERNEL::Exception("DataArrayChar::setPartOfValues2 : DataArrayChar pointer in input is NULL !"); + const char msg[]="DataArrayChar::setPartOfValues2"; + checkAllocated(); + a->checkAllocated(); + int nbComp=getNumberOfComponents(); + int nbOfTuples=getNumberOfTuples(); + for(const int *z=bgComp;z!=endComp;z++) + DataArray::CheckValueInRange(nbComp,*z,"invalid component id"); + int newNbOfTuples=(int)std::distance(bgTuples,endTuples); + int newNbOfComp=(int)std::distance(bgComp,endComp); + bool assignTech=true; + if(a->getNbOfElems()==newNbOfTuples*newNbOfComp) + { + if(strictCompoCompare) + a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg); + } + else + { + a->checkNbOfTuplesAndComp(1,newNbOfComp,msg); + assignTech=false; + } + char *pt=getPointer(); + const char *srcPt=a->getConstPointer(); + if(assignTech) + { + for(const int *w=bgTuples;w!=endTuples;w++) + { + DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id"); + for(const int *z=bgComp;z!=endComp;z++,srcPt++) + { + pt[(*w)*nbComp+(*z)]=*srcPt; + } + } + } + else + { + for(const int *w=bgTuples;w!=endTuples;w++) + { + const char *srcPt2=srcPt; + DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id"); + for(const int *z=bgComp;z!=endComp;z++,srcPt2++) + { + pt[(*w)*nbComp+(*z)]=*srcPt2; + } + } + } +} + +/*! + * Assign a given value to values at specified tuples and components of \a this array. + * The tuples and components to assign to are defined by C arrays of indices. + * \param [in] a - the value to assign. + * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to + * assign \a a to. + * \param [in] endTuples - specifies the end of the array \a bgTuples, so that + * pointer to a tuple index (\a pi) varies as this: + * \a bgTuples <= \a pi < \a endTuples. + * \param [in] bgComp - pointer to an array of component indices of \a this array to + * assign \a a to. + * \param [in] endComp - specifies the end of the array \a bgTuples, so that + * pointer to a component index (\a pi) varies as this: + * \a bgComp <= \a pi < \a endComp. + * \throw If \a this is not allocated. + * \throw If any index of tuple/component given by bgTuples / bgComp is + * out of a valid range for \a this array. + * + * \ref cpp_mcdataarrayint_setpartofvaluessimple2 "Here is a Python example". + */ +void DataArrayChar::setPartOfValuesSimple2(char a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + int nbComp=getNumberOfComponents(); + int nbOfTuples=getNumberOfTuples(); + for(const int *z=bgComp;z!=endComp;z++) + DataArray::CheckValueInRange(nbComp,*z,"invalid component id"); + char *pt=getPointer(); + for(const int *w=bgTuples;w!=endTuples;w++) + for(const int *z=bgComp;z!=endComp;z++) + { + DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id"); + pt[(*w)*nbComp+(*z)]=a; + } +} + +/*! + * Copy all values from another DataArrayChar (\a a) into specified tuples and + * components of \a this array. Textual data is not copied. + * The tuples to assign to are defined by a C array of indices. + * The components to assign to are defined by three values similar to parameters of + * the Python function \c range(\c start,\c stop,\c step). + * There are two *modes of usage*: + * - If \a a->getNbOfElems() equals to number of values to assign to, then every value + * of \a a is assigned to its own location within \a this array. + * - If \a a includes one tuple, then all values of \a a are assigned to the specified + * components of every specified tuple of \a this array. In this mode it is required + * that \a a->getNumberOfComponents() equals to the number of specified components. + * + * \param [in] a - the array to copy values from. + * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to + * assign values of \a a to. + * \param [in] endTuples - specifies the end of the array \a bgTuples, so that + * pointer to a tuple index (pi) varies as this: + * \a bgTuples <= \a pi < \a endTuples. + * \param [in] bgComp - index of the first component of \a this array to assign to. + * \param [in] endComp - index of the component before which the components to assign + * to are located. + * \param [in] stepComp - index increment to get index of the next component to assign to. + * \param [in] strictCompoCompare - this parameter is checked only in the first + * *mode of usage*; if \a strictCompoCompare is \a true (default), + * then \a a->getNumberOfComponents() must be equal + * to the number of specified columns, else this is not required. + * \throw If \a a is NULL. + * \throw If \a a is not allocated. + * \throw If \a this is not allocated. + * \throw If any index of tuple given by \a bgTuples is out of a valid range for + * \a this array. + * \throw In the first *mode of usage*, if strictCompoCompare == true and + * if a->getNumberOfComponents() is unequal to the number of components + * defined by (bgComp,endComp,stepComp). + * \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or + * a->getNumberOfComponents() is unequal to the number of components + * defined by (bgComp,endComp,stepComp). + * \throw If parameters specifying components to assign to, do not give a + * non-empty range of increasing indices or indices are out of a valid range + * for \this array. + * + * \ref cpp_mcdataarrayint_setpartofvalues3 "Here is a Python example". + */ +void DataArrayChar::setPartOfValues3(const DataArrayChar *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception) +{ + if(!a) + throw INTERP_KERNEL::Exception("DataArrayChar::setPartOfValues3 : DataArrayChar pointer in input is NULL !"); + const char msg[]="DataArrayChar::setPartOfValues3"; + checkAllocated(); + a->checkAllocated(); + int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg); + int nbComp=getNumberOfComponents(); + int nbOfTuples=getNumberOfTuples(); + DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value"); + int newNbOfTuples=(int)std::distance(bgTuples,endTuples); + bool assignTech=true; + if(a->getNbOfElems()==newNbOfTuples*newNbOfComp) + { + if(strictCompoCompare) + a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg); + } + else + { + a->checkNbOfTuplesAndComp(1,newNbOfComp,msg); + assignTech=false; + } + char *pt=getPointer()+bgComp; + const char *srcPt=a->getConstPointer(); + if(assignTech) + { + for(const int *w=bgTuples;w!=endTuples;w++) + for(int j=0;j(pi) varies as this: + * \a bgTuples <= \a pi < \a endTuples. + * \param [in] bgComp - index of the first component of \a this array to assign to. + * \param [in] endComp - index of the component before which the components to assign + * to are located. + * \param [in] stepComp - index increment to get index of the next component to assign to. + * \throw If \a this is not allocated. + * \throw If any index of tuple given by \a bgTuples is out of a valid range for + * \a this array. + * \throw If parameters specifying components to assign to, do not give a + * non-empty range of increasing indices or indices are out of a valid range + * for \this array. + * + * \ref cpp_mcdataarrayint_setpartofvaluessimple3 "Here is a Python example". + */ +void DataArrayChar::setPartOfValuesSimple3(char a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception) +{ + const char msg[]="DataArrayChar::setPartOfValuesSimple3"; + checkAllocated(); + int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg); + int nbComp=getNumberOfComponents(); + int nbOfTuples=getNumberOfTuples(); + DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value"); + char *pt=getPointer()+bgComp; + for(const int *w=bgTuples;w!=endTuples;w++) + for(int j=0;jcheckAllocated(); + int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg); + int newNbOfComp=(int)std::distance(bgComp,endComp); + int nbComp=getNumberOfComponents(); + for(const int *z=bgComp;z!=endComp;z++) + DataArray::CheckValueInRange(nbComp,*z,"invalid component id"); + int nbOfTuples=getNumberOfTuples(); + DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value"); + bool assignTech=true; + if(a->getNbOfElems()==newNbOfTuples*newNbOfComp) + { + if(strictCompoCompare) + a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg); + } + else + { + a->checkNbOfTuplesAndComp(1,newNbOfComp,msg); + assignTech=false; + } + const char *srcPt=a->getConstPointer(); + char *pt=getPointer()+bgTuples*nbComp; + if(assignTech) + { + for(int i=0;ithis->getNumberOfComponents() != a->getNumberOfComponents(). + * \throw If \a tuplesSelec->getNumberOfComponents() != 2. + * \throw If any tuple index given by \a tuplesSelec is out of a valid range for + * the corresponding (\a this or \a a) array. + */ +void DataArrayChar::setPartOfValuesAdv(const DataArrayChar *a, const DataArrayChar *tuplesSelec) throw(INTERP_KERNEL::Exception) +{ + if(!a || !tuplesSelec) + throw INTERP_KERNEL::Exception("DataArrayChar::setPartOfValuesAdv : DataArrayChar pointer in input is NULL !"); + checkAllocated(); + a->checkAllocated(); + tuplesSelec->checkAllocated(); + int nbOfComp=getNumberOfComponents(); + if(nbOfComp!=a->getNumberOfComponents()) + throw INTERP_KERNEL::Exception("DataArrayChar::setPartOfValuesAdv : This and a do not have the same number of components !"); + if(tuplesSelec->getNumberOfComponents()!=2) + throw INTERP_KERNEL::Exception("DataArrayChar::setPartOfValuesAdv : Expecting to have a tuple selector DataArrayChar instance with exactly 2 components !"); + int thisNt=getNumberOfTuples(); + int aNt=a->getNumberOfTuples(); + char *valsToSet=getPointer(); + const char *valsSrc=a->getConstPointer(); + for(const char *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple+=2) + { + if(tuple[1]>=0 && tuple[1]=0 && tuple[0]begin(),tuple)/2; + oss << " of 'tuplesSelec' request of tuple id #" << tuple[0] << " in 'this' ! It should be in [0," << thisNt << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + else + { + std::ostringstream oss; oss << "DataArrayChar::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2; + oss << " of 'tuplesSelec' request of tuple id #" << tuple[1] << " in 'a' ! It should be in [0," << aNt << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } +} + +/*! + * Returns a value located at specified tuple and component. + * This method is equivalent to DataArrayChar::getIJ() except that validity of + * parameters is checked. So this method is safe but expensive if used to go through + * all values of \a this. + * \param [in] tupleId - index of tuple of interest. + * \param [in] compoId - index of component of interest. + * \return double - value located by \a tupleId and \a compoId. + * \throw If \a this is not allocated. + * \throw If condition ( 0 <= tupleId < this->getNumberOfTuples() ) is violated. + * \throw If condition ( 0 <= compoId < this->getNumberOfComponents() ) is violated. + */ +char DataArrayChar::getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + if(tupleId<0 || tupleId>=getNumberOfTuples()) + { + std::ostringstream oss; oss << "DataArrayChar::getIJSafe : request for tupleId " << tupleId << " should be in [0," << getNumberOfTuples() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(compoId<0 || compoId>=getNumberOfComponents()) + { + std::ostringstream oss; oss << "DataArrayChar::getIJSafe : request for compoId " << compoId << " should be in [0," << getNumberOfComponents() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return _mem[tupleId*((int)_info_on_compo.size())+compoId]; +} + +/*! + * Returns the last value of \a this. + * \return double - the last value of \a this array. + * \throw If \a this is not allocated. + * \throw If \a this->getNumberOfComponents() != 1. + * \throw If \a this->getNumberOfTuples() < 1. + */ +char DataArrayChar::back() const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayChar::back : number of components not equal to one !"); + int nbOfTuples=getNumberOfTuples(); + if(nbOfTuples<1) + throw INTERP_KERNEL::Exception("DataArrayChar::back : number of tuples must be >= 1 !"); + return *(getConstPointer()+nbOfTuples-1); +} + +/*! + * Creates a new DataArrayChar containing IDs (indices) of tuples holding value equal to a + * given one. + * \param [in] val - the value to find within \a this. + * \return DataArrayChar * - a new instance of DataArrayChar. The caller is to delete this + * array using decrRef() as it is no more needed. + * \throw If \a this is not allocated. + * \throw If \a this->getNumberOfComponents() != 1. + */ +DataArrayInt *DataArrayChar::getIdsEqual(char val) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayChar::getIdsEqual : the array must have only one component, you can call 'rearrange' method before !"); + const char *cptr=getConstPointer(); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); ret->alloc(0,1); + int nbOfTuples=getNumberOfTuples(); + for(int i=0;ipushBackSilent(i); + return ret.retn(); +} + +/*! + * Creates a new DataArrayChar containing IDs (indices) of tuples holding value \b not + * equal to a given one. + * \param [in] val - the value to ignore within \a this. + * \return DataArrayChar * - a new instance of DataArrayChar. The caller is to delete this + * array using decrRef() as it is no more needed. + * \throw If \a this is not allocated. + * \throw If \a this->getNumberOfComponents() != 1. + */ +DataArrayInt *DataArrayChar::getIdsNotEqual(char val) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayChar::getIdsNotEqual : the array must have only one component, you can call 'rearrange' method before !"); + const char *cptr=getConstPointer(); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); ret->alloc(0,1); + int nbOfTuples=getNumberOfTuples(); + for(int i=0;ipushBackSilent(i); + return ret.retn(); +} + +/*! + * This method searches the sequence specified in input parameter \b vals in \b this. + * This works only for DataArrayChar having number of components equal to one (if not an INTERP_KERNEL::Exception will be thrown). + * This method differs from DataArrayChar::locateTuple in that the position is internal raw data is not considered here contrary to DataArrayChar::locateTuple. + * \sa DataArrayChar::locateTuple + */ +int DataArrayChar::search(const std::vector& vals) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + int nbOfCompo=getNumberOfComponents(); + if(nbOfCompo!=1) + throw INTERP_KERNEL::Exception("DataArrayChar::search : works only for DataArrayChar instance with one component !"); + const char *cptr=getConstPointer(); + int nbOfVals=getNbOfElems(); + const char *loc=std::search(cptr,cptr+nbOfVals,vals.begin(),vals.end()); + if(loc!=cptr+nbOfVals) + return std::distance(cptr,loc); + return -1; +} + +/*! + * This method is an extension of DataArrayChar::locateValue 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. + * If any the tuple id is returned. If not -1 is returned. + * + * 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. + * + * \return tuple id where \b tupl is. -1 if no such tuple exists in \b this. + * \sa DataArrayChar::search. + */ +int DataArrayChar::locateTuple(const std::vector& tupl) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + int nbOfCompo=getNumberOfComponents(); + if(nbOfCompo==0) + throw INTERP_KERNEL::Exception("DataArrayChar::locateTuple : 0 components in 'this' !"); + if(nbOfCompo!=(int)tupl.size()) + { + std::ostringstream oss; oss << "DataArrayChar::locateTuple : 'this' contains " << nbOfCompo << " components and searching for a tuple of length " << tupl.size() << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const char *cptr=getConstPointer(); + int nbOfVals=getNbOfElems(); + for(const char *work=cptr;work!=cptr+nbOfVals;) + { + work=std::search(work,cptr+nbOfVals,tupl.begin(),tupl.end()); + if(work!=cptr+nbOfVals) + { + if(std::distance(cptr,work)%nbOfCompo!=0) + work++; + else + return std::distance(cptr,work)/nbOfCompo; + } + } + 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. + * \return bool - \a true in case if \a value is present within \a this array. + * \throw If \a this is not allocated. + * \throw If \a this->getNumberOfComponents() != 1. + * \sa locateValue() + */ +bool DataArrayChar::presenceOfValue(char value) const throw(INTERP_KERNEL::Exception) +{ + return locateValue(value)!=-1; +} + +/*! + * This method expects to be called when number of components of this is equal to one. + * This method returns true if it exists a tuple so that the value is contained in \b vals. + * If not any tuple contains one of the values contained in 'vals' false is returned. + * \sa DataArrayChar::locateValue + */ +bool DataArrayChar::presenceOfValue(const std::vector& vals) const throw(INTERP_KERNEL::Exception) +{ + return locateValue(vals)!=-1; +} + +/*! + * This method expects to be called when number of components of this is equal to one. + * This method returns the tuple id, if it exists, of the first tuple equal to \b value. + * If not any tuple contains \b value -1 is returned. + * \sa DataArrayChar::presenceOfValue + */ +int DataArrayChar::locateValue(char value) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayChar::presenceOfValue : the array must have only one component, you can call 'rearrange' method before !"); + const char *cptr=getConstPointer(); + int nbOfTuples=getNumberOfTuples(); + const char *ret=std::find(cptr,cptr+nbOfTuples,value); + if(ret!=cptr+nbOfTuples) + return std::distance(cptr,ret); + return -1; +} + +/*! + * This method expects to be called when number of components of this is equal to one. + * This method returns the tuple id, if it exists, of the first tuple so that the value is contained in \b vals. + * If not any tuple contains one of the values contained in 'vals' false is returned. + * \sa DataArrayChar::presenceOfValue + */ +int DataArrayChar::locateValue(const std::vector& vals) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::presenceOfValue : the array must have only one component, you can call 'rearrange' method before !"); + std::set vals2(vals.begin(),vals.end()); + const char *cptr=getConstPointer(); + int nbOfTuples=getNumberOfTuples(); + for(const char *w=cptr;w!=cptr+nbOfTuples;w++) + if(vals2.find(*w)!=vals2.end()) + return std::distance(cptr,w); + return -1; +} + +/*! + * Returns the maximal value and its location within \a this one-dimensional array. + * \param [out] tupleId - index of the tuple holding the maximal value. + * \return double - the maximal value among all values of \a this array. + * \throw If \a this->getNumberOfComponents() != 1 + * \throw If \a this->getNumberOfTuples() < 1 + */ +char DataArrayChar::getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayChar::getMaxValue : must be applied on DataArrayChar with only one component !"); + int nbOfTuples=getNumberOfTuples(); + if(nbOfTuples<=0) + throw INTERP_KERNEL::Exception("DataArrayChar::getMaxValue : array exists but number of tuples must be > 0 !"); + const char *vals=getConstPointer(); + const char *loc=std::max_element(vals,vals+nbOfTuples); + tupleId=(int)std::distance(vals,loc); + return *loc; +} + +/*! + * Returns the maximal value within \a this array that is allowed to have more than + * one component. + * \return char - the maximal value among all values of \a this array. + * \throw If \a this is not allocated. + */ +char DataArrayChar::getMaxValueInArray() const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + const char *loc=std::max_element(begin(),end()); + return *loc; +} + +/*! + * Returns the minimal value and its location within \a this one-dimensional array. + * \param [out] tupleId - index of the tuple holding the minimal value. + * \return char - the minimal value among all values of \a this array. + * \throw If \a this->getNumberOfComponents() != 1 + * \throw If \a this->getNumberOfTuples() < 1 + */ +char DataArrayChar::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayChar::getMaxValue : must be applied on DataArrayChar with only one component !"); + int nbOfTuples=getNumberOfTuples(); + if(nbOfTuples<=0) + throw INTERP_KERNEL::Exception("DataArrayChar::getMaxValue : array exists but number of tuples must be > 0 !"); + const char *vals=getConstPointer(); + const char *loc=std::min_element(vals,vals+nbOfTuples); + tupleId=(int)std::distance(vals,loc); + return *loc; +} + +/*! + * Returns the minimal value within \a this array that is allowed to have more than + * one component. + * \return char - the minimal value among all values of \a this array. + * \throw If \a this is not allocated. + */ +char DataArrayChar::getMinValueInArray() const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + const char *loc=std::min_element(begin(),end()); + return *loc; +} + +/*! + * This method works only on data array with one component. + * This method returns a newly allocated array storing stored ascendantly tuple ids in \b this so that + * this[*id] in [\b vmin,\b vmax) + * + * \param [in] vmin begin of range. This value is included in range. + * \param [out] vmax end of range. This value is \b not included in range. + * \return a newly allocated data array that the caller should deal with. + */ +DataArrayInt *DataArrayChar::getIdsInRange(char vmin, char vmax) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayChar::getIdsInRange : this must have exactly one component !"); + const char *cptr=getConstPointer(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(0,1); + int nbOfTuples=getNumberOfTuples(); + for(int i=0;i=vmin && *cptrpushBackSilent(i); + return ret.retn(); +} + +/*! + * Returns a new DataArrayChar by concatenating two given arrays, so that (1) the number + * of tuples in the result array is a1->getNumberOfTuples() + a2->getNumberOfTuples() - + * offsetA2 and (2) + * the number of component in the result array is same as that of each of given arrays. + * First \a offsetA2 tuples of \a a2 are skipped and thus are missing from the result array. + * Info on components is copied from the first of the given arrays. Number of components + * in the given arrays must be the same. + * \param [in] a1 - an array to include in the result array. + * \param [in] a2 - another array to include in the result array. + * \param [in] offsetA2 - number of tuples of \a a2 to skip. + * \return DataArrayChar * - the new instance of DataArrayChar. + * The caller is to delete this result array using decrRef() as it is no more + * needed. + * \throw If either \a a1 or \a a2 is NULL. + * \throw If \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents(). + */ +DataArrayChar *DataArrayChar::Aggregate(const DataArrayChar *a1, const DataArrayChar *a2) +{ + if(!a1 || !a2) + throw INTERP_KERNEL::Exception("DataArrayChar::Aggregate : input DataArrayChar instance is NULL !"); + std::vector v(2); v[0]=a1; v[1]=a2; + return Aggregate(v); +} + +/*! + * Returns a new DataArrayChar by concatenating all given arrays, so that (1) the number + * of tuples in the result array is a sum of the number of tuples of given arrays and (2) + * the number of component in the result array is same as that of each of given arrays. + * Info on components is copied from the first of the given arrays. Number of components + * in the given arrays must be the same. + * \param [in] arr - a sequence of arrays to include in the result array. + * \return DataArrayChar * - the new instance of DataArrayChar. + * The caller is to delete this result array using decrRef() as it is no more + * needed. + * \throw If all arrays within \a arr are NULL. + * \throw If getNumberOfComponents() of arrays within \a arr. + */ +DataArrayChar *DataArrayChar::Aggregate(const std::vector& arr) throw(INTERP_KERNEL::Exception) +{ + std::vector a; + for(std::vector::const_iterator it4=arr.begin();it4!=arr.end();it4++) + if(*it4) + a.push_back(*it4); + if(a.empty()) + throw INTERP_KERNEL::Exception("DataArrayChar::Aggregate : input list must be NON EMPTY !"); + std::vector::const_iterator it=a.begin(); + int nbOfComp=(*it)->getNumberOfComponents(); + int nbt=(*it++)->getNumberOfTuples(); + for(int i=1;it!=a.end();it++,i++) + { + if((*it)->getNumberOfComponents()!=nbOfComp) + throw INTERP_KERNEL::Exception("DataArrayChar::Aggregate : Nb of components mismatch for array aggregation !"); + nbt+=(*it)->getNumberOfTuples(); + } + 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.retn(); +} + +/*! + * Returns a new DataArrayChar by aggregating two given arrays, so that (1) the number + * of components in the result array is a sum of the number of components of given arrays + * and (2) the number of tuples in the result array is same as that of each of given + * arrays. In other words the i-th tuple of result array includes all components of + * i-th tuples of all given arrays. + * Number of tuples in the given arrays must be the same. + * \param [in] a1 - an array to include in the result array. + * \param [in] a2 - another array to include in the result array. + * \return DataArrayChar * - the new instance of DataArrayChar. + * The caller is to delete this result array using decrRef() as it is no more + * needed. + * \throw If both \a a1 and \a a2 are NULL. + * \throw If any given array is not allocated. + * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() + */ +DataArrayChar *DataArrayChar::Meld(const DataArrayChar *a1, const DataArrayChar *a2) throw(INTERP_KERNEL::Exception) +{ + std::vector arr(2); + arr[0]=a1; arr[1]=a2; + return Meld(arr); +} + +/*! + * Returns a new DataArrayChar by aggregating all given arrays, so that (1) the number + * of components in the result array is a sum of the number of components of given arrays + * and (2) the number of tuples in the result array is same as that of each of given + * arrays. In other words the i-th tuple of result array includes all components of + * i-th tuples of all given arrays. + * Number of tuples in the given arrays must be the same. + * \param [in] arr - a sequence of arrays to include in the result array. + * \return DataArrayChar * - the new instance of DataArrayChar. + * The caller is to delete this result array using decrRef() as it is no more + * needed. + * \throw If all arrays within \a arr are NULL. + * \throw If any given array is not allocated. + * \throw If getNumberOfTuples() of arrays within \a arr is different. + */ +DataArrayChar *DataArrayChar::Meld(const std::vector& arr) throw(INTERP_KERNEL::Exception) +{ + std::vector a; + for(std::vector::const_iterator it4=arr.begin();it4!=arr.end();it4++) + if(*it4) + a.push_back(*it4); + if(a.empty()) + throw INTERP_KERNEL::Exception("DataArrayChar::Meld : array must be NON empty !"); + std::vector::const_iterator it; + for(it=a.begin();it!=a.end();it++) + (*it)->checkAllocated(); + it=a.begin(); + int nbOfTuples=(*it)->getNumberOfTuples(); + std::vector nbc(a.size()); + std::vector pts(a.size()); + nbc[0]=(*it)->getNumberOfComponents(); + pts[0]=(*it++)->getConstPointer(); + for(int i=1;it!=a.end();it++,i++) + { + if(nbOfTuples!=(*it)->getNumberOfTuples()) + throw INTERP_KERNEL::Exception("DataArrayChar::meld : mismatch of number of tuples !"); + nbc[i]=(*it)->getNumberOfComponents(); + pts[i]=(*it)->getConstPointer(); + } + int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0); + DataArrayChar *ret=a[0]->buildEmptySpecializedDAChar(); + ret->alloc(nbOfTuples,totalNbOfComp); + char *retPtr=ret->getPointer(); + for(int i=0;isetInfoOnComponent(k,a[i]->getInfoOnComponent(j).c_str()); + return ret; +} + +/*! + * Sets a C array to be used as raw data of \a this. The previously set info + * of components is retained and re-sized. + * For more info see \ref MEDCouplingArraySteps1. + * \param [in] array - the C array to be used as raw data of \a this. + * \param [in] ownership - if \a true, \a array will be deallocated at destruction of \a this. + * \param [in] type - specifies how to deallocate \a array. If \a type == ParaMEDMEM::CPP_DEALLOC, + * \c delete [] \c array; will be called. If \a type == ParaMEDMEM::C_DEALLOC, + * \c free(\c array ) will be called. + * \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) 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) throw(INTERP_KERNEL::Exception) +{ + _info_on_compo.resize(nbOfCompo); + _mem.useExternalArrayWithRWAccess(array,nbOfTuple*nbOfCompo); + declareAsNew(); +} + +/*! + * 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 << (int)_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; +} + +/*! + * Returns a new instance of DataArrayAsciiChar. The caller is to delete this array + * using decrRef() as it is no more needed. + * \param [in] st the string. This input string should have a length greater than 0. If not an excpetion will be thrown. + */ +DataArrayAsciiChar *DataArrayAsciiChar::New(const std::string& st) throw(INTERP_KERNEL::Exception) +{ + return new DataArrayAsciiChar(st); +} + +/*! + * \param [in] st the string. This input string should have a length greater than 0. If not an excpetion will be thrown. + */ +DataArrayAsciiChar::DataArrayAsciiChar(const std::string& st) throw(INTERP_KERNEL::Exception) +{ + std::size_t lgth=st.length(); + if(lgth==0) + throw INTERP_KERNEL::Exception("DataArrayAsciiChar contructor with string ! Size of input string is null !"); + alloc(1,lgth); + std::copy(st.begin(),st.begin()+lgth,getPointer()); +} + +/*! + * Returns a new instance of DataArrayAsciiChar. The caller is to delete this array + * using decrRef() as it is no more needed. + * This constructor uses \a vst input vector of strings to initialize itself. For all strings whose length is lower than max length of strings in + * \a vst the remaining locations in memory will be set to character \a defaultChar. + * + * \param [in] defaultChar the default character used to fill not defined locations in \a this + * \param [in] vst vector of strings. This input vector must be non empty. \a this will have its component size set to the max lgth of strings contained + * in \a vst. If all strings are empty an INTERP_KERNEL::Exception will be thrown. + * + * \throw If input \a vst is empty. + * \throw If all strings in \a vst are empty. + */ +DataArrayAsciiChar *DataArrayAsciiChar::New(const std::vector& vst, char defaultChar) throw(INTERP_KERNEL::Exception) +{ + return new DataArrayAsciiChar(vst,defaultChar); +} + +/*! + * This constructor uses \a vst input vector of strings to initialize itself. For all strings whose length is lower than max length of strings in + * \a vst the remaining locations in memory will be set to character \a defaultChar. + * + * \param [in] defaultChar the default character used to fill not defined locations in \a this + * \param [in] vst vector of strings. This input vector must be non empty. \a this will have its component size set to the max lgth of strings contained + * in \a vst. If all strings are empty an INTERP_KERNEL::Exception will be thrown. + * + * \throw If input \a vst is empty. + * \throw If all strings in \a vst are empty. + */ +DataArrayAsciiChar::DataArrayAsciiChar(const std::vector& vst, char defaultChar) throw(INTERP_KERNEL::Exception) +{ + if(vst.empty()) + throw INTERP_KERNEL::Exception("DataArrayAsciiChar contructor with vector of strings ! Empty array !"); + std::size_t nbCompo=0; + for(std::vector::const_iterator it=vst.begin();it!=vst.end();it++) + nbCompo=std::max(nbCompo,(*it).length()); + if(nbCompo==0) + throw INTERP_KERNEL::Exception("DataArrayAsciiChar contructor with vector of strings ! All strings in not empty vector are empty !"); + int nbTuples=(int)vst.size(); + alloc(nbTuples,(int)nbCompo); + char *pt=getPointer(); + for(int i=0;i(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); + if(_mem.reprHeader(getNumberOfComponents(),stream)) + { + const char *data=begin(); + int nbOfTuples=getNumberOfTuples(); + int nbCompo=getNumberOfComponents(); + for(int i=0;i(stream)); + stream << "\"\n"; + } + } +} + +void DataArrayAsciiChar::reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) +{ + reprWithoutNameStream(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) + { + _da->incrRef(); + if(_da->isAllocated()) + { + _nb_comp=da->getNumberOfComponents(); + _nb_tuple=da->getNumberOfTuples(); + _pt=da->getPointer(); + } + } +} + +DataArrayAsciiCharIterator::~DataArrayAsciiCharIterator() +{ + if(_da) + _da->decrRef(); +} + +DataArrayAsciiCharTuple *DataArrayAsciiCharIterator::nextt() throw(INTERP_KERNEL::Exception) +{ + if(_tuple_id<_nb_tuple) + { + _tuple_id++; + DataArrayAsciiCharTuple *ret=new DataArrayAsciiCharTuple(_pt,_nb_comp); + _pt+=_nb_comp; + return ret; + } + else + return 0; +} + +DataArrayAsciiCharTuple::DataArrayAsciiCharTuple(char *pt, int nbOfComp):_pt(pt),_nb_of_compo(nbOfComp) +{ +} + +std::string DataArrayAsciiCharTuple::repr() const throw(INTERP_KERNEL::Exception) +{ + std::ostringstream oss; + std::copy(_pt,_pt+_nb_of_compo,std::ostream_iterator(oss)); + return oss.str(); +} + +char DataArrayAsciiCharTuple::asciiCharValue() const throw(INTERP_KERNEL::Exception) +{ + if(_nb_of_compo==1) + return *_pt; + 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::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. + */ +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)) + { + DataArrayAsciiChar *ret=DataArrayAsciiChar::New(); + ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo); + return ret; + } + else + { + 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/MEDCouplingNatureOfField.cxx b/src/MEDCoupling/MEDCouplingNatureOfField.cxx index 818614ba0..7a1161848 100644 --- a/src/MEDCoupling/MEDCouplingNatureOfField.cxx +++ b/src/MEDCoupling/MEDCouplingNatureOfField.cxx @@ -33,7 +33,7 @@ namespace ParaMEDMEM const int MEDCouplingNatureOfField::POS_OF_NATUREOFFIELD[NB_OF_POSSIBILITIES]={17,26,32,35,37}; - const char *MEDCouplingNatureOfField::getRepr(NatureOfField nat) throw(INTERP_KERNEL::Exception) + const char *MEDCouplingNatureOfField::GetRepr(NatureOfField nat) throw(INTERP_KERNEL::Exception) { const int *pos=std::find(POS_OF_NATUREOFFIELD,POS_OF_NATUREOFFIELD+NB_OF_POSSIBILITIES,(int)nat); if(pos==POS_OF_NATUREOFFIELD+NB_OF_POSSIBILITIES) diff --git a/src/MEDCoupling/MEDCouplingNatureOfField.hxx b/src/MEDCoupling/MEDCouplingNatureOfField.hxx index 6bcf75abe..00a9b02d4 100644 --- a/src/MEDCoupling/MEDCouplingNatureOfField.hxx +++ b/src/MEDCoupling/MEDCouplingNatureOfField.hxx @@ -38,7 +38,7 @@ namespace ParaMEDMEM class MEDCouplingNatureOfField { public: - MEDCOUPLING_EXPORT static const char *getRepr(NatureOfField nat) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static const char *GetRepr(NatureOfField nat) throw(INTERP_KERNEL::Exception); private: static const int NB_OF_POSSIBILITIES=5; static const char *REPR_OF_NATUREOFFIELD[NB_OF_POSSIBILITIES]; diff --git a/src/MEDCoupling/MEDCouplingPointSet.cxx b/src/MEDCoupling/MEDCouplingPointSet.cxx index 3f6886a53..f8480f8c2 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.cxx +++ b/src/MEDCoupling/MEDCouplingPointSet.cxx @@ -96,6 +96,11 @@ void MEDCouplingPointSet::setCoords(const DataArrayDouble *coords) } } +/*! + * Returns a pointer to the array of point coordinates held by \a this. + * \return DataArrayDouble * - the pointer to the array of point coordinates. The + * caller is to delete this array using decrRef() as it is no more needed. + */ DataArrayDouble *MEDCouplingPointSet::getCoordinatesAndOwner() const { if(_coords) @@ -104,8 +109,13 @@ DataArrayDouble *MEDCouplingPointSet::getCoordinatesAndOwner() const } /*! - * This method copyies all tiny strings from other (name and components name). - * @throw if other and this have not same mesh type. + * Copies string attributes from an \a other mesh. The copied strings are + * - mesh name + * - mesh description + * - time units + * - textual data of the coordinates array (name and components info) + * + * \param [in] other - the mesh to copy string attributes from. */ void MEDCouplingPointSet::copyTinyStringsFrom(const MEDCouplingMesh *other) throw(INTERP_KERNEL::Exception) { @@ -134,6 +144,13 @@ bool MEDCouplingPointSet::isEqualIfNotWhy(const MEDCouplingMesh *other, double p return true; } +/*! + * Checks equality of point coordinates with coordinates of an \a other mesh. + * None textual data is considered. + * \param [in] other - the mesh to compare coordinates with \a this one. + * \param [in] prec - precision value to compare coordinates. + * \return bool - \a true if coordinates of points are equal, \a false else. + */ bool MEDCouplingPointSet::isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const { const MEDCouplingPointSet *otherC=dynamic_cast(other); @@ -161,12 +178,26 @@ bool MEDCouplingPointSet::areCoordsEqualIfNotWhy(const MEDCouplingPointSet& othe return ret; } +/*! + * Checks equality of point coordinates with \a other point coordinates. + * Textual data (name and components info) \b is compared as well. + * \param [in] other - the point coordinates to compare with \a this one. + * \param [in] prec - precision value to compare coordinates. + * \return bool - \a true if coordinates of points are equal, \a false else. + */ bool MEDCouplingPointSet::areCoordsEqual(const MEDCouplingPointSet& other, double prec) const { std::string tmp; return areCoordsEqualIfNotWhy(other,prec,tmp); } +/*! + * Checks equality of point coordinates with \a other point coordinates. + * None textual data is considered. + * \param [in] other - the point coordinates to compare with \a this one. + * \param [in] prec - precision value to compare coordinates. + * \return bool - \a true if coordinates of points are equal, \a false else. + */ bool MEDCouplingPointSet::areCoordsEqualWithoutConsideringStr(const MEDCouplingPointSet& other, double prec) const { if(_coords==0 && other._coords==0) @@ -179,7 +210,16 @@ bool MEDCouplingPointSet::areCoordsEqualWithoutConsideringStr(const MEDCouplingP } /*! - * Returns coordinates of node with id 'nodeId' and append it in 'coo'. + * Returns coordinates of \a nodeId-th node. + * \param [in] nodeId - the ID of the node of interest. + * \param [in, out] coo - the array filled with coordinates of the \a nodeId-th + * node. This array is not cleared before filling in, the coordinates are + * appended to its end. + * \throw If the coordinates array is not set. + * \throw If \a nodeId is not a valid index for the coordinates array. + * + * \ref cpp_mcpointset_getcoordinatesofnode "Here is a C++ example".
+ * \ref py_mcpointset_getcoordinatesofnode "Here is a Python example". */ void MEDCouplingPointSet::getCoordinatesOfNode(int nodeId, std::vector& coo) const throw(INTERP_KERNEL::Exception) { @@ -200,12 +240,19 @@ void MEDCouplingPointSet::getCoordinatesOfNode(int nodeId, std::vector& } /*! - * This method is typically the base method used for implementation of mergeNodes. This method computes this permutation array using as input, - * This method is const ! So this method simply computes the array, no permutation of nodes is done. - * a precision 'precision' and a 'limitNodeId' that is the node id so that every nodes which id is strictly lower than 'limitNodeId' will not be merged. - * To desactivate this advanced feature put -1 to this argument. - * @param areNodesMerged output parameter that states if some nodes have been "merged" in returned array - * @param newNbOfNodes output parameter too this is the maximal id in returned array to avoid to recompute it. + * Finds nodes equal within \a precision and returns an array describing the + * permutation to remove duplicated nodes. + * \param [in] precision - minimal absolute distance between two nodes at which they are + * considered not coincident. + * \param [in] limitNodeId - limit node id. Nodes with id strictly lower than \a + * limitTupleId are \b not considered. Put -1 to this parameter to have + * all nodes treated. + * \param [out] areNodesMerged - is set to \a true if any coincident nodes found. + * \param [out] newNbOfNodes - returns number of unique nodes. + * \return DataArrayInt * - the permutation array in "Old to New" mode. For more + * info on "Old to New" mode see \ref MEDCouplingArrayRenumbering. The caller + * is to delete this array using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. */ DataArrayInt *MEDCouplingPointSet::buildPermArrayForMergeNode(double precision, int limitNodeId, bool& areNodesMerged, int& newNbOfNodes) const { @@ -220,11 +267,29 @@ DataArrayInt *MEDCouplingPointSet::buildPermArrayForMergeNode(double precision, } /*! - * This methods searches for each node if there are any nodes in _coords that are less far than 'prec' from n1. if any, these nodes are stored in out params - * comm and commIndex. - * @param limitNodeId is the limit node id. All nodes which id is strictly lower than 'limitNodeId' will not be merged each other. - * @param comm out parameter (not inout) - * @param commIndex out parameter (not inout) + * Finds nodes coincident within \a prec tolerance. + * Ids of coincident nodes are stored in output arrays. + * A pair of arrays (\a comm, \a commIndex) is called "Surjective Format 2". + * \param [in] prec - minimal absolute distance between two nodes at which they are + * considered not coincident. + * \param [in] limitNodeId - limit node id. Nodes with id strictly lower than \a + * limitTupleId are \b not considered. Put -1 to this parameter to have + * all nodes treated. + * \param [out] comm - the array holding ids of coincident nodes. + * \a comm->getNumberOfComponents() == 1. + * \a comm->getNumberOfTuples() == \a commIndex->back(). The caller + * is to delete this array using decrRef() as it is no more needed. + * \param [out] commIndex - the array dividing all ids stored in \a comm into + * groups of (ids of) coincident nodes. Its every value is a tuple + * index where a next group of nodes begins. For example the second + * group of nodes in \a comm is described by following range of indices: + * [ \a commIndex[1], \a commIndex[2] ). \a commIndex->getNumberOfTuples()-1 + * gives the number of groups of coincident nodes. The caller + * is to delete this array using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * + * \ref cpp_mcpointset_findcommonnodes "Here is a C++ example".
+ * \ref py_mcpointset_findcommonnodes "Here is a Python example". */ void MEDCouplingPointSet::findCommonNodes(double prec, int limitNodeId, DataArrayInt *&comm, DataArrayInt *&commIndex) const { @@ -233,6 +298,21 @@ void MEDCouplingPointSet::findCommonNodes(double prec, int limitNodeId, DataArra _coords->findCommonTuples(prec,limitNodeId,comm,commIndex); } +/*! + * Finds nodes located at distances lower that \a eps from a given point. + * \param [in] pos - pointer to coordinates of the point. This array is expected to + * be of length \a this->getSpaceDimension() at least, else the + * behavior is not warranted. + * \param [in] eps - the lowest distance between a point and a node at which the node is + * not returned by this method. + * \return DataArrayInt * - a new instance of DataArrayInt holding ids of nodes + * close to the point. The caller is to delete this + * array using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * + * \ref cpp_mcpointset_getnodeidsnearpoint "Here is a C++ example".
+ * \ref py_mcpointset_getnodeidsnearpoint "Here is a Python example". + */ DataArrayInt *MEDCouplingPointSet::getNodeIdsNearPoint(const double *pos, double eps) const throw(INTERP_KERNEL::Exception) { DataArrayInt *c=0,*cI=0; @@ -242,17 +322,37 @@ DataArrayInt *MEDCouplingPointSet::getNodeIdsNearPoint(const double *pos, double } /*! - * Given a point given by its position 'pos' this method finds the set of node ids that are a a distance lower than eps. - * Position 'pos' is expected to be of size getSpaceDimension()*nbOfNodes. If not the behabiour is not warranted. - * This method throws an exception if no coordiantes are set. + * Finds nodes located at distances lower that \a eps from given points. + * \param [in] pos - pointer to coordinates of the points. This array is expected to + * be of length \a nbOfPoints * \a this->getSpaceDimension() at least, else the + * behavior is not warranted. + * \param [in] nbOfPoints - number of points whose coordinates are given by \a pos + * parameter. + * \param [in] eps - the lowest distance between a point and a node at which the node is + * not returned by this method. + * \param [out] c - array returning ids of nodes located closer than \a eps to the + * given points. The caller + * is to delete this array using decrRef() as it is no more needed. + * \param [out] cI - for each i-th given point, the array specifies tuples of \a c + * holding ids of nodes close to the i-th point.
The i-th value of \a cI is an + * index of tuple of \a c holding id of a first (if any) node close to the + * i-th given point. Difference between the i-th and (i+1)-th value of \a cI + * (i.e. \a cI[ i+1 ] - \a cI[ i ]) defines number of nodes close to the i-th + * point (that can be zero!). For example, the group of nodes close to the + * second point is described by following range of indices [ \a cI[1], \a cI[2] ). + * The caller is to delete this array using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * + * \ref cpp_mcpointset_getnodeidsnearpoints "Here is a C++ example".
+ * \ref py_mcpointset_getnodeidsnearpoints "Here is a Python example". */ -void MEDCouplingPointSet::getNodeIdsNearPoints(const double *pos, int nbOfNodes, double eps, DataArrayInt *& c, DataArrayInt *& cI) const throw(INTERP_KERNEL::Exception) +void MEDCouplingPointSet::getNodeIdsNearPoints(const double *pos, int nbOfPoints, double eps, DataArrayInt *& c, DataArrayInt *& cI) const throw(INTERP_KERNEL::Exception) { if(!_coords) throw INTERP_KERNEL::Exception("MEDCouplingPointSet::getNodeIdsNearPoint : no coordiantes set !"); int spaceDim=getSpaceDimension(); MEDCouplingAutoRefCountObjectPtr points=DataArrayDouble::New(); - points->useArray(pos,false,CPP_DEALLOC,nbOfNodes,spaceDim); + points->useArray(pos,false,CPP_DEALLOC,nbOfPoints,spaceDim); _coords->computeTupleIdsNearTuples(points,eps,c,cI); } @@ -317,9 +417,17 @@ void MEDCouplingPointSet::renumberNodes2(const int *newNodeNumbers, int newNbOfN } /*! - * This method fills bbox params like that : bbox[0]=XMin, bbox[1]=XMax, bbox[2]=YMin... - * The returned bounding box is arranged along trihedron. - * @param bbox out array of size 2*this->getSpaceDimension(). + * Computes the minimum box bounding all nodes. The edges of the box are parallel to + * the Cartesian coordinate axes. The bounding box is described by coordinates of its + * two extremum points with minimal and maximal coordinates. + * \param [out] bbox - array filled with coordinates of extremum points in "no + * interlace" mode, i.e. xMin, xMax, yMin, yMax, zMin, zMax (if in 3D). This + * array, of length 2 * \a this->getSpaceDimension() at least, is to be + * pre-allocated by the caller. + * \throw If the coordinates array is not set. + * + * \ref cpp_mcpointset_getBoundingBox "Here is a C++ example".
+ * \ref py_mcpointset_getBoundingBox "Here is a Python example". */ void MEDCouplingPointSet::getBoundingBox(double *bbox) const throw(INTERP_KERNEL::Exception) { @@ -329,7 +437,9 @@ void MEDCouplingPointSet::getBoundingBox(double *bbox) const throw(INTERP_KERNEL } /*! - * This method removes useless nodes in coords. + * Removes "free" nodes, i.e. nodes not used to define any element. + * \throw If the coordinates array is not set. + * \throw If the elements are not defined. */ void MEDCouplingPointSet::zipCoords() { @@ -344,9 +454,9 @@ struct MEDCouplingCompAbs }; /*! - * This method expects that _coords attribute is set. - * @return the carateristic dimension of point set. This caracteristic dimension is the max of difference - * @exception If _coords attribute not set. + * Returns the carateristic dimension of \a this point set, that is a maximal + * absolute values of node coordinates. + * \throw If the coordinates array is not set. */ double MEDCouplingPointSet::getCaracteristicDimension() const { @@ -374,12 +484,22 @@ void MEDCouplingPointSet::recenterForMaxPrecision(double eps) throw(INTERP_KERNE } /*! - * Non const method that operates a rotation of 'this'. - * If spaceDim==2 'vector' parameter is ignored (and could be 0) and the rotation is done around 'center' with angle specified by 'angle'. - * If spaceDim==3 the rotation axe is defined by ('center','vector') and the angle is 'angle'. - * @param center an array of size getSpaceDimension(). - * @param vector in array of size getSpaceDimension(). - * @param angle angle of rotation in radian. + * Rotates \a this set of nodes by \a angle around either an axis (in 3D) or a point + * (in 2D). + * \param [in] center - coordinates either of an origin of rotation axis (in 3D) or + * of center of rotation (in 2D). This array is to be of size \a + * this->getSpaceDimension() at least. + * \param [in] vector - 3 components of a vector defining direction of the rotation + * axis in 3D. In 2D this parameter is not used. + * \param [in] angle - the rotation angle in radians. + * \throw If the coordinates array is not set. + * \throw If \a this->getSpaceDimension() != 2 && \a this->getSpaceDimension() != 3. + * \throw If \a center == NULL + * \throw If \a vector == NULL && \a this->getSpaceDimension() == 3. + * \throw If Magnitude of \a vector is zero. + * + * \ref cpp_mcpointset_rotate "Here is a C++ example".
+ * \ref py_mcpointset_rotate "Here is a Python example". */ void MEDCouplingPointSet::rotate(const double *center, const double *vector, double angle) { @@ -395,8 +515,14 @@ void MEDCouplingPointSet::rotate(const double *center, const double *vector, dou } /*! - * Non const method that operates a translation of 'this'. - * @param vector in array of size getSpaceDimension(). + * Translates \a this set of nodes. + * \param [in] vector - components of a translation vector. This array is to be of + * size \a this->getSpaceDimension() at least. + * \throw If the coordinates array is not set. + * \throw If \a vector == NULL. + * + * \ref cpp_mcpointset_translate "Here is a C++ example".
+ * \ref py_mcpointset_translate "Here is a Python example". */ void MEDCouplingPointSet::translate(const double *vector) { @@ -414,10 +540,17 @@ void MEDCouplingPointSet::translate(const double *vector) updateTime(); } + /*! - * Non const method that operates a scale on 'this' with 'point' as reference point of scale and with factor 'factor'. - * @param point in array of size getSpaceDimension(). - * @param factor factor of the scaling + * Applies scaling transformation to \a this set of nodes. + * \param [in] point - coordinates of a scaling center. This array is to be of + * size \a this->getSpaceDimension() at least. + * \param [in] factor - a scale factor. + * \throw If the coordinates array is not set. + * \throw If \a point == NULL. + * + * \ref cpp_mcpointset_scale "Here is a C++ example".
+ * \ref py_mcpointset_scale "Here is a Python example". */ void MEDCouplingPointSet::scale(const double *point, double factor) { @@ -439,12 +572,15 @@ void MEDCouplingPointSet::scale(const double *point, double factor) } /*! - * This method is only available for already defined coordinates. - * If not an INTERP_KERNEL::Exception is thrown. The 'newSpaceDim' input must be greater or equal to 1. - * This method simply convert this to newSpaceDim space : - * - by putting a 0. for each \f$ i^{th} \f$ components of each coord of nodes so that i>=getSpaceDim(), if 'newSpaceDim'>getSpaceDimsion() - * - by ignoring each \f$ i^{th} \f$ components of each coord of nodes so that i >= 'newSpaceDim', 'newSpaceDim'getSpaceDimension(), nothing is done. + * \param [in] newSpaceDim - the new space dimension. + * \param [in] dftValue - the value to assign to added components of point coordinates + * (if the dimension increases). + * \throw If the coordinates array is not set. + * \throw If \a newSpaceDim < 1. */ void MEDCouplingPointSet::changeSpaceDimension(int newSpaceDim, double dftValue) throw(INTERP_KERNEL::Exception) { @@ -462,8 +598,14 @@ void MEDCouplingPointSet::changeSpaceDimension(int newSpaceDim, double dftValue) } /*! - * This method try to substitute this->_coords with other._coords if arrays match. - * This method potentially modifies 'this' if it succeeds, otherway an exception is thrown. + * Substitutes \a this->_coords with \a other._coords provided that coordinates of + * the two point sets match with a specified precision, else an exception is thrown. + * \param [in] other - the other point set whose coordinates array will be used by + * \a this point set in case of their equality. + * \param [in] epsilon - the precision used to compare coordinates. + * \throw If the coordinates array of \a this is not set. + * \throw If the coordinates array of \a other is not set. + * \throw If the coordinates of \a this and \a other do not match. */ void MEDCouplingPointSet::tryToShareSameCoords(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception) { @@ -495,21 +637,33 @@ void MEDCouplingPointSet::duplicateNodesInCoords(const int *nodeIdsToDuplicateBg } /*! - * This method is expecting to be called for meshes so that getSpaceDimension() returns 3. - * This method returns in 'nodes' output all the nodes that are at a distance lower than epsilon from plane - * defined by the point 'pt' and the vector 'vec'. - * @param pt points to an array of size 3 and represents a point that owns to plane. - * @param vec points to an array of size 3 and represents the normal vector of the plane. The norm of the vector is not compulsory equal to 1. But norm must be greater than 10*abs(eps) - * @param eps is the maximal distance around the plane where node in this->_coords will be picked. - * @param nodes is the output of the method. The vector is not compulsory empty before call. The nodes that fulfills the condition will be added at the end of the nodes. + * Finds nodes located at distance lower that \a eps from a specified plane. + * \param [in] pt - 3 components of a point defining location of the plane. + * \param [in] vec - 3 components of a normal vector to the plane. Vector magnitude + * must be greater than 10*\a eps. + * \param [in] eps - maximal distance of a node from the plane at which the node is + * considered to lie on the plane. + * \param [in,out] nodes - a vector returning ids of found nodes. This vector is not + * cleared before filling in. + * \throw If the coordinates array is not set. + * \throw If \a pt == NULL. + * \throw If \a vec == NULL. + * \throw If the magnitude of \a vec is zero. + * \throw If \a this->getSpaceDimension() != 3. */ void MEDCouplingPointSet::findNodesOnPlane(const double *pt, const double *vec, double eps, std::vector& nodes) const throw(INTERP_KERNEL::Exception) { if(getSpaceDimension()!=3) throw INTERP_KERNEL::Exception("MEDCouplingPointSet::findNodesOnPlane : Invalid spacedim to be applied on this ! Must be equal to 3 !"); + if(!pt) + throw INTERP_KERNEL::Exception("MEDCouplingPointSet::findNodesOnPlane : NULL point pointer specified !"); + if(!vec) + throw INTERP_KERNEL::Exception("MEDCouplingPointSet::findNodesOnPlane : NULL vector pointer specified !"); int nbOfNodes=getNumberOfNodes(); double a=vec[0],b=vec[1],c=vec[2],d=-pt[0]*vec[0]-pt[1]*vec[1]-pt[2]*vec[2]; double deno=sqrt(a*a+b*b+c*c); + if(deno::min()) + throw INTERP_KERNEL::Exception("MEDCouplingPointSet::findNodesOnPlane : vector pointer specified has norm equal to 0. !"); const double *work=_coords->getConstPointer(); for(int i=0;igetSpaceDimension and represents a point that owns to plane. - * @param vec points to an array of size this->getSpaceDimension and represents the direction vector of the line. The norm of the vector is not compulsory equal to 1. - * But norm must be greater than 10*abs(eps) - * @param eps is the maximal distance around the plane where node in this->_coords will be picked. - * @param nodes is the output of the method. The vector is not compulsory empty before call. The nodes that fulfills the condition will be added at the end of the nodes. + * Finds nodes located at distance lower that \a eps from a specified line in 2D and 3D. + * \param [in] pt - components of coordinates of an initial point of the line. This + * array is to be of size \a this->getSpaceDimension() at least. + * \param [in] vec - components of a vector defining the line direction. This array + * is to be of size \a this->getSpaceDimension() at least. Vector magnitude + * must be greater than 10*\a eps. + * \param [in] eps - maximal distance of a node from the line at which the node is + * considered to lie on the line. + * \param [in,out] nodes - a vector returning ids of found nodes. This vector is not + * cleared before filling in. + * \throw If the coordinates array is not set. + * \throw If \a pt == NULL. + * \throw If \a vec == NULL. + * \throw If the magnitude of \a vec is zero. + * \throw If ( \a this->getSpaceDimension() != 3 && \a this->getSpaceDimension() != 2 ). */ void MEDCouplingPointSet::findNodesOnLine(const double *pt, const double *vec, double eps, std::vector& nodes) const throw(INTERP_KERNEL::Exception) { int spaceDim=getSpaceDimension(); if(spaceDim!=2 && spaceDim!=3) throw INTERP_KERNEL::Exception("MEDCouplingPointSet::findNodesOnLine : Invalid spacedim to be applied on this ! Must be equal to 2 or 3 !"); + if(!pt) + throw INTERP_KERNEL::Exception("MEDCouplingPointSet::findNodesOnLine : NULL point pointer specified !"); + if(!vec) + throw INTERP_KERNEL::Exception("MEDCouplingPointSet::findNodesOnLine : NULL vector pointer specified !"); int nbOfNodes=getNumberOfNodes(); double den=0.; for(int i=0;igetSpaceDimension() != \a m2->getSpaceDimension(). */ DataArrayDouble *MEDCouplingPointSet::MergeNodesArray(const MEDCouplingPointSet *m1, const MEDCouplingPointSet *m2) throw(INTERP_KERNEL::Exception) { @@ -838,10 +1015,14 @@ void MEDCouplingPointSet::Rotate3DAlg(const double *center, const double *vect, } /*! - * This method implements pure virtual method MEDCouplingMesh::buildPart. - * This method build a part of 'this' by simply keeping cells whose ids are in ['start','end'). - * The coords are kept unchanged contrary to pure virtual method MEDCouplingMesh::buildPartAndReduceNodes. - * The returned mesh has to be managed by the caller. + * Creates a new MEDCouplingMesh containing a part of cells of \a this mesh. The new + * mesh shares a coordinates array with \a this one. The cells to include to the + * result mesh are specified by an array of cell ids. + * \param [in] start - an array of cell ids to include to the result mesh. + * \param [in] end - specifies the end of the array \a start, so that + * the last value of \a start is \a end[ -1 ]. + * \return MEDCouplingMesh * - a new instance of MEDCouplingMesh. The caller is to + * delete this mesh using decrRef() as it is no more needed. */ MEDCouplingMesh *MEDCouplingPointSet::buildPart(const int *start, const int *end) const { @@ -849,13 +1030,17 @@ MEDCouplingMesh *MEDCouplingPointSet::buildPart(const int *start, const int *end } /*! - * This method implements pure virtual method MEDCouplingMesh::buildPartAndReduceNodes. - * This method build a part of 'this' by simply keeping cells whose ids are in ['start','end') \b and potentially reduces the nodes set - * behind returned mesh. This cause an overhead but it is lesser in memory. - * This method returns an array too. This array allows to the caller to know the mapping between nodeids in 'this' and nodeids in - * returned mesh. This is quite useful for MEDCouplingFieldDouble on nodes for example... - * 'arr' is in old2New format of size ret->getNumberOfCells like MEDCouplingUMesh::zipCoordsTraducer is. - * The returned mesh has to be managed by the caller. + * Creates a new MEDCouplingMesh containing a part of cells of \a this mesh. The + * cells to include to the result mesh are specified by an array of cell ids. + *
This method additionally returns a renumbering map in "Old to New" mode + * which allows the caller to know the mapping between nodes in \a this and the result mesh. + * \param [in] start - an array of cell ids to include to the result mesh. + * \param [in] end - specifies the end of the array \a start, so that + * the last value of \a start is \a end[ -1 ]. + * \param [out] arr - a new DataArrayInt that is the "Old to New" renumbering + * map. The caller is to delete this array using decrRef() as it is no more needed. + * \return MEDCouplingMesh * - a new instance of MEDCouplingMesh. The caller is to + * delete this mesh using decrRef() as it is no more needed. */ MEDCouplingMesh *MEDCouplingPointSet::buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const { diff --git a/src/MEDCoupling/MEDCouplingPointSet.hxx b/src/MEDCoupling/MEDCouplingPointSet.hxx index 41c5eb21a..b23f11800 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.hxx +++ b/src/MEDCoupling/MEDCouplingPointSet.hxx @@ -56,9 +56,7 @@ namespace ParaMEDMEM int getNumberOfNodes() const; int getSpaceDimension() const; void setCoords(const DataArrayDouble *coords); - //! This method returns directly the array in 'this' \b without incrementing ref counter. The pointer is dealed by the mesh. The caller should not deal (decrRef) with this pointer const DataArrayDouble *getCoords() const { return _coords; } - //! This method returns directly the array in 'this' \b without incrementing ref counter. The pointer is dealed by the mesh. The caller should not deal (decrRef) with this pointer DataArrayDouble *getCoords() { return _coords; } DataArrayDouble *getCoordinatesAndOwner() const; void copyTinyStringsFrom(const MEDCouplingMesh *other) throw(INTERP_KERNEL::Exception); @@ -72,7 +70,7 @@ namespace ParaMEDMEM void getCoordinatesOfNode(int nodeId, std::vector& coo) const throw(INTERP_KERNEL::Exception); DataArrayInt *buildPermArrayForMergeNode(double precision, int limitNodeId, bool& areNodesMerged, int& newNbOfNodes) const; DataArrayInt *getNodeIdsNearPoint(const double *pos, double eps) const throw(INTERP_KERNEL::Exception); - void getNodeIdsNearPoints(const double *pos, int nbOfNodes, double eps, DataArrayInt *& c, DataArrayInt *& cI) const throw(INTERP_KERNEL::Exception); + void getNodeIdsNearPoints(const double *pos, int nbOfPoints, double eps, DataArrayInt *& c, DataArrayInt *& cI) const throw(INTERP_KERNEL::Exception); void findCommonNodes(double prec, int limitNodeId, DataArrayInt *&comm, DataArrayInt *&commIndex) const; DataArrayInt *buildNewNumberingFromCommonNodesFormat(const DataArrayInt *comm, const DataArrayInt *commIndex, int& newNbOfNodes) const; @@ -105,7 +103,6 @@ namespace ParaMEDMEM virtual void renumberNodes(const int *newNodeNumbers, int newNbOfNodes); virtual void renumberNodes2(const int *newNodeNumbers, int newNbOfNodes); virtual bool isEmptyMesh(const std::vector& tinyInfo) const = 0; - //! size of returned tinyInfo must be always the same. void getTinySerializationInformation(std::vector& tinyInfoD, std::vector& tinyInfo, std::vector& littleStrings) const; void resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const; void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const; diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 312e9bc53..b842fa2c7 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -206,8 +206,8 @@ void MEDCouplingUMesh::checkCoherency2(double eps) const throw(INTERP_KERNEL::Ex void MEDCouplingUMesh::setMeshDimension(int meshDim) { - if(meshDim<-1) - throw INTERP_KERNEL::Exception("Invalid meshDim specified ! Must be greater or equal to -1 !"); + if(meshDim<-1 || meshDim>3) + throw INTERP_KERNEL::Exception("Invalid meshDim specified ! Must be greater or equal to -1 and lower or equal to 3 !"); _mesh_dim=meshDim; declareAsNew(); } diff --git a/src/MEDCoupling/Makefile.am b/src/MEDCoupling/Makefile.am index 4202fab88..ed3728872 100644 --- a/src/MEDCoupling/Makefile.am +++ b/src/MEDCoupling/Makefile.am @@ -52,7 +52,8 @@ dist_libmedcoupling_la_SOURCES = \ MEDCouplingExtrudedMesh.cxx MEDCouplingMesh.cxx MEDCouplingGaussLocalization.cxx \ MEDCouplingNatureOfField.cxx MEDCouplingMultiFields.cxx \ MEDCouplingDefinitionTime.cxx MEDCouplingFieldOverTime.cxx \ - MEDCouplingCurveLinearMesh.cxx MEDCouplingStructuredMesh.cxx + MEDCouplingCurveLinearMesh.cxx MEDCouplingStructuredMesh.cxx \ + MEDCouplingMemArrayChar.cxx libmedcoupling_la_LDFLAGS= diff --git a/src/MEDCoupling/Test/MEDCouplingExamplesTest.cxx b/src/MEDCoupling/Test/MEDCouplingExamplesTest.cxx index 649fae28c..1db61dfa7 100644 --- a/src/MEDCoupling/Test/MEDCouplingExamplesTest.cxx +++ b/src/MEDCoupling/Test/MEDCouplingExamplesTest.cxx @@ -26,6 +26,231 @@ #include "MEDCouplingMemArray.hxx" #include "MEDCouplingMultiFields.hxx" + +void CppExample_MEDCouplingPointSet_scale() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingPointSet_scale_1] + double coords[4*2]={0.0,0.0, 1.0,0.0, 1.0,1.0, 0.0,1.0}; // 2D coordinates of 4 nodes + DataArrayDouble *coordsArr=DataArrayDouble::New(); + coordsArr->useExternalArrayWithRWAccess(coords, 4,2); + MEDCouplingUMesh *mesh=MEDCouplingUMesh::New(); + mesh->setCoords(coordsArr); + DataArrayDouble *initCoords = coordsArr->deepCpy(); + //! [CppSnippet_MEDCouplingPointSet_scale_1] + //! [CppSnippet_MEDCouplingPointSet_scale_2] + const double center[2] = {0.,0.}; + const double factor = 2.; + mesh->scale( center, factor ); + //! [CppSnippet_MEDCouplingPointSet_scale_2] + //! [CppSnippet_MEDCouplingPointSet_scale_3] + const DataArrayDouble * coordsArr2 = mesh->getCoords(); + CPPUNIT_ASSERT( coordsArr2->isEqualWithoutConsideringStr( *initCoords, 1.0 )); + CPPUNIT_ASSERT( !coordsArr2->isEqualWithoutConsideringStr( *initCoords, 0.9 )); + // release data + mesh->decrRef(); + coordsArr->decrRef(); + initCoords->decrRef(); + //! [CppSnippet_MEDCouplingPointSet_scale_3] +} + +void CppExample_MEDCouplingPointSet_translate() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingPointSet_translate_1] + double coords[4*2]={0.0,0.0, 1.0,0.0, 1.0,1.0, 0.0,1.0}; // 2D coordinates of 4 nodes + DataArrayDouble *coordsArr=DataArrayDouble::New(); + coordsArr->useExternalArrayWithRWAccess(coords, 4,2); + MEDCouplingUMesh *mesh=MEDCouplingUMesh::New(); + mesh->setCoords(coordsArr); + DataArrayDouble *initCoords = coordsArr->deepCpy(); + //! [CppSnippet_MEDCouplingPointSet_translate_1] + //! [CppSnippet_MEDCouplingPointSet_translate_2] + double vector[2] = {1.,1.}; + mesh->translate( vector ); + //! [CppSnippet_MEDCouplingPointSet_translate_2] + //! [CppSnippet_MEDCouplingPointSet_translate_3] + const DataArrayDouble * coordsArr2 = mesh->getCoords(); + CPPUNIT_ASSERT( coordsArr2->isEqualWithoutConsideringStr( *initCoords, 1.0 )); + CPPUNIT_ASSERT( !coordsArr2->isEqualWithoutConsideringStr( *initCoords, 0.9 )); + // release data + mesh->decrRef(); + coordsArr->decrRef(); + initCoords->decrRef(); + //! [CppSnippet_MEDCouplingPointSet_translate_3] +} + +void CppExample_MEDCouplingPointSet_rotate() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingPointSet_rotate_1] + double coords[4*2]={0.0,0.0, 0.1,0.0, 0.1,0.1, 0.0,0.1}; // 2D coordinates of 4 nodes + DataArrayDouble *coordsArr=DataArrayDouble::New(); + coordsArr->useExternalArrayWithRWAccess(coords, 4,2); + MEDCouplingUMesh *mesh=MEDCouplingUMesh::New(); + mesh->setCoords(coordsArr); + //! [CppSnippet_MEDCouplingPointSet_rotate_1] + //! [CppSnippet_MEDCouplingPointSet_rotate_2] + double center[3] = {0.,0.,0.}; // it suits for 2D as well + double vector[3] = {0.,0.,1.}; // it is not used in 2D + mesh->rotate( center, vector, -M_PI/2); + //! [CppSnippet_MEDCouplingPointSet_rotate_2] + //! [CppSnippet_MEDCouplingPointSet_rotate_3] + mesh->changeSpaceDimension(3); + mesh->rotate( center, vector, +M_PI/2); + //! [CppSnippet_MEDCouplingPointSet_rotate_3] + //! [CppSnippet_MEDCouplingPointSet_rotate_4] + mesh->changeSpaceDimension(2); + const DataArrayDouble * coordsArr2 = mesh->getCoords(); + CPPUNIT_ASSERT( coordsArr2->isEqualWithoutConsideringStr( *coordsArr, 1e-13 )); + // release data + mesh->decrRef(); + coordsArr->decrRef(); + //! [CppSnippet_MEDCouplingPointSet_rotate_4] +} + +void CppExample_MEDCouplingPointSet_getBoundingBox() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingPointSet_getBoundingBox_1] + double cc[2*3]={0.0, 0.1, 0.2, // 3D coordinates of 2 nodes + 2.0, 2.1, 2.2}; + DataArrayDouble *coordsArr=DataArrayDouble::New(); + coordsArr->useExternalArrayWithRWAccess(cc, 2,3); + MEDCouplingUMesh *mesh=MEDCouplingUMesh::New(); + mesh->setCoords(coordsArr); + coordsArr->decrRef(); + //! [CppSnippet_MEDCouplingPointSet_getBoundingBox_1] + //! [CppSnippet_MEDCouplingPointSet_getBoundingBox_2] + double bbox[3][2]; + mesh->getBoundingBox( (double*) bbox ); + mesh->decrRef(); + + // check the returned coordinates of extremum points of the bounding box + for ( int i = 0; i < 2; ++i ) // point id + for ( int j = 0; j < 3; ++j ) // component + CPPUNIT_ASSERT_DOUBLES_EQUAL( cc[ i*3 + j ], bbox[j][i], 1e-13); + //! [CppSnippet_MEDCouplingPointSet_getBoundingBox_2] +} + +void CppExample_MEDCouplingPointSet_getNodeIdsNearPoint() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_1] + // 2D coordinates of 5 nodes + double coords[5*2]={0.3,-0.301, // #0 + 0.2,-0.3, // #1 + 0.3,-0.302, // #2 + 1.1,0.0, // #3 + 0.3,-0.303};// #4 + DataArrayDouble *coordsArr=DataArrayDouble::New(); + coordsArr->useExternalArrayWithRWAccess(coords, 5,2); + MEDCouplingUMesh *mesh=MEDCouplingUMesh::New(); + mesh->setCoords(coordsArr); + coordsArr->decrRef(); + //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_1] + //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_2] + double point [2]={0.3, -0.3}; // point close to nodes #0, #2 and #4 + DataArrayInt *ids = mesh->getNodeIdsNearPoint(point, 1e-13); + + // check found ids + const int expectedIDs[3] = {0,2,4}; + DataArrayInt * okIDs = ids->getIdsEqualList ( expectedIDs, expectedIDs+3 ); + CPPUNIT_ASSERT_EQUAL(3, okIDs->getNumberOfTuples()); + + // release data + mesh->decrRef(); + ids->decrRef(); + okIDs->decrRef(); + //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoint_2] +} +void CppExample_MEDCouplingPointSet_getNodeIdsNearPoints() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_1] + // 2D coordinates of 7 nodes + double coords[7*2]={0.3,-0.301, // #0 + 0.2,-0.3, // #1 + 0.3,-0.302, // #2 + 1.1,0.0, // #3 + 1.1,0.0, // #4 + 1.1,0.002, // #5 + 0.3,-0.303};// #6 + DataArrayDouble *coordsArr=DataArrayDouble::New(); + coordsArr->useExternalArrayWithRWAccess(coords, 7,2); + MEDCouplingUMesh *mesh=MEDCouplingUMesh::New(); + mesh->setCoords(coordsArr); + coordsArr->decrRef(); + //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_1] + //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_2] + const int nbOfPoints = 3; + double points [nbOfPoints*2]={0.2,-0.301, // ~ node #1 + 0.0, 0.0, + 1.1, 0.002}; // ~ nodes #3, #4 and #5 + DataArrayInt *ids, *idsIndex; + mesh->getNodeIdsNearPoints(points, nbOfPoints, 1e-13,ids,idsIndex); + + // check found ids (i.e. contents of 'ids' array) + const int expectedIDs[4] = {1, 3, 4, 5}; + DataArrayInt * okIDs = ids->getIdsEqualList ( expectedIDs, expectedIDs+4 ); + CPPUNIT_ASSERT_EQUAL(4, okIDs->getNumberOfTuples()); + + // release data + mesh->decrRef(); + ids->decrRef(); + idsIndex->decrRef(); + okIDs->decrRef(); + //! [CppSnippet_MEDCouplingPointSet_getNodeIdsNearPoints_2] +} + +void CppExample_MEDCouplingPointSet_findCommonNodes() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingPointSet_findCommonNodes_1] + double coords[6*2]={0.3,-0.301, // 0 + 0.2,-0.3, // 1 + 0.3,-0.302, // 2 + 1.1,0.0, // 3 + 1.1,0.0, // 4 + 0.3,-0.303};// 5 + DataArrayDouble *coordsArr=DataArrayDouble::New(); + coordsArr->useExternalArrayWithRWAccess(coords, 6,2); + MEDCouplingUMesh *mesh=MEDCouplingUMesh::New(); + mesh->setCoords(coordsArr); + coordsArr->decrRef(); + //! [CppSnippet_MEDCouplingPointSet_findCommonNodes_1] + //! [CppSnippet_MEDCouplingPointSet_findCommonNodes_2] + DataArrayInt *com, *comI; + mesh->findCommonNodes(1e-13,-1,com,comI); + CPPUNIT_ASSERT_EQUAL(2, com->getNumberOfTuples()); + mesh->findCommonNodes(0.004,-1,com,comI); + CPPUNIT_ASSERT_EQUAL(5, com->getNumberOfTuples()); + //! [CppSnippet_MEDCouplingPointSet_findCommonNodes_2] + mesh->decrRef(); + com->decrRef(); + comI->decrRef(); +} + +void CppExample_MEDCouplingPointSet_getCoordinatesOfNode() +{ + using namespace ParaMEDMEM; + //! [CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_1] + double coords[18]={-0.3,-0.3, 0.2,-0.3, 0.7,-0.3}; + DataArrayDouble *coordsArr=DataArrayDouble::New(); + coordsArr->useExternalArrayWithRWAccess(coords, 3,2); + MEDCouplingUMesh *mesh=MEDCouplingUMesh::New(); + mesh->setCoords(coordsArr); + coordsArr->decrRef(); + //! [CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_1] + //! [CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_2] + std::vector coords2; + mesh->getCoordinatesOfNode(1,coords2); + CPPUNIT_ASSERT_DOUBLES_EQUAL(coords[0],coords2[0],1e-13); + CPPUNIT_ASSERT_DOUBLES_EQUAL(coords[1],coords2[1],1e-13); + //! [CppSnippet_MEDCouplingPointSet_getCoordinatesOfNode_2] + mesh->decrRef(); +} + void CppExample_DataArrayInt_buildPermutationArr() { using namespace ParaMEDMEM; diff --git a/src/MEDCoupling_Swig/CMakeLists.txt b/src/MEDCoupling_Swig/CMakeLists.txt index bbd5f1848..ff93d516c 100644 --- a/src/MEDCoupling_Swig/CMakeLists.txt +++ b/src/MEDCoupling_Swig/CMakeLists.txt @@ -27,7 +27,7 @@ SET_SOURCE_FILES_PROPERTIES(MEDCoupling.i PROPERTIES SWIG_DEFINITIONS "-shadow") INCLUDE_DIRECTORIES( ${PYTHON_INCLUDE_DIRS} - ${PTHREAD_INCLUDE_DIRS} + ${PTHREAD_INCLUDE_DIRS} # pthread dependancy due to python2.7 library ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR} diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 06111e164..d832e9df6 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -2669,6 +2669,12 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(nodeCor==None); cellCor=0; self.assertTrue(nodeCor==None); + a,b=mesh1.checkDeepEquivalWith(mesh2,0,1e-12); + self.assertEqual(renum,list(a.getValues())) + self.assertTrue(b==None); + mesh2.setCoords(mesh1.getCoords()) + a=mesh1.checkDeepEquivalOnSameNodesWith(mesh2,0,1e-12); + self.assertEqual(renum,list(a.getValues())) #4th test : cell and node permutation by keeping the first the middle and the last as it is. mesh2=MEDCouplingDataForTest.build2DTargetMesh_3(); renum2=[0,2,1,3,4,5,6,8,7,9,10] @@ -11445,6 +11451,167 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertAlmostEqual(res6[1],4.*integExp1,11) pass + def testSwig2SlowDADFindClosestTupleId(self): + nbPts=[10,] + for nbPt in nbPts: + d=DataArrayDouble(nbPt) ; d.iota() ; d*=1./(nbPt-1) + c=MEDCouplingCMesh() ; c.setCoords(d,d) ; m=c.buildUnstructured() ; pts=m.getCoords() ; del m + # + d0=DataArrayDouble((nbPt-1)*(nbPt-1)) ; d0.iota() ; d0*=(3./((nbPt-1)*(nbPt-1))) ; d0=d0.applyFunc("exp(x)-1") + d1=DataArrayDouble((nbPt-1)*(nbPt-1)) ; d1.iota() + d2=DataArrayDouble.Meld(d0,d1) ; d2=d2.fromPolarToCart() ; d2+=[0.32,0.73] + ids=pts.findClosestTupleId(d2) + #print "Start of costly computation" + idsExpected=DataArrayInt(len(d2)) + tmp=1e300 + for i,elt in enumerate(d2): + l,m=(pts-elt).magnitude().getMinValue() + idsExpected.setIJSilent(i,0,m) + if lgetPointer()); std::copy(eltsIndex.begin(),eltsIndex.end(),d1->getPointer()); PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - d0->incrRef(); - d1->incrRef(); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } @@ -617,10 +649,8 @@ namespace ParaMEDMEM std::copy(elts.begin(),elts.end(),d0->getPointer()); std::copy(eltsIndex.begin(),eltsIndex.end(),d1->getPointer()); PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - d0->incrRef(); - d1->incrRef(); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } @@ -671,6 +701,24 @@ namespace ParaMEDMEM PyList_SetItem(res,1,SWIG_NewPointerObj(SWIG_as_voidptr(nodeCor),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, nodeCor?SWIG_POINTER_OWN | 0:0 )); return res; } + + PyObject *checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec) const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *cellCor=0,*nodeCor=0; + self->checkDeepEquivalWith(other,cellCompPol,prec,cellCor,nodeCor); + PyObject *res = PyList_New(2); + PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(cellCor),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, cellCor?SWIG_POINTER_OWN | 0:0 )); + PyList_SetItem(res,1,SWIG_NewPointerObj(SWIG_as_voidptr(nodeCor),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, nodeCor?SWIG_POINTER_OWN | 0:0 )); + return res; + } + + DataArrayInt *checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec) const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *cellCor=0; + self->checkDeepEquivalOnSameNodesWith(other,cellCompPol,prec,cellCor); + return cellCor; + } + DataArrayInt *getCellIdsFullyIncludedInNodeIds(PyObject *li) const throw(INTERP_KERNEL::Exception) { void *da=0; @@ -823,119 +871,1115 @@ namespace ParaMEDMEM return ret; } - void translate(PyObject *vector) throw(INTERP_KERNEL::Exception) - { - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - int spaceDim=self->getSpaceDimension(); - const char msg[]="Python wrap of MEDCouplingPointSet::translate : "; - const double *vectorPtr=convertObjToPossibleCpp5_Safe(vector,sw,val,a,aa,bb,msg,1,spaceDim,true); - self->translate(vectorPtr); - } + void translate(PyObject *vector) throw(INTERP_KERNEL::Exception) + { + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + int spaceDim=self->getSpaceDimension(); + const char msg[]="Python wrap of MEDCouplingPointSet::translate : "; + const double *vectorPtr=convertObjToPossibleCpp5_Safe(vector,sw,val,a,aa,bb,msg,1,spaceDim,true); + self->translate(vectorPtr); + } + + void rotate(PyObject *center, double alpha) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Python wrap of MEDCouplingPointSet::rotate : "; + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + int spaceDim=self->getSpaceDimension(); + const double *centerPtr=convertObjToPossibleCpp5_Safe(center,sw,val,a,aa,bb,msg,1,spaceDim,true); + self->rotate(centerPtr,0,alpha); + } + + void rotate(PyObject *center, PyObject *vector, double alpha) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Python wrap of MEDCouplingPointSet::rotate : "; + double val; + DataArrayDouble *a; + DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + int spaceDim=self->getSpaceDimension(); + const double *centerPtr=convertObjToPossibleCpp5_Safe(center,sw,val,a,aa,bb,msg,1,spaceDim,true); + const double *vectorPtr=convertObjToPossibleCpp5_Safe(vector,sw,val,a,aa,bb,msg,1,spaceDim,false); + self->rotate(centerPtr,vectorPtr,alpha); + } + + PyObject *getAllGeoTypes() const throw(INTERP_KERNEL::Exception) + { + std::set result=self->getAllGeoTypes(); + std::set::const_iterator iL=result.begin(); + PyObject *res=PyList_New(result.size()); + for(int i=0;iL!=result.end(); i++, iL++) + PyList_SetItem(res,i,PyInt_FromLong(*iL)); + return res; + } + + static MEDCouplingMesh *MergeMeshes(PyObject *li) throw(INTERP_KERNEL::Exception) + { + 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()); + return ret.retn(); + } + 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()); + return ret.retn(); + } + } + 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()); + return ret.retn(); + } + } + 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); + return ret.retn(); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {//DataArrayByte.New(5) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayByte::New(); + ret->alloc(nbOfTuples1,1); + return ret.retn(); + } + } + 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::DataArrayAsciiCharTuple +{ + std::string __str__() const + { + return self->repr(); + } + + DataArrayAsciiChar *buildDAAsciiChar() + { + return self->buildDAAsciiChar(1,self->getNumberOfCompo()); + } +} + +%extend ParaMEDMEM::DataArrayAsciiCharIterator +{ + PyObject *next() + { + DataArrayAsciiCharTuple *ret=self->nextt(); + if(ret) + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiCharTuple,SWIG_POINTER_OWN | 0); + else + { + PyErr_SetString(PyExc_StopIteration,"No more data."); + return 0; + } + } +} + +%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([\"abc\",\"de\",\"fghi\"])\n-DataArrayAsciiChar.New([\"abc\",\"de\",\"fghi\"],\"t\")\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()); + return ret.retn(); + } + 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()); + return ret.retn(); + } + } + else if(PyString_Check(nbOfTuples)) + { + if(PyString_Size(nbOfTuples)!=1) + throw INTERP_KERNEL::Exception(msg); + //DataArrayAsciiChar.New(["abc","de","fghi"],"t") + std::vector tmp; + if(fillStringVector(elt0,tmp)) + return DataArrayAsciiChar::New(tmp,PyString_AsString(nbOfTuples)[0]); + else + throw INTERP_KERNEL::Exception(msg); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + { + std::vector tmmp; + if(fillStringVector(elt0,tmmp)) + //DataArrayAsciiChar.New(["abc","de","fghi"]) + return DataArrayAsciiChar::New(tmmp,' '); + 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()); + return ret.retn(); + } + } + } + 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); + return ret.retn(); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + throw INTERP_KERNEL::Exception(msg); + } + else + {//DataArrayAsciiChar.New(5) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayAsciiChar::New(); + ret->alloc(nbOfTuples1,1); + return ret.retn(); + } + } + else + throw INTERP_KERNEL::Exception(msg); + } + + DataArrayAsciiChar(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) + { + return ParaMEDMEM_DataArrayAsciiChar_New__SWIG_3(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) const 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; + } - void rotate(PyObject *center, double alpha) throw(INTERP_KERNEL::Exception) + int index(PyObject *obj) const throw(INTERP_KERNEL::Exception) + { + int nbOfCompo=self->getNumberOfComponents(); + switch(nbOfCompo) + { + case 1: { - const char msg[]="Python wrap of MEDCouplingPointSet::rotate : "; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - int spaceDim=self->getSpaceDimension(); - const double *centerPtr=convertObjToPossibleCpp5_Safe(center,sw,val,a,aa,bb,msg,1,spaceDim,true); - self->rotate(centerPtr,0,alpha); + 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); + } + } - void rotate(PyObject *center, PyObject *vector, double alpha) throw(INTERP_KERNEL::Exception) + bool __contains__(PyObject *obj) const throw(INTERP_KERNEL::Exception) + { + int nbOfCompo=self->getNumberOfComponents(); + switch(nbOfCompo) + { + case 0: + return false; + case 1: { - const char msg[]="Python wrap of MEDCouplingPointSet::rotate : "; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - int spaceDim=self->getSpaceDimension(); - const double *centerPtr=convertObjToPossibleCpp5_Safe(center,sw,val,a,aa,bb,msg,1,spaceDim,true); - const double *vectorPtr=convertObjToPossibleCpp5_Safe(vector,sw,val,a,aa,bb,msg,1,spaceDim,false); - self->rotate(centerPtr,vectorPtr,alpha); + 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); + } + } - PyObject *getAllGeoTypes() const throw(INTERP_KERNEL::Exception) - { - std::set result=self->getAllGeoTypes(); - std::set::const_iterator iL=result.begin(); - PyObject *res=PyList_New(result.size()); - for(int i=0;iL!=result.end(); i++, iL++) - PyList_SetItem(res,i,PyInt_FromLong(*iL)); - return res; + PyObject *__getitem__(PyObject *obj) const throw(INTERP_KERNEL::Exception) + { + int sw,iTypppArr; + std::vector stdvecTyyppArr; + std::pair > sTyyppArr; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + convertObjToPossibleCpp2(obj,self->getNumberOfTuples(),sw,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp); + switch(sw) + { + case 1: + return ParaMEDMEM_DataArrayAsciiChar_getTuple(self,iTypppArr); + case 2: + return convertDataArrayChar(self->selectByTupleIdSafe(&stdvecTyyppArr[0],&stdvecTyyppArr[0]+stdvecTyyppArr.size()), SWIG_POINTER_OWN | 0 ); + case 3: + return convertDataArrayChar(self->selectByTupleId2(sTyyppArr.first,sTyyppArr.second.first,sTyyppArr.second.second), SWIG_POINTER_OWN | 0 ); + case 4: + return convertDataArrayChar(self->selectByTupleIdSafe(daIntTyypp->begin(),daIntTyypp->end()), SWIG_POINTER_OWN | 0 ); + default: + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::__getitem__ : supporting int, list of int, tuple of int, DataArrayInt and slice in input !"); + } + } + + DataArrayAsciiChar *__setitem__(PyObject *obj, PyObject *value) throw(INTERP_KERNEL::Exception) + { + static const char msg[]="DataArrayAsciiChar::__setitem__ : supporting int, list of int, tuple of int, DataArrayInt and slice in input, and 4 types accepted in value : string, list or tuple of strings having same size, not null DataArrayChar instance."; + int sw1,iTypppArr; + std::vector stdvecTyyppArr; + std::pair > sTyyppArr; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + int nbOfCompo=self->getNumberOfTuples(); + convertObjToPossibleCpp2(obj,nbOfCompo,sw1,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp); + int sw2; + char vc; std::string sc; std::vector vsc; DataArrayChar *dacc=0; + convertObjToPossibleCpp6(value,sw2,vc,sc,vsc,dacc); + switch(sw1) + { + case 1: + {//obj int + switch(sw2) + {//value char + case 1: + { + self->setPartOfValuesSimple3(vc,&iTypppArr,&iTypppArr+1,0,nbOfCompo,1); + return self; + } + //value string + case 2: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(sc); + self->setPartOfValues3(tmp,&iTypppArr,&iTypppArr+1,0,nbOfCompo,1,false); + return self; + } + //value vector + case 3: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(vsc,' '); + self->setPartOfValues3(tmp,&iTypppArr,&iTypppArr+1,0,nbOfCompo,1,false); + return self; + } + //value DataArrayChar + case 4: + { + self->setPartOfValues3(dacc,&iTypppArr,&iTypppArr+1,0,nbOfCompo,1,false); + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } } - - static MEDCouplingMesh *MergeMeshes(PyObject *li) throw(INTERP_KERNEL::Exception) - { - std::vector tmp; - convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__MEDCouplingMesh,"MEDCouplingMesh",tmp); - return MEDCouplingMesh::MergeMeshes(tmp); + case 2: + {//obj list-tuple[int] + switch(sw2) + { + {//value char + case 1: + { + self->setPartOfValuesSimple3(vc,&stdvecTyyppArr[0],&stdvecTyyppArr[0]+stdvecTyyppArr.size(),0,nbOfCompo,1); + return self; + } + //value string + case 2: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(sc); + self->setPartOfValues3(tmp,&stdvecTyyppArr[0],&stdvecTyyppArr[0]+stdvecTyyppArr.size(),0,nbOfCompo,1,false); + return self; + } + //value vector + case 3: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(vsc,' '); + self->setPartOfValues3(tmp,&stdvecTyyppArr[0],&stdvecTyyppArr[0]+stdvecTyyppArr.size(),0,nbOfCompo,1,false); + return self; + } + //value DataArrayChar + case 4: + { + self->setPartOfValues3(dacc,&stdvecTyyppArr[0],&stdvecTyyppArr[0]+stdvecTyyppArr.size(),0,nbOfCompo,1,false); + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + } + case 3: + {//slice + switch(sw2) + { + {//value char + case 1: + { + self->setPartOfValuesSimple1(vc,sTyyppArr.first,sTyyppArr.second.first,sTyyppArr.second.second,0,nbOfCompo,1); + return self; + } + //value string + case 2: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(sc); + self->setPartOfValues1(tmp,sTyyppArr.first,sTyyppArr.second.first,sTyyppArr.second.second,0,nbOfCompo,1,false); + return self; + } + //value vector + case 3: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(vsc,' '); + self->setPartOfValues1(tmp,sTyyppArr.first,sTyyppArr.second.first,sTyyppArr.second.second,0,nbOfCompo,1,false); + return self; + } + //value DataArrayChar + case 4: + { + self->setPartOfValues1(dacc,sTyyppArr.first,sTyyppArr.second.first,sTyyppArr.second.second,0,nbOfCompo,1,false); + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + } + case 4: + {//DataArrayInt + switch(sw2) + { + {//value char + case 1: + { + self->setPartOfValuesSimple3(vc,daIntTyypp->begin(),daIntTyypp->end(),0,nbOfCompo,1); + return self; + } + //value string + case 2: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(sc); + self->setPartOfValues3(tmp,daIntTyypp->begin(),daIntTyypp->end(),0,nbOfCompo,1,false); + return self; + } + //value vector + case 3: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(vsc,' '); + self->setPartOfValues3(tmp,daIntTyypp->begin(),daIntTyypp->end(),0,nbOfCompo,1,false); + return self; + } + //value DataArrayChar + case 4: + { + self->setPartOfValues3(dacc,daIntTyypp->begin(),daIntTyypp->end(),0,nbOfCompo,1,false); + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } } + default: + throw INTERP_KERNEL::Exception(msg); } - }; -} - -%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;igetSpaceDimension(); const char msg[]="Python wrap of MEDCouplingPointSet::getNodeIdsNearPoints : "; - const double *pos=convertObjToPossibleCpp5_Safe(pt,sw,val,a,aa,bb,msg,nbOfNodes,spaceDim,true); - self->getNodeIdsNearPoints(pos,nbOfNodes,eps,c,cI); + const double *pos=convertObjToPossibleCpp5_Safe(pt,sw,val,a,aa,bb,msg,nbOfPoints,spaceDim,true); + self->getNodeIdsNearPoints(pos,nbOfPoints,eps,c,cI); PyObject *ret=PyTuple_New(2); PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(c),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cI),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); @@ -1287,12 +2336,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 +2493,7 @@ namespace ParaMEDMEM return self->simpleRepr(); } - MEDCouplingUMeshCellIterator *__iter__() + MEDCouplingUMeshCellIterator *__iter__() throw(INTERP_KERNEL::Exception) { return self->cellIterator(); } @@ -2238,14 +3287,12 @@ namespace ParaMEDMEM MEDCouplingUMesh *mOut=self->emulateMEDMEMBDC(nM1LevMesh,d0,d1,d2,d3,d4,dd5); PyObject *ret=PyTuple_New(7); PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(mOut),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr((DataArrayInt *)d0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr((DataArrayInt *)d1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d0.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); PyTuple_SetItem(ret,3,SWIG_NewPointerObj(SWIG_as_voidptr(d2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); PyTuple_SetItem(ret,4,SWIG_NewPointerObj(SWIG_as_voidptr(d3),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); PyTuple_SetItem(ret,5,SWIG_NewPointerObj(SWIG_as_voidptr(d4),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); PyTuple_SetItem(ret,6,SWIG_NewPointerObj(SWIG_as_voidptr(dd5),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - d0->incrRef(); - d1->incrRef(); return ret; } @@ -2255,10 +3302,8 @@ namespace ParaMEDMEM MEDCouplingAutoRefCountObjectPtr d1=DataArrayInt::New(); self->getReverseNodalConnectivity(d0,d1); PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - d0->incrRef(); - d1->incrRef(); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } @@ -2600,7 +3645,7 @@ namespace ParaMEDMEM %extend ParaMEDMEM::DataArrayDoubleTuple { - std::string __str__() const + std::string __str__() const throw(INTERP_KERNEL::Exception) { return self->repr(); } @@ -2892,8 +3937,7 @@ namespace ParaMEDMEM MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); std::vector tmp=fillArrayWithPyListDbl2(elt0,nbOfTuples1,nbOfCompo); ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - ret->incrRef(); - return ret; + return ret.retn(); } else throw INTERP_KERNEL::Exception(msg); @@ -2904,8 +3948,7 @@ namespace ParaMEDMEM int tmpp1=-1; std::vector tmp=fillArrayWithPyListDbl2(elt0,nbOfTuples1,tmpp1); ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - ret->incrRef(); - return ret; + return ret.retn(); } } else @@ -2917,8 +3960,7 @@ namespace ParaMEDMEM int tmpp1=-1,tmpp2=-1; std::vector tmp=fillArrayWithPyListDbl2(elt0,tmpp1,tmpp2); ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - ret->incrRef(); - return ret; + return ret.retn(); } } else if(PyInt_Check(elt0)) @@ -2937,8 +3979,7 @@ namespace ParaMEDMEM throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !"); MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); ret->alloc(nbOfTuples1,nbOfCompo); - ret->incrRef(); - return ret; + return ret.retn(); } else throw INTERP_KERNEL::Exception(msg); @@ -2950,8 +3991,7 @@ namespace ParaMEDMEM {//DataArrayDouble.New(5) MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); ret->alloc(nbOfTuples1,1); - ret->incrRef(); - return ret; + return ret.retn(); } } else @@ -2973,7 +4013,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 +4086,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 +4104,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); @@ -3886,8 +4926,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(1.,val); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -3923,8 +4962,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(1.,val); - ret->incrRef(); - return ret; + return ret.retn(); } case 3: { @@ -3998,8 +5036,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(1.,-val); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -4035,8 +5072,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(-1.,val); - ret->incrRef(); - return ret; + return ret.retn(); } case 3: { @@ -4110,8 +5146,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(val,0.); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -4147,8 +5182,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(val,0.); - ret->incrRef(); - return ret; + return ret.retn(); } case 3: { @@ -4224,8 +5258,7 @@ namespace ParaMEDMEM throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !"); MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(1/val,0.); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -4261,8 +5294,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyInv(val); - ret->incrRef(); - return ret; + return ret.retn(); } case 3: { @@ -4337,7 +5369,7 @@ namespace ParaMEDMEM %extend ParaMEDMEM::DataArrayIntTuple { - std::string __str__() const + std::string __str__() const throw(INTERP_KERNEL::Exception) { return self->repr(); } @@ -4347,7 +5379,7 @@ namespace ParaMEDMEM return self->intValue(); } - DataArrayInt *buildDAInt() + DataArrayInt *buildDAInt() throw(INTERP_KERNEL::Exception) { return self->buildDAInt(1,self->getNumberOfCompo()); } @@ -4653,8 +5685,7 @@ namespace ParaMEDMEM MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,nbOfCompo); ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - ret->incrRef(); - return ret; + return ret.retn(); } else throw INTERP_KERNEL::Exception(msg); @@ -4665,8 +5696,7 @@ namespace ParaMEDMEM 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; + return ret.retn(); } } else @@ -4678,8 +5708,7 @@ namespace ParaMEDMEM 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; + return ret.retn(); } } else if(PyInt_Check(elt0)) @@ -4698,8 +5727,7 @@ namespace ParaMEDMEM throw INTERP_KERNEL::Exception("DataArrayInt::New : should be a positive number of components !"); MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(nbOfTuples1,nbOfCompo); - ret->incrRef(); - return ret; + return ret.retn(); } else throw INTERP_KERNEL::Exception(msg); @@ -4711,8 +5739,7 @@ namespace ParaMEDMEM {//DataArrayInt.New(5) MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(nbOfTuples1,1); - ret->incrRef(); - return ret; + return ret.retn(); } } else @@ -4724,7 +5751,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 +5846,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 +5864,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); @@ -5825,8 +6852,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(1,val); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -5862,8 +6888,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(1,val); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -5937,8 +6962,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(1,-val); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -5974,8 +6998,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(-1,val); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -6049,8 +7072,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(val,0); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -6086,8 +7108,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(val,0); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -6161,8 +7182,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyDivideBy(val); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -6198,8 +7218,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyInv(val); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -6273,8 +7292,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyModulus(val); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -6310,8 +7328,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyRModulus(val); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -7240,7 +8257,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/MEDCouplingExamplesTest.py b/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py index 1a5bd6264..a270397b3 100644 --- a/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingExamplesTest.py @@ -20,10 +20,178 @@ from MEDCoupling import * import unittest +from math import pi class MEDCouplingBasicsTest(unittest.TestCase): - def testExample_DataArrayInt_(self): -#! [PySnippet_DataArrayInt__1] + def testExample_MEDCouplingPointSet_(self): + #! [PySnippet_MEDCouplingPointSet__1] + pass + # mesh.allocateCells(1); + # mesh.insertNextCell(NORM_QUAD4,4,range(4)); + # mesh.finishInsertingCells(); + + def testExample_MEDCouplingPointSet_scale(self): + #! [PySnippet_MEDCouplingPointSet_scale_1] + coords=[0.0,0.0, 1.0,0.0, 1.0,1.0, 0.0,1.0] # 2D coordinates of 4 nodes + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,4,2); + mesh=MEDCouplingUMesh.New(); + mesh.setCoords(coordsArr); + initCoords = coordsArr.deepCpy() + #! [PySnippet_MEDCouplingPointSet_scale_1] + #! [PySnippet_MEDCouplingPointSet_scale_2] + center = [0.,0.] + factor = 2. + mesh.scale(center,factor) + #! [PySnippet_MEDCouplingPointSet_scale_2] + #! [PySnippet_MEDCouplingPointSet_scale_3] + coords2 = mesh.getCoords() + assert coords2.isEqualWithoutConsideringStr( initCoords, 1.0 ) + assert not coords2.isEqualWithoutConsideringStr( initCoords, 0.9 ) + #! [PySnippet_MEDCouplingPointSet_scale_3] + pass + + def testExample_MEDCouplingPointSet_translate(self): + #! [PySnippet_MEDCouplingPointSet_translate_1] + coords=[0.0,0.0, 1.0,0.0, 1.0,1.0, 0.0,1.0] # 2D coordinates of 4 nodes + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,4,2); + mesh=MEDCouplingUMesh.New(); + mesh.setCoords(coordsArr); + initCoords = coordsArr.deepCpy() + #! [PySnippet_MEDCouplingPointSet_translate_1] + #! [PySnippet_MEDCouplingPointSet_translate_2] + vector = [1.,1.] + mesh.translate(vector) + #! [PySnippet_MEDCouplingPointSet_translate_2] + #! [PySnippet_MEDCouplingPointSet_translate_3] + coords2 = mesh.getCoords() + assert coords2.isEqualWithoutConsideringStr( initCoords, 1 ) + assert not coords2.isEqualWithoutConsideringStr( initCoords, 0.9 ) + #! [PySnippet_MEDCouplingPointSet_translate_3] + pass + + def testExample_MEDCouplingPointSet_rotate(self): + #! [PySnippet_MEDCouplingPointSet_rotate_1] + coords=[0.0,0.0, 0.1,0.0, 0.1,0.1, 0.0,0.1] # 2D coordinates of 4 nodes + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,4,2); + mesh=MEDCouplingUMesh.New(); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingPointSet_rotate_1] + #! [PySnippet_MEDCouplingPointSet_rotate_2] + center = [0.,0.] + mesh.rotate(center,-pi/2) + #! [PySnippet_MEDCouplingPointSet_rotate_2] + #! [PySnippet_MEDCouplingPointSet_rotate_3] + mesh.changeSpaceDimension(3) + center = [0.,0.,0.] + vector = [0.,0.,1.] + mesh.rotate(center,vector,pi/2) + #! [PySnippet_MEDCouplingPointSet_rotate_3] + #! [PySnippet_MEDCouplingPointSet_rotate_4] + mesh.changeSpaceDimension(2) + coords2 = mesh.getCoords().getValues() + for i,c in enumerate( coords ): + self.assertAlmostEqual( c, coords2[i], 13 ) + #! [PySnippet_MEDCouplingPointSet_rotate_4] + pass + + def testExample_MEDCouplingPointSet_getBoundingBox(self): + #! [PySnippet_MEDCouplingPointSet_getBoundingBox_1] + cc=[0.0, 0.1, 0.2, # 3D coordinates of 2 nodes + 2.0, 2.1, 2.2] + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(cc,2,3); + mesh=MEDCouplingUMesh.New(); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingPointSet_getBoundingBox_1] + #! [PySnippet_MEDCouplingPointSet_getBoundingBox_2] + bbox=mesh.getBoundingBox() + assert bbox == [( cc[0], cc[3] ), # NOTE: list of 3 tuples is retirned! + ( cc[1], cc[4] ), + ( cc[2], cc[5] )] + #! [PySnippet_MEDCouplingPointSet_getBoundingBox_2] + + def testExample_MEDCouplingPointSet_getNodeIdsNearPoint(self): + #! [PySnippet_MEDCouplingPointSet_getNodeIdsNearPoint_1] + # 2D coordinates of 5 nodes + coords=[0.3,-0.301, # 0 + 0.2,-0.3, # 1 + 0.3,-0.302, # 2 + 1.1,0.0, # 3 + 0.3,-0.303];# 4 + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,5,2); + mesh=MEDCouplingUMesh.New(); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingPointSet_getNodeIdsNearPoint_1] + #! [PySnippet_MEDCouplingPointSet_getNodeIdsNearPoint_2] + point=[0.3, -0.3] # point close to nodes #0, #2 and #4 + ids=mesh.getNodeIdsNearPoint(point,0.003); + assert ids.getValues() == [0,2,4] + #! [PySnippet_MEDCouplingPointSet_getNodeIdsNearPoint_2] + pass + + def testExample_MEDCouplingPointSet_getNodeIdsNearPoints(self): + #! [PySnippet_MEDCouplingPointSet_getNodeIdsNearPoints_1] + # 2D coordinates of 7 nodes + coords=[0.3,-0.301, # 0 + 0.2,-0.3, # 1 + 0.3,-0.302, # 2 + 1.1,0.0, # 3 + 1.1,0.0, # 4 + 1.1,0.002, # 5 + 0.3,-0.303];# 6 + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,7,2); + mesh=MEDCouplingUMesh.New(); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingPointSet_getNodeIdsNearPoints_1] + #! [PySnippet_MEDCouplingPointSet_getNodeIdsNearPoints_2] + points=[0.2,-0.301, # ~ node #1 + 0.0, 0.0, + 1.1, 0.002] # ~ nodes #3, #4 and #5 + ids,idsIndex=mesh.getNodeIdsNearPoints(points,3,0.003); + assert ids.getValues() == [1, 3, 4, 5] + print idsIndex.getValues() + #! [PySnippet_MEDCouplingPointSet_getNodeIdsNearPoints_2] + pass + + def testExample_MEDCouplingPointSet_findCommonNodes(self): + #! [PySnippet_MEDCouplingPointSet_findCommonNodes_1] + coords=[0.3,-0.301, # 0 + 0.2,-0.3, # 1 + 0.3,-0.302, # 2 + 1.1,0.0, # 3 + 1.1,0.0, # 4 + 0.3,-0.303];# 5 + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,6,2); + mesh=MEDCouplingUMesh.New(); + mesh.setCoords(coordsArr); + #! [PySnippet_MEDCouplingPointSet_findCommonNodes_1] + #! [PySnippet_MEDCouplingPointSet_findCommonNodes_2] + comm,commI=mesh.findCommonNodes(1e-13) + assert comm.getValues() == [3,4] + comm,commI=mesh.findCommonNodes(0.004) + assert comm.getValues() == [0,2,5,3,4] + #! [PySnippet_MEDCouplingPointSet_findCommonNodes_2] + pass + + def testExample_MEDCouplingPointSet_getCoordinatesOfNode(self): + #! [PySnippet_MEDCouplingPointSet_getCoordinatesOfNode_1] + coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3]; + coordsArr=DataArrayDouble.New(); + coordsArr.setValues(coords,3,2); + mesh=MEDCouplingUMesh.New(); + mesh.setCoords(coordsArr); +#! [PySnippet_MEDCouplingPointSet_getCoordinatesOfNode_1] +#! [PySnippet_MEDCouplingPointSet_getCoordinatesOfNode_2] + nodeCoords=mesh.getCoordinatesOfNode(1) + self.assertAlmostEqual(0.2, nodeCoords[0],13); + self.assertAlmostEqual(-0.3,nodeCoords[1],13); +#! [PySnippet_MEDCouplingPointSet_getCoordinatesOfNode_2] pass def testExample_DataArrayInt_getTuple(self): diff --git a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i index 7a1a8eb01..6d2801d01 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; @@ -476,6 +490,40 @@ static std::vector fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, return ret; } +static bool fillStringVector(PyObject *pyLi, std::vector& vec) throw(INTERP_KERNEL::Exception) +{ + if(PyList_Check(pyLi)) + { + Py_ssize_t sz=PyList_Size(pyLi); + vec.resize(sz); + for(int i=0;i tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0'; + for(int i=0;i cpp int sw=1 * if python list[int] -> cpp vector sw=2 * if python tuple[int] -> cpp vector sw=2 - * if python slicp -> cpp pair sw=3 - * if python DataArrayInt -> cpp DataArrayInt sw=4 + * if python slicp -> cpp pair sw=3 (begin,end,step) + * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown. * * switch between (int,vector,DataArrayInt) */ @@ -1013,7 +1073,7 @@ static void convertObjToPossibleCpp2(PyObject *value, int nbelem, int& sw, int& sw=4; return ; } - status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);; + status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0); if(SWIG_IsOK(status)) { ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp); @@ -1030,6 +1090,13 @@ static void convertObjToPossibleCpp2(PyObject *value, int nbelem, int& sw, int& throw INTERP_KERNEL::Exception(msg); } +/*! + * if python int -> cpp int sw=1 + * if python tuple[int] -> cpp vector sw=2 + * if python list[int] -> cpp vector sw=2 + * if python slice -> cpp pair sw=3 + * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer ! + */ static void convertObjToPossibleCpp22(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector& stdvecTyypp, std::pair >& p, ParaMEDMEM::DataArrayIntTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception) { sw=-1; @@ -1099,6 +1166,86 @@ static void convertObjToPossibleCpp22(PyObject *value, int nbelem, int& sw, int& sw=4; } +/*! + * if python string with size one -> cpp char sw=1 + * if python string with size different from one -> cpp string sw=2 + * if python tuple[string] or list[string] -> vector sw=3 + * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4 + * switch between (int,string,vector,DataArrayChar) + */ +static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception) +{ + const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance."; + sw=-1; + if(PyString_Check(value)) + { + const char *pt=PyString_AsString(value); + Py_ssize_t sz=PyString_Size(value); + if(sz==1) + { + cTyp=pt[0]; + sw=1; + return; + } + else + { + sType=pt; + sw=2; + return; + } + } + if(PyTuple_Check(value)) + { + int size=PyTuple_Size(value); + vsType.resize(size); + for(int i=0;i(argp); + if(!dacType) + { + std::ostringstream oss; oss << msg << " Instance in null !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + sw=4; + return ; + } + throw INTERP_KERNEL::Exception(msg); +} + /*! * if value int -> cpp it sw=1 * if value list[int] -> vt sw=2