//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// Author : Anthony Geay (CEA/DEN)
+// Author : Anthony Geay (EDF R&D)
#include "MEDCouplingMemArray.txx"
template class MEDCoupling::DataArrayTemplateFP<double>;
template class MEDCoupling::DataArrayIterator<double>;
template class MEDCoupling::DataArrayIterator<int>;
+template class MEDCoupling::DataArrayDiscrete<Int32>;
+template class MEDCoupling::DataArrayDiscreteSigned<Int32>;
template<int SPACEDIM>
void DataArrayDouble::findCommonTuplesAlg(const double *bbox, int nbNodes, int limitNodeId, double prec, DataArrayInt *c, DataArrayInt *cI) const
* \ref MEDCouplingArrayBasicsCopyDeep.
* \return DataArrayInt * - a new instance of DataArrayInt.
*/
-DataArrayInt *DataArrayInt::deepCopy() const
+DataArrayInt32 *DataArrayInt32::deepCopy() const
{
- return new DataArrayInt(*this);
+ return new DataArrayInt32(*this);
}
/*!
return ret;
}
-/*!
- * Equivalent to DataArrayInt::isEqual except that if false the reason of
- * mismatch is given.
- *
- * \param [in] other the instance to be compared with \a this
- * \param [out] reason In case of inequality returns the reason.
- * \sa DataArrayInt::isEqual
- */
-bool DataArrayInt::isEqualIfNotWhy(const DataArrayInt& other, std::string& reason) const
-{
- if(!areInfoEqualsIfNotWhy(other,reason))
- return false;
- return _mem.isEqual(other._mem,0,reason);
-}
-
-/*!
- * Checks if \a this and another DataArrayInt are fully equal. For more info see
- * \ref MEDCouplingArrayBasicsCompare.
- * \param [in] other - an instance of DataArrayInt to compare with \a this one.
- * \return bool - \a true if the two arrays are equal, \a false else.
- */
-bool DataArrayInt::isEqual(const DataArrayInt& other) const
-{
- std::string tmp;
- return isEqualIfNotWhy(other,tmp);
-}
-
-/*!
- * Checks if values of \a this and another DataArrayInt are equal. For more info see
- * \ref MEDCouplingArrayBasicsCompare.
- * \param [in] other - an instance of DataArrayInt to compare with \a this one.
- * \return bool - \a true if the values of two arrays are equal, \a false else.
- */
-bool DataArrayInt::isEqualWithoutConsideringStr(const DataArrayInt& other) const
-{
- std::string tmp;
- return _mem.isEqual(other._mem,0,tmp);
-}
-
-/*!
- * Checks if values of \a this and another DataArrayInt are equal. Comparison is
- * performed on sorted value sequences.
- * For more info see\ref MEDCouplingArrayBasicsCompare.
- * \param [in] other - an instance of DataArrayInt to compare with \a this one.
- * \return bool - \a true if the sorted values of two arrays are equal, \a false else.
- */
-bool DataArrayInt::isEqualWithoutConsideringStrAndOrder(const DataArrayInt& other) const
-{
- MCAuto<DataArrayInt> a=deepCopy();
- MCAuto<DataArrayInt> b=other.deepCopy();
- a->sort();
- b->sort();
- return a->isEqualWithoutConsideringStr(*b);
-}
-
-/*!
- * This method compares content of input vector \a v and \a this.
- * If for each id in \a this v[id]==True and for all other ids id2 not in \a this v[id2]==False, true is returned.
- * For performance reasons \a this is expected to be sorted ascendingly. If not an exception will be thrown.
- *
- * \param [in] v - the vector of 'flags' to be compared with \a this.
- *
- * \throw If \a this is not sorted ascendingly.
- * \throw If \a this has not exactly one component.
- * \throw If \a this is not allocated.
- */
-bool DataArrayInt::isFittingWith(const std::vector<bool>& v) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::isFittingWith : number of components of this should be equal to one !");
- const int *w(begin()),*end2(end());
- int refVal=-std::numeric_limits<int>::max();
- int i=0;
- std::vector<bool>::const_iterator it(v.begin());
- for(;it!=v.end();it++,i++)
- {
- if(*it)
- {
- if(w!=end2)
- {
- if(*w++==i)
- {
- if(i>refVal)
- refVal=i;
- else
- {
- std::ostringstream oss; oss << "DataArrayInt::isFittingWith : At pos #" << std::distance(begin(),w-1) << " this is not sorted ascendingly !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- else
- return false;
- }
- else
- return false;
- }
- }
- return w==end2;
-}
-
-/*!
- * 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.
- */
-void DataArrayInt::switchOnTupleEqualTo(int val, std::vector<bool>& vec) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleEqualTo : number of components of this should be equal to one !");
- int nbOfTuples(getNumberOfTuples());
- if(nbOfTuples!=(int)vec.size())
- throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleEqualTo : number of tuples of this should be equal to size of input vector of bool !");
- const int *pt(begin());
- for(int i=0;i<nbOfTuples;i++)
- if(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 different from \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::switchOnTupleEqualTo.
- */
-void DataArrayInt::switchOnTupleNotEqualTo(int val, std::vector<bool>& vec) const
-{
- checkAllocated();
- if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleNotEqualTo : number of components of this should be equal to one !");
- int nbOfTuples(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 int *pt(begin());
- for(int i=0;i<nbOfTuples;i++)
- if(pt[i]!=val)
- vec[i]=true;
-}
-
/*!
* Computes for each tuple the sum of number of components values in the tuple and return it.
*
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// Author : Anthony Geay (CEA/DEN)
+// Author : Anthony Geay (EDF R&D)
#ifndef __MEDCOUPLING_MEDCOUPLINGMEMARRAY_HXX__
#define __MEDCOUPLING_MEDCOUPLINGMEMARRAY_HXX__
DataArrayDouble() { }
};
+ template<class T>
+ class DataArrayDiscrete : public DataArrayTemplateClassic<T>
+ {
+ public:
+ 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 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:
+ ~DataArrayDiscrete() { }
+ };
+
+ template<class T>
+ class DataArrayDiscreteSigned : public DataArrayDiscrete<T>
+ {
+ public:
+ MEDCOUPLING_EXPORT bool isFittingWith(const std::vector<bool>& v) const;
+ protected:
+ ~DataArrayDiscreteSigned() { }
+ };
+
class DataArrayInt32Iterator;
- class DataArrayInt32 : public DataArrayTemplateClassic<Int32>
+ class DataArrayInt32 : public DataArrayDiscreteSigned<Int32>
{
public:
MEDCOUPLING_EXPORT static DataArrayInt32 *New();
MEDCOUPLING_EXPORT int intValue() const;
MEDCOUPLING_EXPORT int getHashCode() const;
- MEDCOUPLING_EXPORT DataArrayInt32 *deepCopy() const;
- MEDCOUPLING_EXPORT DataArrayInt32 *buildNewEmptyInstance() const { return DataArrayInt32::New(); }
- MEDCOUPLING_EXPORT bool isEqual(const DataArrayInt32& other) const;
- MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayInt32& other, std::string& reason) const;
- MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayInt32& other) const;
- MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStrAndOrder(const DataArrayInt32& other) const;
- MEDCOUPLING_EXPORT bool isFittingWith(const std::vector<bool>& v) const;
- MEDCOUPLING_EXPORT void switchOnTupleEqualTo(int val, std::vector<bool>& vec) const;
- MEDCOUPLING_EXPORT void switchOnTupleNotEqualTo(int val, std::vector<bool>& vec) const;
+ MEDCOUPLING_EXPORT DataArrayInt32 *deepCopy() const;//ok
+ MEDCOUPLING_EXPORT DataArrayInt32 *buildNewEmptyInstance() const { return DataArrayInt32::New(); }//ok
MEDCOUPLING_EXPORT DataArrayInt32 *buildPermutationArr(const DataArrayInt32& other) const;
MEDCOUPLING_EXPORT DataArrayInt32 *indicesOfSubPart(const DataArrayInt32& partOfThis) const;
MEDCOUPLING_EXPORT DataArrayInt32 *sumPerTuple() const;
DataArrayInt32() { }
};
- class DataArrayInt64 : public DataArrayTemplateClassic<Int64>
+ class DataArrayInt64 : public DataArrayDiscrete<Int64>
{
};
ptr[i]=init+T(i);
this->declareAsNew();
}
+
+ /*!
+ * Equivalent to DataArrayInt::isEqual except that if false the reason of
+ * mismatch is given.
+ *
+ * \param [in] other the instance to be compared with \a this
+ * \param [out] reason In case of inequality returns the reason.
+ * \sa DataArrayInt::isEqual
+ */
+ template<class T>
+ bool DataArrayDiscrete<T>::isEqualIfNotWhy(const DataArrayDiscrete<T>& other, std::string& reason) const
+ {
+ if(!this->areInfoEqualsIfNotWhy(other,reason))
+ return false;
+ return this->_mem.isEqual(other._mem,0,reason);
+ }
+
+ /*!
+ * Checks if \a this and another DataArrayInt are fully equal. For more info see
+ * \ref MEDCouplingArrayBasicsCompare.
+ * \param [in] other - an instance of DataArrayInt to compare with \a this one.
+ * \return bool - \a true if the two arrays are equal, \a false else.
+ */
+ template<class T>
+ bool DataArrayDiscrete<T>::isEqual(const DataArrayDiscrete<T>& other) const
+ {
+ std::string tmp;
+ return isEqualIfNotWhy(other,tmp);
+ }
+
+ /*!
+ * Checks if values of \a this and another DataArrayInt are equal. For more info see
+ * \ref MEDCouplingArrayBasicsCompare.
+ * \param [in] other - an instance of DataArrayInt to compare with \a this one.
+ * \return bool - \a true if the values of two arrays are equal, \a false else.
+ */
+ template<class T>
+ bool DataArrayDiscrete<T>::isEqualWithoutConsideringStr(const DataArrayDiscrete<T>& other) const
+ {
+ std::string tmp;
+ return this->_mem.isEqual(other._mem,0,tmp);
+ }
+
+ /*!
+ * Checks if values of \a this and another DataArrayInt are equal. Comparison is
+ * performed on sorted value sequences.
+ * For more info see\ref MEDCouplingArrayBasicsCompare.
+ * \param [in] other - an instance of DataArrayInt to compare with \a this one.
+ * \return bool - \a true if the sorted values of two arrays are equal, \a false else.
+ */
+ 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());
+ a->sort();
+ 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
+ {
+ this->checkAllocated();
+ if(this->getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleEqualTo : number of components of this should be equal to one !");
+ int nbOfTuples(this->getNumberOfTuples());
+ if(nbOfTuples!=(int)vec.size())
+ 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)
+ 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 different from \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::switchOnTupleEqualTo.
+ */
+ 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;
+ }
+
+ /*!
+ * This method compares content of input vector \a v and \a this.
+ * If for each id in \a this v[id]==True and for all other ids id2 not in \a this v[id2]==False, true is returned.
+ * For performance reasons \a this is expected to be sorted ascendingly. If not an exception will be thrown.
+ *
+ * \param [in] v - the vector of 'flags' to be compared with \a this.
+ *
+ * \throw If \a this is not sorted ascendingly.
+ * \throw If \a this has not exactly one component.
+ * \throw If \a this is not allocated.
+ */
+ template<class T>
+ bool DataArrayDiscreteSigned<T>::isFittingWith(const std::vector<bool>& v) const
+ {
+ this->checkAllocated();
+ if(this->getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt::isFittingWith : number of components of this should be equal to one !");
+ const T *w(this->begin()),*end2(this->end());
+ T refVal=-std::numeric_limits<T>::max();
+ int i=0;
+ std::vector<bool>::const_iterator it(v.begin());
+ for(;it!=v.end();it++,i++)
+ {
+ if(*it)
+ {
+ if(w!=end2)
+ {
+ if(*w++==i)
+ {
+ if(i>refVal)
+ refVal=i;
+ else
+ {
+ std::ostringstream oss; oss << "DataArrayInt::isFittingWith : At pos #" << std::distance(this->begin(),w-1) << " this is not sorted ascendingly !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ else
+ return false;
+ }
+ else
+ return false;
+ }
+ }
+ return w==end2;
+ }
}
#endif