stream << "\n";
}
+std::string DataArray::cppRepr(const char *varName) const throw(INTERP_KERNEL::Exception)
+{
+ std::ostringstream ret;
+ reprCppStream(varName,ret);
+ return ret.str();
+}
+
void DataArray::setInfoOnComponents(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
{
if(getNumberOfComponents()!=(int)info.size())
_mem.reprZip(getNumberOfComponents(),stream);
}
+void DataArrayDouble::reprCppStream(const char *varName, std::ostream& stream) const
+{
+ int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents();
+ const double *data=getConstPointer();
+ stream.precision(17);
+ stream << "DataArrayDouble *" << varName << "=DataArrayDouble::New();" << std::endl;
+ if(nbTuples*nbComp>=1)
+ {
+ stream << "const double " << varName << "Data[" << nbTuples*nbComp << "]={";
+ std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator<double>(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 DataArrayDouble::isEqualIfNotWhy(const DataArrayDouble& other, double prec, std::string& reason) const
{
if(!areInfoEqualsIfNotWhy(other,reason))
_mem.reprZip(getNumberOfComponents(),stream);
}
+void DataArrayInt::reprCppStream(const char *varName, std::ostream& stream) const
+{
+ int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents();
+ const int *data=getConstPointer();
+ stream << "DataArrayInt *" << varName << "=DataArrayInt::New();" << std::endl;
+ if(nbTuples*nbComp>=1)
+ {
+ stream << "const int " << varName << "Data[" << nbTuples*nbComp << "]={";
+ std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator<int>(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;
+}
+
/*!
* This method expects a number of components equal to 1.
* This method sweeps all the values (tuples) in 'this' (it should be allocated) and for each value v is replaced by
}
/*!
- * Idem DataArrayDouble::renumber method except that the number of tuples is reduced.
+ * Idem DataArrayInt::renumber method except that the number of tuples is reduced.
* That is to say that it is expected that newNbOfTuple<this->getNumberOfTuples().
* ['old2New','old2New'+getNumberOfTuples()) defines a range containing old to new array. For every negative value in ['old2NewBg','old2New'getNumberOfTuples()) the corresponding tuple is
* omitted.
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 std::string cppRepr(const char *varName) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT std::string getName() const { return _name; }
MEDCOUPLING_EXPORT const std::vector<std::string> &getInfoOnComponents() const { return _info_on_compo; }
MEDCOUPLING_EXPORT std::vector<std::string> &getInfoOnComponents() { return _info_on_compo; }
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;
protected:
DataArray():_nb_of_tuples(-1) { }
protected:
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 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 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,
return ret.str();
}
+/*!
+ * This method returns a C++ code that is a dump of \a this.
+ * This method will throw if this is not fully defined.
+ */
+std::string MEDCouplingUMesh::cppRepr() const throw(INTERP_KERNEL::Exception)
+{
+ static const char coordsName[]="coords";
+ static const char connName[]="conn";
+ static const char connIName[]="connI";
+ checkFullyDefined();
+ std::ostringstream ret; ret << "// coordinates" << std::endl;
+ _coords->reprCppStream(coordsName,ret); ret << std::endl << "// connectivity" << std::endl;
+ _nodal_connec->reprCppStream(connName,ret); ret << std::endl;
+ _nodal_connec_index->reprCppStream(connIName,ret); ret << std::endl;
+ ret << "MEDCouplingUMesh *mesh=MEDCouplingUMesh::New(\"" << getName() << "\"," << getMeshDimension() << ");" << std::endl;
+ ret << "mesh->setCoords(" << coordsName << ");" << std::endl;
+ ret << "mesh->setConnectivity(" << connName << "," << connIName << ",true);" << std::endl;
+ ret << coordsName << "->decrRef(); " << connName << "->decrRef(); " << connIName << "->decrRef();" << std::endl;
+ return ret.str();
+}
+
std::string MEDCouplingUMesh::reprConnectivityOfThis() const
{
std::ostringstream ret;
MEDCOUPLING_EXPORT DataArrayInt *getCellIdsFullyIncludedInNodeIds(const int *partBg, const int *partEnd) const;
MEDCOUPLING_EXPORT std::string simpleRepr() const;
MEDCOUPLING_EXPORT std::string advancedRepr() const;
+ MEDCOUPLING_EXPORT std::string cppRepr() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT std::string reprConnectivityOfThis() const;
MEDCOUPLING_EXPORT MEDCouplingUMesh *buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT int getNumberOfNodesInCell(int cellId) const;
MEDCouplingFieldDouble *getWarpField() const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *getSkewField() const throw(INTERP_KERNEL::Exception);
DataArrayInt *convexEnvelop2D() throw(INTERP_KERNEL::Exception);
+ std::string cppRepr() const throw(INTERP_KERNEL::Exception);
static MEDCouplingUMesh *Build0DMeshFromCoords(DataArrayDouble *da) throw(INTERP_KERNEL::Exception);
static MEDCouplingUMesh *MergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception);
static MEDCouplingUMesh *MergeUMeshesOnSameCoords(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception);