1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (EDF R&D)
21 #include "MEDCouplingPartDefinition.hxx"
23 using namespace ParaMEDMEM;
25 PartDefinition *PartDefinition::New(int start, int stop, int step)
27 return SlicePartDefinition::New(start,stop,step);
30 PartDefinition *PartDefinition::New(DataArrayInt *listOfIds)
32 return DataArrayPartDefinition::New(listOfIds);
35 PartDefinition::~PartDefinition()
39 DataArrayPartDefinition *DataArrayPartDefinition::New(DataArrayInt *listOfIds)
41 return new DataArrayPartDefinition(listOfIds);
44 int DataArrayPartDefinition::getNumberOfElems() const
46 checkInternalArrayOK();
47 return _arr->getNumberOfTuples();
50 PartDefinition *DataArrayPartDefinition::operator+(const PartDefinition& other) const
52 const PartDefinition *otherPt(&other);
54 throw INTERP_KERNEL::Exception("DataArrayPartDefinition::operator+ : NULL input !");
55 const DataArrayPartDefinition *other1(dynamic_cast<const DataArrayPartDefinition *>(otherPt));
58 const SlicePartDefinition *other2(dynamic_cast<const SlicePartDefinition *>(otherPt));
61 throw INTERP_KERNEL::Exception("DataArrayPartDefinition::operator+ : unrecognized type in input !");
64 std::string DataArrayPartDefinition::getRepr() const
66 std::ostringstream oss; oss << "DataArray Part : ";
67 const DataArrayInt *arr(_arr);
69 arr->reprQuickOverview(oss);
75 DataArrayInt *DataArrayPartDefinition::toDAI() const
77 checkInternalArrayOK();
78 const DataArrayInt *arr(_arr);
79 DataArrayInt *arr2(const_cast<DataArrayInt *>(arr));
84 DataArrayPartDefinition::DataArrayPartDefinition(DataArrayInt *listOfIds)
86 CheckInternalArrayOK(listOfIds);
91 void DataArrayPartDefinition::checkInternalArrayOK() const
93 CheckInternalArrayOK(_arr);
96 void DataArrayPartDefinition::CheckInternalArrayOK(const DataArrayInt *listOfIds)
98 if(!listOfIds || !listOfIds->isAllocated() || listOfIds->getNumberOfComponents()!=1)
99 throw INTERP_KERNEL::Exception("DataArrayPartDefinition::CheckInternalArrayOK : Input list must be not null allocated and with one components !");
102 void DataArrayPartDefinition::updateTime() const
104 if((const DataArrayInt *)_arr)
105 updateTimeWith(*_arr);
108 std::size_t DataArrayPartDefinition::getHeapMemorySizeWithoutChildren() const
110 return sizeof(DataArrayPartDefinition);
113 std::vector<const BigMemoryObject *> DataArrayPartDefinition::getDirectChildrenWithNull() const
115 std::vector<const BigMemoryObject *> ret(1,(const DataArrayInt *)_arr);
119 DataArrayPartDefinition *DataArrayPartDefinition::add1(const DataArrayPartDefinition *other) const
121 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a1(toDAI()),a2(other->toDAI());
122 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a3(DataArrayInt::Aggregate(a1,a2,0));
124 return DataArrayPartDefinition::New(a3);
127 DataArrayPartDefinition *DataArrayPartDefinition::add2(const SlicePartDefinition *other) const
129 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a1(toDAI()),a2(other->toDAI());
130 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a3(DataArrayInt::Aggregate(a1,a2,0));
132 return DataArrayPartDefinition::New(a3);
135 DataArrayPartDefinition::~DataArrayPartDefinition()
139 SlicePartDefinition *SlicePartDefinition::New(int start, int stop, int step)
141 return new SlicePartDefinition(start,stop,step);
144 DataArrayInt *SlicePartDefinition::toDAI() const
146 return DataArrayInt::Range(_start,_stop,_step);
149 int SlicePartDefinition::getNumberOfElems() const
151 return DataArray::GetNumberOfItemGivenBES(_start,_stop,_step,"SlicePartDefinition::getNumberOfElems");
154 PartDefinition *SlicePartDefinition::operator+(const PartDefinition& other) const
156 const PartDefinition *otherPt(&other);
158 throw INTERP_KERNEL::Exception("DataArrayPartDefinition::operator+ : NULL input !");
159 const DataArrayPartDefinition *other1(dynamic_cast<const DataArrayPartDefinition *>(otherPt));
162 const SlicePartDefinition *other2(dynamic_cast<const SlicePartDefinition *>(otherPt));
165 throw INTERP_KERNEL::Exception("SlicePartDefinition::operator+ : unrecognized type in input !");
168 std::string SlicePartDefinition::getRepr() const
170 std::ostringstream oss;
171 oss << "Slice is defined with : start=" << _start << " stop=" << _stop << " step=" << _step;
175 int SlicePartDefinition::getEffectiveStop() const
177 int nbElems(DataArray::GetNumberOfItemGivenBES(_start,_stop,_step,"SlicePartDefinition::getEffectiveStop"));
178 return _start+nbElems*_step;
181 SlicePartDefinition::SlicePartDefinition(int start, int stop, int step):_start(start),_stop(stop),_step(step)
186 * No child ! It is the leaf ! So no implementation.
188 void SlicePartDefinition::updateTime() const
192 std::size_t SlicePartDefinition::getHeapMemorySizeWithoutChildren() const
194 return sizeof(SlicePartDefinition);
197 std::vector<const BigMemoryObject *> SlicePartDefinition::getDirectChildrenWithNull() const
199 return std::vector<const BigMemoryObject *>();
202 DataArrayPartDefinition *SlicePartDefinition::add1(const DataArrayPartDefinition *other) const
204 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a1(toDAI()),a2(other->toDAI());
205 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a3(DataArrayInt::Aggregate(a1,a2,0));
207 return DataArrayPartDefinition::New(a3);
210 PartDefinition *SlicePartDefinition::add2(const SlicePartDefinition *other) const
212 if(_step==other->_step && getEffectiveStop()==other->_start)
214 return SlicePartDefinition::New(_start,other->_stop,_step);
218 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a1(toDAI()),a2(other->toDAI());
219 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a3(DataArrayInt::Aggregate(a1,a2,0));
221 return DataArrayPartDefinition::New(a3);
225 SlicePartDefinition::~SlicePartDefinition()