template class MEDCoupling::DataArrayIterator<int>;
template class MEDCoupling::DataArrayDiscrete<Int32>;
template class MEDCoupling::DataArrayDiscreteSigned<Int32>;
+template class MEDCoupling::DataArrayDiscrete<Int64>;
+template class MEDCoupling::DataArrayDiscreteSigned<Int64>;
template class MEDCoupling::DataArrayTuple<int>;
template class MEDCoupling::DataArrayTuple<double>;
template class MEDCoupling::DataArrayTuple<float>;
}
}
-/*!
- * Returns a textual and human readable representation of \a this instance of
- * DataArrayDouble. This text is shown when a DataArrayDouble is printed in Python.
- * \return std::string - text describing \a this DataArrayDouble.
- *
- * \sa reprNotTooLong, reprZip
- */
-std::string DataArrayDouble::repr() const
-{
- std::ostringstream ret;
- reprStream(ret);
- return ret.str();
-}
-
-std::string DataArrayDouble::reprZip() const
-{
- std::ostringstream ret;
- reprZipStream(ret);
- return ret.str();
-}
-
void DataArrayDouble::writeVTK(std::ostream& ofs, int indent, const std::string& nameInFile, DataArrayByte *byteArr) const
{
static const char SPACE[4]={' ',' ',' ',' '};
stream << "DataArrayDouble C++ instance at " << this << ". ";
if(isAllocated())
{
- int nbOfCompo=(int)_info_on_compo.size();
+ std::size_t nbOfCompo(_info_on_compo.size());
if(nbOfCompo>=1)
{
- int nbOfTuples=getNumberOfTuples();
+ std::size_t nbOfTuples(getNumberOfTuples());
stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl;
reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR);
}
return this->buildDA(nbOfTuples,nbOfCompo);
}
-/*!
- * Returns a new instance of DataArrayInt. The caller is to delete this array
- * using decrRef() as it is no more needed.
- */
-DataArrayInt *DataArrayInt::New()
-{
- return new DataArrayInt;
-}
-
/*!
* 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.
throw INTERP_KERNEL::Exception("DataArrayInt::intValue : DataArrayInt instance is not allocated !");
}
-/*!
- * 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 DataArrayInt::getHashCode() const
-{
- checkAllocated();
- std::size_t nbOfElems=getNbOfElems();
- int ret=nbOfElems*65536;
- int delta=3;
- if(nbOfElems>48)
- delta=nbOfElems/8;
- int ret0=0;
- const int *pt=begin();
- for(std::size_t i=0;i<nbOfElems;i+=delta)
- ret0+=pt[i] & 0x1FFF;
- return ret+ret0;
-}
-
/*!
* Returns a full copy of \a this. For more info on copying data arrays see
* \ref MEDCouplingArrayBasicsCopyDeep.
return new DataArrayInt32(*this);
}
-/*!
- * Returns a textual and human readable representation of \a this instance of
- * DataArrayInt. This text is shown when a DataArrayInt is printed in Python.
- * \return std::string - text describing \a this DataArrayInt.
- *
- * \sa reprNotTooLong, reprZip
- */
-std::string DataArrayInt::repr() const
-{
- std::ostringstream ret;
- reprStream(ret);
- return ret.str();
-}
-
-std::string DataArrayInt::reprZip() const
-{
- std::ostringstream ret;
- reprZipStream(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]={' ',' ',' ',' '};
- checkAllocated();
- std::string idt(indent,' ');
- ofs << idt << "<DataArray type=\"" << type << "\" Name=\"" << nameInFile << "\" NumberOfComponents=\"" << getNumberOfComponents() << "\"";
- if(byteArr)
- {
- ofs << " format=\"appended\" offset=\"" << byteArr->getNumberOfTuples() << "\">";
- if(std::string(type)=="Int32")
- {
- const char *data(reinterpret_cast<const char *>(begin()));
- std::size_t sz(getNbOfElems()*sizeof(int));
- byteArr->insertAtTheEnd(data,data+sz);
- byteArr->insertAtTheEnd(SPACE,SPACE+4);
- }
- else if(std::string(type)=="Int8")
- {
- INTERP_KERNEL::AutoPtr<char> tmp(new char[getNbOfElems()]);
- std::copy(begin(),end(),(char *)tmp);
- byteArr->insertAtTheEnd((char *)tmp,(char *)tmp+getNbOfElems());
- byteArr->insertAtTheEnd(SPACE,SPACE+4);
- }
- else if(std::string(type)=="UInt8")
- {
- INTERP_KERNEL::AutoPtr<unsigned char> tmp(new unsigned char[getNbOfElems()]);
- std::copy(begin(),end(),(unsigned char *)tmp);
- byteArr->insertAtTheEnd((unsigned char *)tmp,(unsigned char *)tmp+getNbOfElems());
- byteArr->insertAtTheEnd(SPACE,SPACE+4);
- }
- else
- throw INTERP_KERNEL::Exception("DataArrayInt::writeVTK : Only Int32, Int8 and UInt8 supported !");
- }
- else
- {
- ofs << " RangeMin=\"" << getMinValueInArray() << "\" RangeMax=\"" << getMaxValueInArray() << "\" format=\"ascii\">\n" << idt;
- std::copy(begin(),end(),std::ostream_iterator<int>(ofs," "));
- }
- ofs << std::endl << idt << "</DataArray>\n";
-}
-
-void DataArrayInt::reprCppStream(const std::string& varName, std::ostream& stream) const
-{
- int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents();
- const int *data=getConstPointer();
- stream << "DataArrayInt *" << varName << "=DataArrayInt::New();" << std::endl;
- if(nbTuples*nbComp>=1)
- {
- stream << "const int " << varName << "Data[" << nbTuples*nbComp << "]={";
- std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator<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;
-}
-
-/*!
- * Method that gives a quick overvien of \a this for python.
- */
-void DataArrayInt::reprQuickOverview(std::ostream& stream) const
-{
- static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300;
- stream << "DataArrayInt C++ instance at " << this << ". ";
- if(isAllocated())
- {
- int nbOfCompo=(int)_info_on_compo.size();
- if(nbOfCompo>=1)
- {
- int nbOfTuples=getNumberOfTuples();
- stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl;
- reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR);
- }
- else
- stream << "Number of components : 0.";
- }
- else
- stream << "*** No data allocated ****";
-}
-
-void DataArrayInt::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const
-{
- const int *data=begin();
- int nbOfTuples=getNumberOfTuples();
- int nbOfCompo=(int)_info_on_compo.size();
- std::ostringstream oss2; oss2 << "[";
- std::string oss2Str(oss2.str());
- bool isFinished=true;
- for(int i=0;i<nbOfTuples && isFinished;i++)
- {
- if(nbOfCompo>1)
- {
- oss2 << "(";
- for(int j=0;j<nbOfCompo;j++,data++)
- {
- oss2 << *data;
- if(j!=nbOfCompo-1) oss2 << ", ";
- }
- oss2 << ")";
- }
- else
- oss2 << *data++;
- if(i!=nbOfTuples-1) oss2 << ", ";
- std::string oss3Str(oss2.str());
- if(oss3Str.length()<maxNbOfByteInRepr)
- oss2Str=oss3Str;
- else
- isFinished=false;
- }
- stream << oss2Str;
- if(!isFinished)
- stream << "... ";
- stream << "]";
-}
-
/*!
* Computes distribution of values of \a this one-dimensional array between given value
* ranges (casts). This method is typically useful for entity number splitting by types,
}
}
-
-/*!
- * Modifies in place \a this one-dimensional array so that each value \a v = \a indArrBg[ \a v ],
- * i.e. a current value is used as in index to get a new value from \a indArrBg.
- * \param [in] indArrBg - pointer to the first element of array of new values to assign
- * to \a this array.
- * \param [in] indArrEnd - specifies the end of the array \a indArrBg, so that
- * the last value of \a indArrBg is \a indArrEnd[ -1 ].
- * \throw If \a this->getNumberOfComponents() != 1
- * \throw If any value of \a this can't be used as a valid index for
- * [\a indArrBg, \a indArrEnd).
- *
- * \sa changeValue, findIdForEach
- */
-void DataArrayInt::transformWithIndArr(const int *indArrBg, const int *indArrEnd)
-{
- this->checkAllocated();
- if(this->getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !");
- int nbElemsIn((int)std::distance(indArrBg,indArrEnd)),nbOfTuples(getNumberOfTuples()),*pt(getPointer());
- for(int i=0;i<nbOfTuples;i++,pt++)
- {
- if(*pt>=0 && *pt<nbElemsIn)
- *pt=indArrBg[*pt];
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::transformWithIndArr : error on tuple #" << i << " of this value is " << *pt << ", should be in [0," << nbElemsIn << ") !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- }
- this->declareAsNew();
-}
-
-void DataArrayInt::transformWithIndArr(const MapKeyVal<int>& m)
-{
- this->checkAllocated();
- if(this->getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !");
- const std::map<int,int>& dat(m.data());
- int nbOfTuples(getNumberOfTuples()),*pt(getPointer());
- for(int i=0;i<nbOfTuples;i++,pt++)
- {
- std::map<int,int>::const_iterator it(dat.find(*pt));
- if(it!=dat.end())
- *pt=(*it).second;
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::transformWithIndArr : error on tuple #" << i << " of this value is " << *pt << " not in map !";
- throw INTERP_KERNEL::Exception(oss.str());
- }
- }
- this->declareAsNew();
-}
-
/*!
* Creates a one-dimensional DataArrayInt (\a res) whose contents are computed from
* values of \a this (\a a) and the given (\a indArr) arrays as follows:
{
return this->buildDA(nbOfTuples,nbOfCompo);
}
+
+DataArrayInt64 *DataArrayInt64::deepCopy() const
+{
+ return new DataArrayInt64(*this);
+}
MEDCOUPLING_EXPORT void setIJSilent(int tupleId, int compoId, T newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; }
MEDCOUPLING_EXPORT T *getPointer() { return _mem.getPointer(); declareAsNew(); }
MEDCOUPLING_EXPORT void pack() const;
- MEDCOUPLING_EXPORT bool isAllocated() const;
+ MEDCOUPLING_EXPORT bool isAllocated() const override;
MEDCOUPLING_EXPORT void checkAllocated() const;
MEDCOUPLING_EXPORT void desallocate();
MEDCOUPLING_EXPORT void reserve(std::size_t nbOfElems);
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 repr() const;
+ MEDCOUPLING_EXPORT std::string reprZip() const;
MEDCOUPLING_EXPORT std::string reprNotTooLong() const;
template<class U>
MCAuto< typename Traits<U>::ArrayType > convertToOtherTypeOfArr() const;
MEDCOUPLING_EXPORT DataArrayDouble *buildNewEmptyInstance() const { return DataArrayDouble::New(); }
MEDCOUPLING_EXPORT void checkMonotonic(bool increasing, double eps) const;
MEDCOUPLING_EXPORT bool isMonotonic(bool increasing, double eps) const;
- MEDCOUPLING_EXPORT std::string repr() const;
- MEDCOUPLING_EXPORT std::string reprZip() const;
MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const std::string& nameInFile, DataArrayByte *byteArr) const;
MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const;
MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const;
class DataArrayDiscrete : public DataArrayTemplateClassic<T>
{
public:
+ MEDCOUPLING_EXPORT static typename Traits<T>::ArrayType *New();
MEDCOUPLING_EXPORT bool isEqual(const DataArrayDiscrete<T>& other) const;
MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayDiscrete<T>& other, std::string& reason) const;
MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayDiscrete<T>& other) const;
MEDCOUPLING_EXPORT bool isMonotonic(bool increasing) const;
MEDCOUPLING_EXPORT void checkStrictlyMonotonic(bool increasing) const;
MEDCOUPLING_EXPORT bool isStrictlyMonotonic(bool increasing) const;
+ MEDCOUPLING_EXPORT int getHashCode() const;
+ MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const;
+ MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const;
+ MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const std::string& type, const std::string& nameInFile, DataArrayByte *byteArr) const;
+ MEDCOUPLING_EXPORT void transformWithIndArr(const T *indArrBg, const T *indArrEnd);
+ MEDCOUPLING_EXPORT void transformWithIndArr(const MapKeyVal<T>& m);
protected:
template<class ALG>
void switchOnTupleAlg(T val, std::vector<bool>& vec, ALG algo) const;
class DataArrayInt32 : public DataArrayDiscreteSigned<Int32>
{
+ friend class DataArrayDiscrete<Int32>;
public:
- MEDCOUPLING_EXPORT static DataArrayInt32 *New();
MEDCOUPLING_EXPORT int intValue() const;
- MEDCOUPLING_EXPORT int getHashCode() const;
MEDCOUPLING_EXPORT DataArrayInt32 *deepCopy() const;//ok
MEDCOUPLING_EXPORT DataArrayInt32 *buildNewEmptyInstance() const { return DataArrayInt32::New(); }//ok
- MEDCOUPLING_EXPORT std::string repr() const;
- MEDCOUPLING_EXPORT std::string reprZip() const;
- MEDCOUPLING_EXPORT void writeVTK(std::ostream& ofs, int indent, const std::string& type, const std::string& nameInFile, DataArrayByte *byteArr) const;
- MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const;
- MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const;
- MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const;
- MEDCOUPLING_EXPORT void transformWithIndArr(const int *indArrBg, const int *indArrEnd);
- MEDCOUPLING_EXPORT void transformWithIndArr(const MapKeyVal<int>& m);
- MEDCOUPLING_EXPORT DataArrayInt32 *transformWithIndArrR(const int *indArrBg, const int *indArrEnd) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *transformWithIndArrR(const int *indArr2Bg, const int *indArrEnd) const;
MEDCOUPLING_EXPORT void splitByValueRange(const int *arrBg, const int *arrEnd,
DataArrayInt32 *& castArr, DataArrayInt32 *& rankInsideCast, DataArrayInt32 *& castsPresent) const;
MEDCOUPLING_EXPORT bool isRange(int& strt, int& sttoopp, int& stteepp) const;
class DataArrayInt64 : public DataArrayDiscrete<Int64>
{
+ friend class DataArrayDiscrete<Int64>;
+ public:
+ MEDCOUPLING_EXPORT DataArrayInt64 *deepCopy() const;
+ MEDCOUPLING_EXPORT DataArrayInt64 *buildNewEmptyInstance() const { return DataArrayInt64::New(); }//ok
+ MEDCOUPLING_EXPORT DataArrayInt64 *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate<Int64>::mySelectByTupleId(new2OldBg,new2OldEnd); }
+ MEDCOUPLING_EXPORT DataArrayInt64 *selectByTupleId(const DataArrayInt32& di) const { return DataArrayTemplate<Int64>::mySelectByTupleId(di); }
+ MEDCOUPLING_EXPORT DataArrayInt64 *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate<Int64>::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
+ MEDCOUPLING_EXPORT DataArrayInt64 *keepSelectedComponents(const std::vector<int>& compoIds) const { return DataArrayTemplate<Int64>::myKeepSelectedComponents(compoIds); }
+ MEDCOUPLING_EXPORT DataArrayInt64 *selectByTupleIdSafeSlice(int bg, int end2, int step) const { return DataArrayTemplate<Int64>::mySelectByTupleIdSafeSlice(bg,end2,step); }
+ MEDCOUPLING_EXPORT DataArrayInt64 *selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const { return DataArrayTemplate<Int64>::mySelectByTupleRanges(ranges); }
+ private:
+ ~DataArrayInt64() { }
+ DataArrayInt64() { }
};
template<class T>
{
std::size_t sz(_mem.getNbOfElemAllocated());
sz*=sizeof(T);
- return DataArray::getHeapMemorySizeWithoutChildren()+sz;
+ return this->getHeapMemorySizeWithoutChildren()+sz;
}
/*!
template<class T>
typename Traits<T>::ArrayType *DataArrayTemplate<T>::mySelectByTupleId(const DataArrayInt& di) const
{
- return DataArrayTemplate<T>::mySelectByTupleId(di.begin(),di.end());
+ return this->mySelectByTupleId(di.begin(),di.end());
}
template<class T>
template<class T>
void DataArrayTemplateClassic<T>::reprWithoutNameStream(std::ostream& stream) const
{
- DataArray::reprWithoutNameStream(stream);
+ this->reprWithoutNameStream(stream);
ImplReprTraits<T>::SetPrecision(stream);
this->_mem.repr(this->getNumberOfComponents(),stream);
}
template<class T>
void DataArrayTemplateClassic<T>::reprZipWithoutNameStream(std::ostream& stream) const
{
- DataArray::reprWithoutNameStream(stream);
+ this->reprWithoutNameStream(stream);
ImplReprTraits<T>::SetPrecision(stream);
this->_mem.reprZip(this->getNumberOfComponents(),stream);
}
template<class T>
void DataArrayTemplateClassic<T>::reprNotTooLongWithoutNameStream(std::ostream& stream) const
{
- DataArray::reprWithoutNameStream(stream);
+ this->reprWithoutNameStream(stream);
ImplReprTraits<T>::SetPrecision(stream);
this->_mem.reprNotTooLong(this->getNumberOfComponents(),stream);
}
return ret.str();
}
+ /*!
+ * Returns a textual and human readable representation of \a this instance of
+ * DataArrayInt. This text is shown when a DataArrayInt is printed in Python.
+ * \return std::string - text describing \a this DataArrayInt.
+ *
+ * \sa reprNotTooLong, reprZip
+ */
+ template<class T>
+ std::string DataArrayTemplateClassic<T>::repr() const
+ {
+ std::ostringstream ret;
+ DataArrayTemplateClassic<T>::reprStream(ret);
+ return ret.str();
+ }
+
+ template<class T>
+ std::string DataArrayTemplateClassic<T>::reprZip() const
+ {
+ std::ostringstream ret;
+ DataArrayTemplateClassic<T>::reprZipStream(ret);
+ return ret.str();
+ }
+
/////////////////////////////////
/*!
std::string tmp;
return isEqualIfNotWhy(other,tmp);
}
-
+
+ /*!
+ * Returns a new instance of DataArrayInt. The caller is to delete this array
+ * using decrRef() as it is no more needed.
+ */
+ template<class T>
+ typename Traits<T>::ArrayType *DataArrayDiscrete<T>::New()
+ {
+ return nullptr;//new typename Traits<T>::ArrayType;
+ }
+
/*!
* Checks if values of \a this and another DataArrayInt are equal. For more info see
* \ref MEDCouplingArrayBasicsCompare.
template<class T>
bool DataArrayDiscrete<T>::isEqualWithoutConsideringStrAndOrder(const typename Traits<T>::ArrayType& other) const
{
- MCAuto<DataArrayInt> a(static_cast<const typename Traits<T>::ArrayType *>(this)->deepCopy()),b(other.deepCopy());
+ MCAuto<typename Traits<T>::ArrayType> a((static_cast<const typename Traits<T>::ArrayType *>(this))->deepCopy());
+ MCAuto<typename Traits<T>::ArrayType> b((static_cast<const typename Traits<T>::ArrayType *>(&other))->deepCopy());
a->sort();
b->sort();
return a->isEqualWithoutConsideringStr(*b);
const T *thisPt(this->begin()),*pt(partOfThis.begin());
MCAuto<DataArrayIdType> ret(DataArrayIdType::New());
ret->alloc(nbTuples,1);
- T *retPt(ret->getPointer());
+ mcIdType *retPt(ret->getPointer());
std::map<int,mcIdType> m;
for(std::size_t i=0;i<thisNbTuples;i++,thisPt++)
m[*thisPt]=(mcIdType)i;
}
}
+ /*!
+ * 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.
+ */
+ template<class T>
+ int DataArrayDiscrete<T>::getHashCode() const
+ {
+ this->checkAllocated();
+ std::size_t nbOfElems(this->getNbOfElems());
+ int ret=nbOfElems*65536;
+ int delta=3;
+ if(nbOfElems>48)
+ delta=nbOfElems/8;
+ T ret0(0);
+ const T *pt(this->begin());
+ for(std::size_t i=0;i<nbOfElems;i+=delta)
+ ret0+=pt[i] & 0x1FFF;
+ return ret+ret0;
+ }
+
+ template<class T>
+ void DataArrayDiscrete<T>::reprCppStream(const std::string& varName, std::ostream& stream) const
+ {
+ std::size_t nbTuples(this->getNumberOfTuples()),nbComp(this->getNumberOfComponents());
+ const T *data(this->getConstPointer());
+ stream << Traits<T>::ArrayTypeName << " *" << varName << "=" << Traits<T>::ArrayTypeName << "::New();" << std::endl;
+ if(nbTuples*nbComp>=1)
+ {
+ stream << "const int " << varName << "Data[" << nbTuples*nbComp << "]={";
+ std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator<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(\"" << this->getName() << "\");" << std::endl;
+ }
+
+ /*!
+ * Method that gives a quick overvien of \a this for python.
+ */
+ template<class T>
+ void DataArrayDiscrete<T>::reprQuickOverview(std::ostream& stream) const
+ {
+ static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300;
+ stream << Traits<T>::ArrayTypeName << " C++ instance at " << this << ". ";
+ if(this->isAllocated())
+ {
+ std::size_t nbOfCompo(this->getNumberOfComponents());
+ if(nbOfCompo>=1)
+ {
+ std::size_t nbOfTuples(this->getNumberOfTuples());
+ stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl;
+ reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR);
+ }
+ else
+ stream << "Number of components : 0.";
+ }
+ else
+ stream << "*** No data allocated ****";
+ }
+
+ template<class T>
+ void DataArrayDiscrete<T>::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const
+ {
+ const T *data(this->begin());
+ std::size_t nbOfTuples(this->getNumberOfTuples()),nbOfCompo(this->getNumberOfComponents());
+ std::ostringstream oss2; oss2 << "[";
+ std::string oss2Str(oss2.str());
+ bool isFinished=true;
+ for(int i=0;i<nbOfTuples && isFinished;i++)
+ {
+ if(nbOfCompo>1)
+ {
+ oss2 << "(";
+ for(int j=0;j<nbOfCompo;j++,data++)
+ {
+ oss2 << *data;
+ if(j!=nbOfCompo-1) oss2 << ", ";
+ }
+ oss2 << ")";
+ }
+ else
+ oss2 << *data++;
+ if(i!=nbOfTuples-1) oss2 << ", ";
+ std::string oss3Str(oss2.str());
+ if(oss3Str.length()<maxNbOfByteInRepr)
+ oss2Str=oss3Str;
+ else
+ isFinished=false;
+ }
+ stream << oss2Str;
+ if(!isFinished)
+ stream << "... ";
+ stream << "]";
+ }
+
+ template<class T>
+ void DataArrayDiscrete<T>::writeVTK(std::ostream& ofs, int indent, const std::string& type, const std::string& nameInFile, DataArrayByte *byteArr) const
+ {
+ static const char SPACE[4]={' ',' ',' ',' '};
+ this->checkAllocated();
+ std::string idt(indent,' ');
+ ofs << idt << "<DataArray type=\"" << type << "\" Name=\"" << nameInFile << "\" NumberOfComponents=\"" << this->getNumberOfComponents() << "\"";
+ if(byteArr)
+ {
+ ofs << " format=\"appended\" offset=\"" << byteArr->getNumberOfTuples() << "\">";
+ if(std::string(type)==Traits<T>::VTKReprStr)
+ {
+ const char *data(reinterpret_cast<const char *>(this->begin()));
+ std::size_t sz(this->getNbOfElems()*sizeof(T));
+ byteArr->insertAtTheEnd(data,data+sz);
+ byteArr->insertAtTheEnd(SPACE,SPACE+4);
+ }
+ else if(std::string(type)=="Int8")
+ {
+ INTERP_KERNEL::AutoPtr<char> tmp(new char[this->getNbOfElems()]);
+ std::copy(this->begin(),this->end(),(char *)tmp);
+ byteArr->insertAtTheEnd((char *)tmp,(char *)tmp+this->getNbOfElems());
+ byteArr->insertAtTheEnd(SPACE,SPACE+4);
+ }
+ else if(std::string(type)=="UInt8")
+ {
+ INTERP_KERNEL::AutoPtr<unsigned char> tmp(new unsigned char[this->getNbOfElems()]);
+ std::copy(this->begin(),this->end(),(unsigned char *)tmp);
+ byteArr->insertAtTheEnd((unsigned char *)tmp,(unsigned char *)tmp+this->getNbOfElems());
+ byteArr->insertAtTheEnd(SPACE,SPACE+4);
+ }
+ else
+ {
+ std::ostringstream oss;
+ oss << Traits<T>::ArrayTypeName << "::writeVTK : Only " << Traits<T>::VTKReprStr << ", Int8 and UInt8 supported !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ }
+ else
+ {
+ ofs << " RangeMin=\"" << this->getMinValueInArray() << "\" RangeMax=\"" << this->getMaxValueInArray() << "\" format=\"ascii\">\n" << idt;
+ std::copy(this->begin(),this->end(),std::ostream_iterator<int>(ofs," "));
+ }
+ ofs << std::endl << idt << "</DataArray>\n";
+ }
+
+ /*!
+ * Modifies in place \a this one-dimensional array so that each value \a v = \a indArrBg[ \a v ],
+ * i.e. a current value is used as in index to get a new value from \a indArrBg.
+ * \param [in] indArrBg - pointer to the first element of array of new values to assign
+ * to \a this array.
+ * \param [in] indArrEnd - specifies the end of the array \a indArrBg, so that
+ * the last value of \a indArrBg is \a indArrEnd[ -1 ].
+ * \throw If \a this->getNumberOfComponents() != 1
+ * \throw If any value of \a this can't be used as a valid index for
+ * [\a indArrBg, \a indArrEnd).
+ *
+ * \sa changeValue, findIdForEach
+ */
+ template<class T>
+ void DataArrayDiscrete<T>::transformWithIndArr(const T *indArrBg, const T *indArrEnd)
+ {
+ this->checkAllocated();
+ if(this->getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !");
+ std::size_t nbElemsIn(std::distance(indArrBg,indArrEnd)),nbOfTuples(this->getNumberOfTuples());
+ T *pt(this->getPointer());
+ for(std::size_t i=0;i<nbOfTuples;i++,pt++)
+ {
+ if(*pt>=0 && *pt<nbElemsIn)
+ *pt=indArrBg[*pt];
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayInt::transformWithIndArr : error on tuple #" << i << " of this value is " << *pt << ", should be in [0," << nbElemsIn << ") !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ }
+ this->declareAsNew();
+ }
+
+ template<class T>
+ void DataArrayDiscrete<T>::transformWithIndArr(const MapKeyVal<T>& m)
+ {
+ this->checkAllocated();
+ if(this->getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !");
+ const typename std::map<T,T>& dat(m.data());
+ std::size_t nbOfTuples(this->getNumberOfTuples());
+ T *pt(this->getPointer());
+ for(std::size_t i=0;i<nbOfTuples;i++,pt++)
+ {
+ typename std::map<T,T>::const_iterator it(dat.find(*pt));
+ if(it!=dat.end())
+ *pt=(*it).second;
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayInt::transformWithIndArr : error on tuple #" << i << " of this value is " << *pt << " not in map !";
+ throw INTERP_KERNEL::Exception(oss.str());
+ }
+ }
+ this->declareAsNew();
+ }
+
////////////////////////////////////
/*!
const char Traits<int>::ReprStr[]="int";
+const char Traits<int>::VTKReprStr[]="Int32";
+
const char Traits<char>::ArrayTypeName[]="DataArrayChar";
const char Traits<Int64>::ArrayTypeName[]="DataArrayInt64";
const char Traits<Int64>::NPYStr[]="INT64";
const char Traits<Int64>::ReprStr[]="int64";
+
+const char Traits<Int64>::VTKReprStr[]="Int64";
static const char FieldTypeName[];
static const char NPYStr[];
static const char ReprStr[];
+ static const char VTKReprStr[];
typedef DataArrayInt32 ArrayType;
typedef DataArrayInt32 ArrayTypeCh;
typedef MEDCouplingFieldInt FieldType;
static const char FieldTypeName[];
static const char NPYStr[];
static const char ReprStr[];
+ static const char VTKReprStr[];
typedef DataArrayInt64 ArrayType;
typedef DataArrayInt64 ArrayTypeCh;
//typedef MEDCouplingFieldInt64 FieldType;