#include "NormalizedUnstructuredMesh.hxx"
#include "InterpKernelException.hxx"
#include "InterpolationUtils.hxx"
+#include "MEDCouplingPartDefinition.hxx"
+#include "InterpKernelAutoPtr.hxx"
#include "MCAuto.hxx"
#include <sstream>
_nb_of_elem=std::max<std::size_t>(_nb_of_elem,id+sizeOfOthers+1);
}
- template<class T>
- template<class InputIterator>
- void MemArray<T>::insertAtTheEnd(InputIterator first, InputIterator last)
- {
- T *pointer=_pointer.getPointer();
- while(first!=last)
- {
- if(_nb_of_elem>=_nb_of_elem_alloc)
- {
- reserve(_nb_of_elem_alloc>0?2*_nb_of_elem_alloc:1);
- pointer=_pointer.getPointer();
- }
- pointer[_nb_of_elem++]=*first++;
- }
- }
-
template<class T>
void MemArray<T>::pushBack(T elem)
{
}
//////////////////////////////////
+
+ template<class T>
+ MCAuto< typename Traits<T>::ArrayTypeCh > DataArrayTemplate<T>::NewFromStdVector(const typename std::vector<T>& v)
+ {
+ std::size_t sz(v.size());
+ MCAuto< typename Traits<T>::ArrayTypeCh > ret(Traits<T>::ArrayTypeCh::New());
+ ret->alloc(sz,1);
+ T *pt(ret->getPointer());
+ std::copy(v.begin(),v.end(),pt);
+ return ret;
+ }
+
+ template<class T>
+ std::vector< MCAuto< typename Traits<T>::ArrayTypeCh > > DataArrayTemplate<T>::explodeComponents() const
+ {
+ checkAllocated();
+ std::size_t sz(getNumberOfComponents());
+ int nbTuples(getNumberOfTuples());
+ std::string name(getName());
+ std::vector<std::string> compNames(getInfoOnComponents());
+ std::vector< MCAuto< typename Traits<T>::ArrayTypeCh > > ret(sz);
+ const T *thisPt(begin());
+ for(std::size_t i=0;i<sz;i++)
+ {
+ MCAuto< typename Traits<T>::ArrayTypeCh > part(Traits<T>::ArrayTypeCh::New());
+ part->alloc(nbTuples,1);
+ part->setName(name);
+ part->setInfoOnComponent(0,compNames[i]);
+ T *otherPt(part->getPointer());
+ for(int j=0;j<nbTuples;j++)
+ otherPt[j]=thisPt[sz*j+i];
+ ret[i]=part;
+ }
+ return ret;
+ }
template<class T>
std::size_t DataArrayTemplate<T>::getHeapMemorySizeWithoutChildren() const
* \throw If \a nbOfTuple < 0 or \a nbOfCompo < 0.
*/
template<class T>
- void DataArrayTemplate<T>::alloc(int nbOfTuple, int nbOfCompo)
+ void DataArrayTemplate<T>::alloc(std::size_t nbOfTuple, std::size_t nbOfCompo)
{
- if(nbOfTuple<0 || nbOfCompo<0)
- {
- std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::alloc : request for negative length of data !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
_info_on_compo.resize(nbOfCompo);
- _mem.alloc(nbOfCompo*(std::size_t)nbOfTuple);
+ _mem.alloc(nbOfCompo*nbOfTuple);
declareAsNew();
}
* \throw If \a nbOfTuples is negative.
*/
template<class T>
- void DataArrayTemplate<T>::reAlloc(int nbOfTuples)
+ void DataArrayTemplate<T>::reAlloc(std::size_t nbOfTuples)
{
- if(nbOfTuples<0)
- {
- std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::reAlloc : input new number of tuples should be >=0 !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
checkAllocated();
- _mem.reAlloc(getNumberOfComponents()*(std::size_t)nbOfTuples);
+ _mem.reAlloc(getNumberOfComponents()*nbOfTuples);
declareAsNew();
}
{
return DataArrayTemplate<T>::mySelectByTupleId(di.begin(),di.end());
}
+
+ template<class T>
+ MCAuto<typename Traits<T>::ArrayTypeCh> DataArrayTemplate<T>::selectPartDef(const PartDefinition *pd) const
+ {
+ if(!pd)
+ throw INTERP_KERNEL::Exception("DataArrayTemplate<T>::selectPartDef : null input pointer !");
+ MCAuto<typename Traits<T>::ArrayTypeCh> ret(Traits<T>::ArrayTypeCh::New());
+ const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
+ if(spd)
+ {
+ int a,b,c;
+ spd->getSlice(a,b,c);
+ if(a==0 && b==getNumberOfTuples() && c==1)
+ {
+ DataArrayTemplate<T> *directRet(const_cast<DataArrayTemplate<T> *>(this));
+ directRet->incrRef();
+ MCAuto<DataArrayTemplate<T> > ret(directRet);
+ return DynamicCastSafe<DataArrayTemplate<T>,typename Traits<T>::ArrayTypeCh>(ret);
+ }
+ else
+ {
+ MCAuto<DataArray> ret(selectByTupleIdSafeSlice(a,b,c));
+ return DynamicCastSafe<DataArray,typename Traits<T>::ArrayTypeCh>(ret);
+ }
+ }
+ const DataArrayPartDefinition *dpd(dynamic_cast<const DataArrayPartDefinition *>(pd));
+ if(dpd)
+ {
+ MCAuto<DataArrayInt> arr(dpd->toDAI());
+ MCAuto<DataArray> ret(selectByTupleIdSafe(arr->begin(),arr->end()));
+ return DynamicCastSafe<DataArray,typename Traits<T>::ArrayTypeCh>(ret);
+
+ }
+ throw INTERP_KERNEL::Exception("DataArrayTemplate<T>::selectPartDef : unrecognized part def !");
+ }
/*!
* Returns a shorten and permuted copy of \a this array. The new DataArrayDouble is
return *loc;
}
+ template<class T>
+ void DataArrayTemplate<T>::circularPermutation(int nbOfShift)
+ {
+ checkAllocated();
+ int nbOfCompo(getNumberOfComponents()),nbTuples(getNumberOfTuples());
+ int effNbSh(EffectiveCircPerm(nbOfShift,nbTuples));
+ if(effNbSh==0)
+ return ;
+ T *work(getPointer());
+ if(effNbSh<nbTuples-effNbSh)
+ {
+ typename INTERP_KERNEL::AutoPtr<T> buf(new T[effNbSh*nbOfCompo]);
+ std::copy(work,work+effNbSh*nbOfCompo,(T *)buf);
+ std::copy(work+effNbSh*nbOfCompo,work+nbTuples*nbOfCompo,work);// ze big shift
+ std::copy((T *)buf,(T *)buf+effNbSh*nbOfCompo,work+(nbTuples-effNbSh)*nbOfCompo);
+ }
+ else
+ {
+ typename INTERP_KERNEL::AutoPtr<T> buf(new T[(nbTuples-effNbSh)*nbOfCompo]);
+ std::copy(work+effNbSh*nbOfCompo,work+nbTuples*nbOfCompo,(T *)buf);
+ std::copy(work,work+effNbSh*nbOfCompo,work+(nbTuples-effNbSh)*nbOfCompo);// ze big shift
+ std::copy((T*)buf,(T *)buf+(nbTuples-effNbSh)*nbOfCompo,work);
+ }
+ }
+
+ template<class T>
+ void DataArrayTemplate<T>::circularPermutationPerTuple(int nbOfShift)
+ {
+ checkAllocated();
+ int nbOfCompo(getNumberOfComponents()),nbTuples(getNumberOfTuples());
+ int effNbSh(EffectiveCircPerm(nbOfShift,nbOfCompo));
+ if(effNbSh==0)
+ return ;
+ T *work(getPointer());
+ if(effNbSh<nbOfCompo-effNbSh)
+ {
+ typename INTERP_KERNEL::AutoPtr<T> buf(new T[effNbSh]);
+ for(int i=0;i<nbTuples;i++,work+=nbOfCompo)
+ {
+ std::copy(work,work+effNbSh,(T *)buf);
+ std::copy(work+effNbSh,work+nbOfCompo,work);// ze big shift
+ std::copy((T *)buf,(T *)buf+effNbSh,work+(nbOfCompo-effNbSh));
+ }
+ }
+ else
+ {
+ typename INTERP_KERNEL::AutoPtr<T> buf(new T[nbOfCompo-effNbSh]);
+ for(int i=0;i<nbTuples;i++,work+=nbOfCompo)
+ {
+ std::copy(work+effNbSh,work+nbOfCompo,(T *)buf);
+ std::copy(work,work+effNbSh,work+(nbOfCompo-effNbSh));// ze big shift
+ std::copy((T*)buf,(T *)buf+(nbOfCompo-effNbSh),work);
+ }
+ }
+ std::vector<std::string> sts(nbOfCompo);
+ for(int i=0;i<nbOfCompo;i++)
+ sts[i]=_info_on_compo[(i+effNbSh)%nbOfCompo];
+ setInfoOnComponents(sts);
+ }
+
+ template<class T>
+ void DataArrayTemplate<T>::reversePerTuple()
+ {
+ checkAllocated();
+ int nbOfCompo(getNumberOfComponents()),nbTuples(getNumberOfTuples());
+ if(nbOfCompo<=1)
+ return ;
+ T *work(getPointer());
+ for(int i=0;i<nbTuples;i++,work+=nbOfCompo)
+ std::reverse(work,work+nbOfCompo);
+ std::reverse(_info_on_compo.begin(),_info_on_compo.end());
+ }
}
#endif