Salome HOME
scotch6.0.4 needs pthread... Quick and dirty solution to be improved
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingPartDefinition.cxx
index 4af214cc01f98000e446f219cf00504c8ac63c4c..9652e8ddd6503210a77bc1d57a3ba0ad4c07022f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -20,7 +20,9 @@
 
 #include "MEDCouplingPartDefinition.hxx"
 
-using namespace ParaMEDMEM;
+#include <sstream>
+
+using namespace MEDCoupling;
 
 PartDefinition *PartDefinition::New(int start, int stop, int step)
 {
@@ -32,6 +34,24 @@ PartDefinition *PartDefinition::New(DataArrayInt *listOfIds)
   return DataArrayPartDefinition::New(listOfIds);
 }
 
+PartDefinition *PartDefinition::Unserialize(std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI)
+{
+  if(tinyInt.empty())
+    {
+      MCAuto<PartDefinition> ret(DataArrayPartDefinition::New(bigArraysI.back()));
+      bigArraysI.pop_back();
+      return ret.retn();
+    }
+  else if(tinyInt.size()==3)
+    {
+      MCAuto<PartDefinition> ret(SlicePartDefinition::New(tinyInt[0],tinyInt[1],tinyInt[2]));
+      tinyInt.erase(tinyInt.begin(),tinyInt.begin()+3);
+      return ret.retn();
+    }
+  else
+    throw INTERP_KERNEL::Exception("PartDefinition::Unserialize");
+}
+
 PartDefinition::~PartDefinition()
 {
 }
@@ -41,6 +61,45 @@ DataArrayPartDefinition *DataArrayPartDefinition::New(DataArrayInt *listOfIds)
   return new DataArrayPartDefinition(listOfIds);
 }
 
+bool DataArrayPartDefinition::isEqual(const PartDefinition *other, std::string& what) const
+{
+  if(!other)
+    {
+      what="DataArrayPartDefinition::isEqual : other is null, this is not null !";
+      return false;
+    }
+  const DataArrayPartDefinition *otherC(dynamic_cast<const DataArrayPartDefinition *>(other));
+  if(!otherC)
+    {
+      what="DataArrayPartDefinition::isEqual : other is not DataArrayPartDefinition !";
+      return false;
+    }
+  const DataArrayInt *arr0(_arr),*arr1(otherC->_arr);
+  if(!arr0 && !arr1)
+    return true;
+  if((arr0 && !arr1) || (!arr0 && arr1))
+    {
+      what="DataArrayPartDefinition::isEqual : array is not defined both in other and this !";
+      return false;
+    }
+  std::string what1;
+  bool ret(arr0->isEqualIfNotWhy(*arr1,what1));
+  if(!ret)
+    {
+      what=std::string("DataArrayPartDefinition::isEqual : arrays are not equal :\n")+what1;
+      return false;
+    }
+  return true;
+}
+
+DataArrayPartDefinition *DataArrayPartDefinition::deepCopy() const
+{
+  const DataArrayInt *arr(_arr);
+  if(!arr)
+    throw INTERP_KERNEL::Exception("DataArrayPartDefinition::deepCopy : array is null !");
+  return DataArrayPartDefinition::New(const_cast<DataArrayInt *>(arr));
+}
+
 int DataArrayPartDefinition::getNumberOfElems() const
 {
   checkInternalArrayOK();
@@ -80,8 +139,8 @@ PartDefinition *DataArrayPartDefinition::composeWith(const PartDefinition *other
 {
   if(!other)
     throw INTERP_KERNEL::Exception("DataArrayPartDefinition::composeWith : input PartDef must be not NULL !");
-  checkCoherency();
-  other->checkCoherency();
+  checkConsistencyLight();
+  other->checkConsistencyLight();
   const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(other));
   if(spd)
     {//special case for optim
@@ -89,19 +148,19 @@ PartDefinition *DataArrayPartDefinition::composeWith(const PartDefinition *other
       spd->getSlice(a,b,c);
       if(c==1)
         {
-          MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr(DataArrayInt::New());
+          MCAuto<DataArrayInt> arr(DataArrayInt::New());
           arr->alloc(_arr->getNumberOfTuples(),1);
           std::transform(_arr->begin(),_arr->end(),arr->getPointer(),std::bind2nd(std::plus<int>(),a));
           return DataArrayPartDefinition::New(arr);
         }
     }
   //
-  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr1(other->toDAI());
-  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2(arr1->selectByTupleIdSafe(_arr->begin(),_arr->end()));
+  MCAuto<DataArrayInt> arr1(other->toDAI());
+  MCAuto<DataArrayInt> arr2(arr1->selectByTupleIdSafe(_arr->begin(),_arr->end()));
   return DataArrayPartDefinition::New(arr2);
 }
 
-void DataArrayPartDefinition::checkCoherency() const
+void DataArrayPartDefinition::checkConsistencyLight() const
 {
   CheckInternalArrayOK(_arr);
 }
@@ -113,7 +172,7 @@ void DataArrayPartDefinition::checkCoherency() const
  */
 PartDefinition *DataArrayPartDefinition::tryToSimplify() const
 {
-  checkCoherency();
+  checkConsistencyLight();
   int a(0),b(0),c(0);
   if(_arr->isRange(a,b,c))
     {
@@ -127,6 +186,11 @@ PartDefinition *DataArrayPartDefinition::tryToSimplify() const
     }
 }
 
+void DataArrayPartDefinition::serialize(std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI) const
+{
+  bigArraysI.push_back(_arr);
+}
+
 DataArrayInt *DataArrayPartDefinition::toDAI() const
 {
   checkInternalArrayOK();
@@ -173,16 +237,16 @@ std::vector<const BigMemoryObject *> DataArrayPartDefinition::getDirectChildrenW
 
 DataArrayPartDefinition *DataArrayPartDefinition::add1(const DataArrayPartDefinition *other) const
 {
-  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a1(toDAI()),a2(other->toDAI());
-  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a3(DataArrayInt::Aggregate(a1,a2,0));
+  MCAuto<DataArrayInt> a1(toDAI()),a2(other->toDAI());
+  MCAuto<DataArrayInt> a3(DataArrayInt::Aggregate(a1,a2,0));
   a3->sort();
   return DataArrayPartDefinition::New(a3);
 }
 
 DataArrayPartDefinition *DataArrayPartDefinition::add2(const SlicePartDefinition *other) const
 {
-  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a1(toDAI()),a2(other->toDAI());
-  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a3(DataArrayInt::Aggregate(a1,a2,0));
+  MCAuto<DataArrayInt> a1(toDAI()),a2(other->toDAI());
+  MCAuto<DataArrayInt> a3(DataArrayInt::Aggregate(a1,a2,0));
   a3->sort();
   return DataArrayPartDefinition::New(a3);
 }
@@ -196,6 +260,33 @@ SlicePartDefinition *SlicePartDefinition::New(int start, int stop, int step)
   return new SlicePartDefinition(start,stop,step);
 }
 
+bool SlicePartDefinition::isEqual(const PartDefinition *other, std::string& what) const
+{
+  if(!other)
+    {
+      what="SlicePartDefinition::isEqual : other is null, this is not null !";
+      return false;
+    }
+  const SlicePartDefinition *otherC(dynamic_cast<const SlicePartDefinition *>(other));
+  if(!otherC)
+    {
+      what="SlicePartDefinition::isEqual : other is not SlicePartDefinition !";
+      return false;
+    }
+  bool ret((_start==otherC->_start) && (_stop==otherC->_stop) && (_step==otherC->_step));
+  if(!ret)
+    {
+      what="SlicePartDefinition::isEqual : values are not the same !";
+      return false;
+    }
+  return true;
+}
+
+SlicePartDefinition *SlicePartDefinition::deepCopy() const
+{
+  return SlicePartDefinition::New(_start,_stop,_step);
+}
+
 DataArrayInt *SlicePartDefinition::toDAI() const
 {
   return DataArrayInt::Range(_start,_stop,_step);
@@ -228,17 +319,17 @@ PartDefinition *SlicePartDefinition::composeWith(const PartDefinition *other) co
 {
   if(!other)
     throw INTERP_KERNEL::Exception("SlicePartDefinition::composeWith : input PartDef must be not NULL !");
-  checkCoherency();
-  other->checkCoherency();
-  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr(other->toDAI());
-  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr1(arr->selectByTupleId2(_start,_stop,_step));
+  checkConsistencyLight();
+  other->checkConsistencyLight();
+  MCAuto<DataArrayInt> arr(other->toDAI());
+  MCAuto<DataArrayInt> arr1(arr->selectByTupleIdSafeSlice(_start,_stop,_step));
   return DataArrayPartDefinition::New(arr1);
 }
 
 /*!
  * Do nothing it is not a bug.
  */
-void SlicePartDefinition::checkCoherency() const
+void SlicePartDefinition::checkConsistencyLight() const
 {
 }
 
@@ -254,6 +345,13 @@ PartDefinition *SlicePartDefinition::tryToSimplify() const
   return ret;
 }
 
+void SlicePartDefinition::serialize(std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI) const
+{
+  tinyInt.push_back(_start);
+  tinyInt.push_back(_stop);
+  tinyInt.push_back(_step);
+}
+
 std::string SlicePartDefinition::getRepr() const
 {
   std::ostringstream oss;
@@ -297,8 +395,8 @@ std::vector<const BigMemoryObject *> SlicePartDefinition::getDirectChildrenWithN
 
 DataArrayPartDefinition *SlicePartDefinition::add1(const DataArrayPartDefinition *other) const
 {
-  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a1(toDAI()),a2(other->toDAI());
-  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a3(DataArrayInt::Aggregate(a1,a2,0));
+  MCAuto<DataArrayInt> a1(toDAI()),a2(other->toDAI());
+  MCAuto<DataArrayInt> a3(DataArrayInt::Aggregate(a1,a2,0));
   a3->sort();
   return DataArrayPartDefinition::New(a3);
 }
@@ -311,8 +409,8 @@ PartDefinition *SlicePartDefinition::add2(const SlicePartDefinition *other) cons
     }
   else
     {
-      MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a1(toDAI()),a2(other->toDAI());
-      MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a3(DataArrayInt::Aggregate(a1,a2,0));
+      MCAuto<DataArrayInt> a1(toDAI()),a2(other->toDAI());
+      MCAuto<DataArrayInt> a3(DataArrayInt::Aggregate(a1,a2,0));
       a3->sort();
       return DataArrayPartDefinition::New(a3);
     }