Salome HOME
First draft of int64.
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 20 Dec 2018 09:55:59 +0000 (10:55 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 20 Dec 2018 12:57:30 +0000 (13:57 +0100)
src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling/MEDCouplingMemArray.hxx
src/MEDCoupling/MEDCouplingMemArray.txx
src/MEDCoupling/MEDCouplingTraits.cxx
src/MEDCoupling/MEDCouplingTraits.hxx

index aaa55d3bc068c4ccd9b6d04bc1a4e5a6e25e404e..29354bb74cd02790c28bdacdf8ac3092d4ca9af7 100644 (file)
@@ -53,6 +53,8 @@ template class MEDCoupling::DataArrayIterator<double>;
 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>;
@@ -884,27 +886,6 @@ bool DataArrayDouble::isMonotonic(bool increasing, double eps) const
     }
 }
 
-/*!
- * 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]={' ',' ',' ',' '};
@@ -969,10 +950,10 @@ void DataArrayDouble::reprQuickOverview(std::ostream& stream) const
   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);
         }
@@ -3678,15 +3659,6 @@ DataArrayDouble *DataArrayDoubleTuple::buildDADouble(int nbOfTuples, int nbOfCom
   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.
@@ -3708,27 +3680,6 @@ int DataArrayInt::intValue() const
     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.
@@ -3739,143 +3690,6 @@ DataArrayInt32 *DataArrayInt32::deepCopy() const
   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,
@@ -4022,60 +3836,6 @@ bool DataArrayInt::isRange(int& strt, int& sttoopp, int& stteepp) const
     }
 }
 
-
-/*!
- * 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:
@@ -6916,3 +6676,8 @@ DataArrayInt *DataArrayIntTuple::buildDAInt(int nbOfTuples, int nbOfCompo) const
 {
   return this->buildDA(nbOfTuples,nbOfCompo);
 }
+
+DataArrayInt64 *DataArrayInt64::deepCopy() const
+{
+  return new DataArrayInt64(*this);
+}
index 3887de6298f60ba3ef6aa4de752194f2f5357edb..56e0e9329a13c8e1e7a8072049c340ad6fcb64f6 100644 (file)
@@ -246,7 +246,7 @@ namespace MEDCoupling
     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);
@@ -353,6 +353,8 @@ namespace MEDCoupling
     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;
@@ -415,8 +417,6 @@ namespace MEDCoupling
     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;
@@ -528,6 +528,7 @@ namespace MEDCoupling
   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;
@@ -540,6 +541,13 @@ namespace MEDCoupling
     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;
@@ -560,21 +568,12 @@ namespace MEDCoupling
 
   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;
@@ -678,6 +677,19 @@ namespace MEDCoupling
 
   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>
index f2c2f4690fdd8500e4fa65f6b3ce44b8c98d19bb..c8ea9370feb552fcfcbc10027a9b809971937820 100644 (file)
@@ -1128,7 +1128,7 @@ namespace MEDCoupling
   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>
@@ -3385,6 +3385,29 @@ struct NotInRange
     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();
+  }
+  
   /////////////////////////////////
   
   /*!
@@ -3438,7 +3461,17 @@ struct NotInRange
     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 new typename Traits<T>::ArrayType;
+  }
+  
   /*!
    * Checks if values of \a this and another DataArrayInt are equal. For more info see
    * \ref MEDCouplingArrayBasicsCompare.
@@ -3462,7 +3495,8 @@ struct NotInRange
   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);
@@ -3586,7 +3620,7 @@ struct NotInRange
     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;
@@ -3720,6 +3754,208 @@ struct NotInRange
       }
   }
 
+  /*!
+   * 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();
+  }
+
   ////////////////////////////////////
 
   /*!
index 46e3f7b1fd1d31f377fca2864bbd976e948bc16a..8febd9af4aa2d1433b1ef814b361b978d676b104 100644 (file)
@@ -46,6 +46,8 @@ const char Traits<int>::NPYStr[]="INT32";
 
 const char Traits<int>::ReprStr[]="int";
 
+const char Traits<int>::VTKReprStr[]="Int32";
+
 const char Traits<char>::ArrayTypeName[]="DataArrayChar";
 
 const char Traits<Int64>::ArrayTypeName[]="DataArrayInt64";
@@ -55,3 +57,5 @@ const char Traits<Int64>::FieldTypeName[]="MEDCouplingFieldInt64";
 const char Traits<Int64>::NPYStr[]="INT64";
 
 const char Traits<Int64>::ReprStr[]="int64";
+
+const char Traits<Int64>::VTKReprStr[]="Int64";
index a14232eec8114310127d62b50cd2ca85f21d485f..7059106c10f572f1c5024692289aebdea22024d7 100644 (file)
@@ -78,6 +78,7 @@ namespace MEDCoupling
     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;
@@ -91,6 +92,7 @@ namespace MEDCoupling
     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;