Salome HOME
On the road agy/Template1
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 26 May 2017 21:26:07 +0000 (23:26 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 26 May 2017 21:26:07 +0000 (23:26 +0200)
src/MEDCoupling/MEDCouplingMemArray.hxx
src/MEDCoupling/MEDCouplingMemArray.txx

index 716bbb7447443c9283867dde7424a069d83f9573..462cd534308c19be3bf6e135f375175914af2378 100644 (file)
@@ -530,6 +530,9 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStrAndOrder(const typename Traits<T>::ArrayType& other) const;
     MEDCOUPLING_EXPORT void switchOnTupleEqualTo(T val, std::vector<bool>& vec) const;
     MEDCOUPLING_EXPORT void switchOnTupleNotEqualTo(T val, std::vector<bool>& vec) const;
+  protected:
+    template<class ALG>
+    void switchOnTupleAlg(T val, std::vector<bool>& vec, ALG algo) const;
   protected:
     ~DataArrayDiscrete() { }
   };
index b66c6a6679e8ca8ad59cd337c9bcdecd7db0dbd6..aaec5ed8eefcaef9320798464e5f4076c8b30dba 100644 (file)
@@ -3307,16 +3307,10 @@ struct NotInRange
     b->sort();
     return a->isEqualWithoutConsideringStr(*b);
   }
-
-  /*!
-   * This method assumes that \a this has one component and is allocated. This method scans all tuples in \a this and for all tuple equal to \a val
-   * put True to the corresponding entry in \a vec.
-   * \a vec is expected to be with the same size than the number of tuples of \a this.
-   *
-   *  \sa DataArrayInt::switchOnTupleNotEqualTo.
-   */
+  
   template<class T>
-  void DataArrayDiscrete<T>::switchOnTupleEqualTo(T val, std::vector<bool>& vec) const
+  template<class ALG>
+  void DataArrayDiscrete<T>::switchOnTupleAlg(T val, std::vector<bool>& vec, ALG algo) const
   {
     this->checkAllocated();
     if(this->getNumberOfComponents()!=1)
@@ -3326,9 +3320,22 @@ struct NotInRange
       throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleEqualTo : number of tuples of this should be equal to size of input vector of bool !");
     const T *pt(this->begin());
     for(int i=0;i<nbOfTuples;i++)
-      if(pt[i]==val)
+      if(algo(pt[i],val))
         vec[i]=true;
   }
+  
+  /*!
+   * This method assumes that \a this has one component and is allocated. This method scans all tuples in \a this and for all tuple equal to \a val
+   * put True to the corresponding entry in \a vec.
+   * \a vec is expected to be with the same size than the number of tuples of \a this.
+   *
+   *  \sa DataArrayInt::switchOnTupleNotEqualTo.
+   */
+  template<class T>
+  void DataArrayDiscrete<T>::switchOnTupleEqualTo(T val, std::vector<bool>& vec) const
+  {
+    switchOnTupleAlg(val,vec,std::equal_to<T>());
+  }
 
   /*!
    * This method assumes that \a this has one component and is allocated. This method scans all tuples in \a this and for all tuple different from \a val
@@ -3340,16 +3347,7 @@ struct NotInRange
   template<class T>
   void DataArrayDiscrete<T>::switchOnTupleNotEqualTo(T val, std::vector<bool>& vec) const
   {
-    this->checkAllocated();
-    if(this->getNumberOfComponents()!=1)
-      throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleNotEqualTo : number of components of this should be equal to one !");
-    int nbOfTuples(this->getNumberOfTuples());
-    if(nbOfTuples!=(int)vec.size())
-      throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleNotEqualTo : number of tuples of this should be equal to size of input vector of bool !");
-    const T *pt(this->begin());
-    for(int i=0;i<nbOfTuples;i++)
-      if(pt[i]!=val)
-        vec[i]=true;
+    switchOnTupleAlg(val,vec,std::not_equal_to<T>());
   }
 
   /*!