From 878ba3d9f6c4859c96493ff2f1bc2f6b9bd66c9d Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 30 May 2017 23:47:11 +0200 Subject: [PATCH] on the road --- src/MEDCoupling/MEDCouplingMemArray.cxx | 100 ------------------- src/MEDCoupling/MEDCouplingMemArray.hxx | 27 ++--- src/MEDCoupling/MEDCouplingMemArray.txx | 67 +++++++++++++ src/MEDCoupling/MEDCouplingMemArrayFloat.cxx | 39 -------- src/MEDCoupling/MEDCouplingTraits.cxx | 10 ++ src/MEDCoupling/MEDCouplingTraits.hxx | 5 + 6 files changed, 89 insertions(+), 159 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 566c07976..9f1ef0fea 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -896,18 +896,6 @@ std::string DataArrayDouble::reprZip() const return ret.str(); } -/*! - * This method is close to repr method except that when \a this has more than 1000 tuples, all tuples are not - * printed out to avoid to consume too much space in interpretor. - * \sa repr - */ -std::string DataArrayDouble::reprNotTooLong() const -{ - std::ostringstream ret; - reprNotTooLongStream(ret); - return ret.str(); -} - void DataArrayDouble::writeVTK(std::ostream& ofs, int indent, const std::string& nameInFile, DataArrayByte *byteArr) const { static const char SPACE[4]={' ',' ',' ',' '}; @@ -945,45 +933,6 @@ void DataArrayDouble::writeVTK(std::ostream& ofs, int indent, const std::string& ofs << std::endl << idt << "\n"; } -void DataArrayDouble::reprStream(std::ostream& stream) const -{ - stream << "Name of double array : \"" << _name << "\"\n"; - reprWithoutNameStream(stream); -} - -void DataArrayDouble::reprZipStream(std::ostream& stream) const -{ - stream << "Name of double array : \"" << _name << "\"\n"; - reprZipWithoutNameStream(stream); -} - -void DataArrayDouble::reprNotTooLongStream(std::ostream& stream) const -{ - stream << "Name of double array : \"" << _name << "\"\n"; - reprNotTooLongWithoutNameStream(stream); -} - -void DataArrayDouble::reprWithoutNameStream(std::ostream& stream) const -{ - DataArray::reprWithoutNameStream(stream); - stream.precision(17); - _mem.repr(getNumberOfComponents(),stream); -} - -void DataArrayDouble::reprZipWithoutNameStream(std::ostream& stream) const -{ - DataArray::reprWithoutNameStream(stream); - stream.precision(17); - _mem.reprZip(getNumberOfComponents(),stream); -} - -void DataArrayDouble::reprNotTooLongWithoutNameStream(std::ostream& stream) const -{ - DataArray::reprWithoutNameStream(stream); - stream.precision(17); - _mem.reprNotTooLong(getNumberOfComponents(),stream); -} - void DataArrayDouble::reprCppStream(const std::string& varName, std::ostream& stream) const { int nbTuples(getNumberOfTuples()),nbComp(getNumberOfComponents()); @@ -3736,18 +3685,6 @@ std::string DataArrayInt::reprZip() const return ret.str(); } -/*! - * This method is close to repr method except that when \a this has more than 1000 tuples, all tuples are not - * printed out to avoid to consume too much space in interpretor. - * \sa repr - */ -std::string DataArrayInt::reprNotTooLong() const -{ - std::ostringstream ret; - reprNotTooLongStream(ret); - return ret.str(); -} - void DataArrayInt::writeVTK(std::ostream& ofs, int indent, const std::string& type, const std::string& nameInFile, DataArrayByte *byteArr) const { static const char SPACE[4]={' ',' ',' ',' '}; @@ -3789,43 +3726,6 @@ void DataArrayInt::writeVTK(std::ostream& ofs, int indent, const std::string& ty ofs << std::endl << idt << "\n"; } -void DataArrayInt::reprStream(std::ostream& stream) const -{ - stream << "Name of int array : \"" << _name << "\"\n"; - reprWithoutNameStream(stream); -} - -void DataArrayInt::reprZipStream(std::ostream& stream) const -{ - stream << "Name of int array : \"" << _name << "\"\n"; - reprZipWithoutNameStream(stream); -} - -void DataArrayInt::reprNotTooLongStream(std::ostream& stream) const -{ - stream << "Name of int array : \"" << _name << "\"\n"; - reprNotTooLongWithoutNameStream(stream); -} - -void DataArrayInt::reprWithoutNameStream(std::ostream& stream) const -{ - DataArray::reprWithoutNameStream(stream); - _mem.repr(getNumberOfComponents(),stream); -} - -void DataArrayInt::reprZipWithoutNameStream(std::ostream& stream) const -{ - DataArray::reprWithoutNameStream(stream); - _mem.reprZip(getNumberOfComponents(),stream); -} - -void DataArrayInt::reprNotTooLongWithoutNameStream(std::ostream& stream) const -{ - DataArray::reprWithoutNameStream(stream); - stream.precision(17); - _mem.reprNotTooLong(getNumberOfComponents(),stream); -} - void DataArrayInt::reprCppStream(const std::string& varName, std::ostream& stream) const { int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents(); diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index d2bcc3dea..b4ed5643c 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -342,6 +342,13 @@ namespace MEDCoupling MEDCOUPLING_EXPORT typename Traits::ArrayType *performCopyOrIncrRef(bool dCpy) const; MEDCOUPLING_EXPORT typename Traits::ArrayType *sumPerTuple() const; MEDCOUPLING_EXPORT void iota(T init=(T)0); + MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const; + MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const; + MEDCOUPLING_EXPORT void reprNotTooLongStream(std::ostream& stream) const; + MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const; + MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const; + MEDCOUPLING_EXPORT void reprNotTooLongWithoutNameStream(std::ostream& stream) const; + MEDCOUPLING_EXPORT std::string reprNotTooLong() const; protected: static typename Traits::ArrayType *PerformCopyOrIncrRef(bool dCpy, const typename Traits::ArrayType& self); template @@ -376,16 +383,10 @@ namespace MEDCoupling MEDCOUPLING_EXPORT DataArrayFloat *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplateFP::mySelectByTupleId(new2OldBg,new2OldEnd); } MEDCOUPLING_EXPORT DataArrayFloat *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplateFP::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); } MEDCOUPLING_EXPORT DataArrayFloat *selectByTupleIdSafeSlice(int bg, int end2, int step) const { return DataArrayTemplateFP::mySelectByTupleIdSafeSlice(bg,end2,step); } - MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const; MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const; MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const; public:// non abstract but essential - MEDCOUPLING_EXPORT std::string reprNotTooLong() const; - MEDCOUPLING_EXPORT void reprNotTooLongStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprNotTooLongWithoutNameStream(std::ostream& stream) const; MEDCOUPLING_EXPORT bool isEqual(const DataArrayFloat& other, float prec) const; MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayFloat& other, float prec, std::string& reason) const; MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayFloat& other, float prec) const; @@ -411,14 +412,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT bool isMonotonic(bool increasing, double eps) const; MEDCOUPLING_EXPORT std::string repr() const; MEDCOUPLING_EXPORT std::string reprZip() const; - MEDCOUPLING_EXPORT std::string reprNotTooLong() const; MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const std::string& nameInFile, DataArrayByte *byteArr) const; - MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprNotTooLongStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprNotTooLongWithoutNameStream(std::ostream& stream) const; MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const; MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const; @@ -566,14 +560,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT DataArrayInt32 *buildNewEmptyInstance() const { return DataArrayInt32::New(); }//ok MEDCOUPLING_EXPORT std::string repr() const; MEDCOUPLING_EXPORT std::string reprZip() const; - MEDCOUPLING_EXPORT std::string reprNotTooLong() const; MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const std::string& type, const std::string& nameInFile, DataArrayByte *byteArr) const; - MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprNotTooLongStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const; - MEDCOUPLING_EXPORT void reprNotTooLongWithoutNameStream(std::ostream& stream) const; MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const; MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const; diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index 7813e5417..5a1f3ee69 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -3261,6 +3261,73 @@ struct NotInRange ptr[i]=init+(T)i; this->declareAsNew(); } + + template + struct ImplReprTraits { static void SetPrecision(std::ostream& oss) { } }; + + template<> + struct ImplReprTraits { static void SetPrecision(std::ostream& oss) { oss.precision(17); } }; + + template<> + struct ImplReprTraits { static void SetPrecision(std::ostream& oss) { oss.precision(7); } }; + + template + void DataArrayTemplateClassic::reprStream(std::ostream& stream) const + { + stream << "Name of " << Traits::ReprStr << " array : \"" << this->_name << "\"\n"; + reprWithoutNameStream(stream); + } + + template + void DataArrayTemplateClassic::reprZipStream(std::ostream& stream) const + { + stream << "Name of " << Traits::ReprStr << " array : \"" << this->_name << "\"\n"; + reprZipWithoutNameStream(stream); + } + + template + void DataArrayTemplateClassic::reprNotTooLongStream(std::ostream& stream) const + { + stream << "Name of "<< Traits::ReprStr << " array : \"" << this->_name << "\"\n"; + reprNotTooLongWithoutNameStream(stream); + } + + template + void DataArrayTemplateClassic::reprWithoutNameStream(std::ostream& stream) const + { + DataArray::reprWithoutNameStream(stream); + ImplReprTraits::SetPrecision(stream); + this->_mem.repr(this->getNumberOfComponents(),stream); + } + + template + void DataArrayTemplateClassic::reprZipWithoutNameStream(std::ostream& stream) const + { + DataArray::reprWithoutNameStream(stream); + ImplReprTraits::SetPrecision(stream); + this->_mem.reprZip(this->getNumberOfComponents(),stream); + } + + template + void DataArrayTemplateClassic::reprNotTooLongWithoutNameStream(std::ostream& stream) const + { + DataArray::reprWithoutNameStream(stream); + ImplReprTraits::SetPrecision(stream); + this->_mem.reprNotTooLong(this->getNumberOfComponents(),stream); + } + + /*! + * This method is close to repr method except that when \a this has more than 1000 tuples, all tuples are not + * printed out to avoid to consume too much space in interpretor. + * \sa repr + */ + template + std::string DataArrayTemplateClassic::reprNotTooLong() const + { + std::ostringstream ret; + reprNotTooLongStream(ret); + return ret.str(); + } ///////////////////////////////// diff --git a/src/MEDCoupling/MEDCouplingMemArrayFloat.cxx b/src/MEDCoupling/MEDCouplingMemArrayFloat.cxx index 08dd53d8a..c9fa547eb 100644 --- a/src/MEDCoupling/MEDCouplingMemArrayFloat.cxx +++ b/src/MEDCoupling/MEDCouplingMemArrayFloat.cxx @@ -38,25 +38,6 @@ DataArrayFloat *DataArrayFloat::deepCopy() const return new DataArrayFloat(*this); } -void DataArrayFloat::reprStream(std::ostream& stream) const -{ - stream << "Name of float array : \"" << _name << "\"\n"; - reprWithoutNameStream(stream); -} - -void DataArrayFloat::reprZipStream(std::ostream& stream) const -{ - stream << "Name of float array : \"" << _name << "\"\n"; - reprZipWithoutNameStream(stream); -} - -void DataArrayFloat::reprZipWithoutNameStream(std::ostream& stream) const -{ - DataArray::reprWithoutNameStream(stream); - stream.precision(7); - _mem.repr(getNumberOfComponents(),stream); -} - void DataArrayFloat::reprCppStream(const std::string& varName, std::ostream& stream) const { int nbTuples(getNumberOfTuples()),nbComp(getNumberOfComponents()); @@ -131,26 +112,6 @@ void DataArrayFloat::reprQuickOverviewData(std::ostream& stream, std::size_t max stream << "]"; } -std::string DataArrayFloat::reprNotTooLong() const -{ - std::ostringstream ret; - reprNotTooLongStream(ret); - return ret.str(); -} - -void DataArrayFloat::reprNotTooLongStream(std::ostream& stream) const -{ - stream << "Name of float array : \"" << _name << "\"\n"; - reprNotTooLongWithoutNameStream(stream); -} - -void DataArrayFloat::reprNotTooLongWithoutNameStream(std::ostream& stream) const -{ - DataArray::reprWithoutNameStream(stream); - stream.precision(7); - _mem.reprNotTooLong(getNumberOfComponents(),stream); -} - bool DataArrayFloat::isEqualIfNotWhy(const DataArrayFloat& other, float prec, std::string& reason) const { if(!areInfoEqualsIfNotWhy(other,reason)) diff --git a/src/MEDCoupling/MEDCouplingTraits.cxx b/src/MEDCoupling/MEDCouplingTraits.cxx index eaeeffa0a..46e3f7b1f 100644 --- a/src/MEDCoupling/MEDCouplingTraits.cxx +++ b/src/MEDCoupling/MEDCouplingTraits.cxx @@ -28,16 +28,24 @@ const char Traits::FieldTypeName[]="MEDCouplingFieldDouble"; const char Traits::NPYStr[]="FLOAT64"; +const char Traits::ReprStr[]="double"; + const char Traits::ArrayTypeName[]="DataArrayFloat"; const char Traits::FieldTypeName[]="MEDCouplingFieldFloat"; const char Traits::NPYStr[]="FLOAT32"; +const char Traits::ReprStr[]="float"; + const char Traits::ArrayTypeName[]="DataArrayInt"; const char Traits::FieldTypeName[]="MEDCouplingFieldInt"; +const char Traits::NPYStr[]="INT32"; + +const char Traits::ReprStr[]="int"; + const char Traits::ArrayTypeName[]="DataArrayChar"; const char Traits::ArrayTypeName[]="DataArrayInt64"; @@ -45,3 +53,5 @@ const char Traits::ArrayTypeName[]="DataArrayInt64"; const char Traits::FieldTypeName[]="MEDCouplingFieldInt64"; const char Traits::NPYStr[]="INT64"; + +const char Traits::ReprStr[]="int64"; diff --git a/src/MEDCoupling/MEDCouplingTraits.hxx b/src/MEDCoupling/MEDCouplingTraits.hxx index ff5debe4c..a14232eec 100644 --- a/src/MEDCoupling/MEDCouplingTraits.hxx +++ b/src/MEDCoupling/MEDCouplingTraits.hxx @@ -51,6 +51,7 @@ namespace MEDCoupling static const char ArrayTypeName[]; static const char FieldTypeName[]; static const char NPYStr[]; + static const char ReprStr[]; typedef DataArrayDouble ArrayType; typedef DataArrayDouble ArrayTypeCh; typedef MEDCouplingFieldDouble FieldType; @@ -63,6 +64,7 @@ namespace MEDCoupling static const char ArrayTypeName[]; static const char FieldTypeName[]; static const char NPYStr[]; + static const char ReprStr[]; typedef DataArrayFloat ArrayType; typedef DataArrayFloat ArrayTypeCh; typedef MEDCouplingFieldFloat FieldType; @@ -74,6 +76,8 @@ namespace MEDCoupling { static const char ArrayTypeName[]; static const char FieldTypeName[]; + static const char NPYStr[]; + static const char ReprStr[]; typedef DataArrayInt32 ArrayType; typedef DataArrayInt32 ArrayTypeCh; typedef MEDCouplingFieldInt FieldType; @@ -86,6 +90,7 @@ namespace MEDCoupling static const char ArrayTypeName[]; static const char FieldTypeName[]; static const char NPYStr[]; + static const char ReprStr[]; typedef DataArrayInt64 ArrayType; typedef DataArrayInt64 ArrayTypeCh; //typedef MEDCouplingFieldInt64 FieldType; -- 2.39.2