bool DataArray::areInfoEqualsIfNotWhy(const DataArray& other, std::string& reason) const
{
std::ostringstream oss;
- if(_nb_of_tuples!=other._nb_of_tuples)
- {
- oss << "Number of tuples of DataArray mismatch : this number of tuples=" << _nb_of_tuples << " other number of tuples=" << other._nb_of_tuples;
- reason=oss.str();
- return false;
- }
if(_name!=other._name)
{
oss << "Names DataArray mismatch : this name=\"" << _name << " other name=\"" << other._name << "\" !";
else if(nbCompo==0)
{
_mem.reserve(nbOfElems);
- if(_nb_of_tuples==-1)
- _nb_of_tuples=0;
- else
- _nb_of_tuples=std::min<int>(_nb_of_tuples,nbOfElems);
_info_on_compo.resize(1);
}
else
void DataArrayDouble::pushBackSilent(double val) throw(INTERP_KERNEL::Exception)
{
if(getNumberOfComponents()==1)
- {
- _mem.pushBack(val);
- _nb_of_tuples++;
- }
+ _mem.pushBack(val);
else
throw INTERP_KERNEL::Exception("DataArrayDouble::pushBackSilent : not available for DataArrayDouble with number of components different than 1 !");
}
double DataArrayDouble::popBackSilent() throw(INTERP_KERNEL::Exception)
{
if(getNumberOfComponents()==1)
- {
- double ret=_mem.popBack();
- _nb_of_tuples--;
- return ret;
- }
+ return _mem.popBack();
else
throw INTERP_KERNEL::Exception("DataArrayDouble::pushBackSilent : not available for DataArrayDouble with number of components different than 1 !");
}
{
if(nbOfTuple<0 || nbOfCompo<0)
throw INTERP_KERNEL::Exception("DataArrayDouble::alloc : request for negative length of data !");
- _nb_of_tuples=nbOfTuple;
_info_on_compo.resize(nbOfCompo);
- _mem.alloc(nbOfCompo*_nb_of_tuples);
+ _mem.alloc(nbOfCompo*nbOfTuple);
declareAsNew();
}
void DataArrayDouble::reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception)
{
checkAllocated();
- _mem.reAlloc((int)(_info_on_compo.size())*nbOfTuples);
- _nb_of_tuples=nbOfTuples;
+ _mem.reAlloc(getNumberOfComponents()*nbOfTuples);
declareAsNew();
}
int nbOfElems=getNbOfElems();
if(nbOfElems%newNbOfCompo!=0)
throw INTERP_KERNEL::Exception("DataArrayDouble::rearrange : nbOfElems%newNbOfCompo!=0 !");
- _nb_of_tuples=nbOfElems/newNbOfCompo;
_info_on_compo.clear();
_info_on_compo.resize(newNbOfCompo);
declareAsNew();
void DataArrayDouble::useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo)
{
- _nb_of_tuples=nbOfTuple;
_info_on_compo.resize(nbOfCompo);
_mem.useArray(array,ownership,type,nbOfTuple*nbOfCompo);
declareAsNew();
void DataArrayDouble::useExternalArrayWithRWAccess(const double *array, int nbOfTuple, int nbOfCompo)
{
- _nb_of_tuples=nbOfTuple;
_info_on_compo.resize(nbOfCompo);
_mem.useExternalArrayWithRWAccess(array,nbOfTuple*nbOfCompo);
declareAsNew();
else if(nbCompo==0)
{
_mem.reserve(nbOfElems);
- if(_nb_of_tuples==-1)
- _nb_of_tuples=0;
- else
- _nb_of_tuples=std::min<int>(_nb_of_tuples,nbOfElems);
_info_on_compo.resize(1);
}
else
void DataArrayInt::pushBackSilent(int val) throw(INTERP_KERNEL::Exception)
{
if(getNumberOfComponents()==1)
- {
- _mem.pushBack(val);
- _nb_of_tuples++;
- }
+ _mem.pushBack(val);
else
throw INTERP_KERNEL::Exception("DataArrayInt::pushBackSilent : not available for DataArrayInt with number of components different than 1 !");
}
int DataArrayInt::popBackSilent() throw(INTERP_KERNEL::Exception)
{
if(getNumberOfComponents()==1)
- {
- int ret=_mem.popBack();
- _nb_of_tuples--;
- return ret;
- }
+ return _mem.popBack();
else
throw INTERP_KERNEL::Exception("DataArrayInt::pushBackSilent : not available for DataArrayInt with number of components different than 1 !");
}
{
if(nbOfTuple<0 || nbOfCompo<0)
throw INTERP_KERNEL::Exception("DataArrayInt::alloc : request for negative length of data !");
- _nb_of_tuples=nbOfTuple;
_info_on_compo.resize(nbOfCompo);
- _mem.alloc(nbOfCompo*_nb_of_tuples);
+ _mem.alloc(nbOfCompo*nbOfTuple);
declareAsNew();
}
void DataArrayInt::useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo)
{
- _nb_of_tuples=nbOfTuple;
_info_on_compo.resize(nbOfCompo);
_mem.useArray(array,ownership,type,nbOfTuple*nbOfCompo);
declareAsNew();
void DataArrayInt::useExternalArrayWithRWAccess(const int *array, int nbOfTuple, int nbOfCompo)
{
- _nb_of_tuples=nbOfTuple;
_info_on_compo.resize(nbOfCompo);
_mem.useExternalArrayWithRWAccess(array,nbOfTuple*nbOfCompo);
declareAsNew();
int nbOfElems=getNbOfElems();
if(nbOfElems%newNbOfCompo!=0)
throw INTERP_KERNEL::Exception("DataArrayInt::rearrange : nbOfElems%newNbOfCompo!=0 !");
- _nb_of_tuples=nbOfElems/newNbOfCompo;
_info_on_compo.clear();
_info_on_compo.resize(newNbOfCompo);
declareAsNew();
void DataArrayInt::reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception)
{
checkAllocated();
- _mem.reAlloc((int)_info_on_compo.size()*nbOfTuples);
- _nb_of_tuples=nbOfTuples;
+ _mem.reAlloc(getNumberOfComponents()*nbOfTuples);
declareAsNew();
}
MEDCOUPLING_EXPORT std::string getUnitOnComponent(int i) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT int getNumberOfComponents() const { return (int)_info_on_compo.size(); }
- MEDCOUPLING_EXPORT int getNumberOfTuples() const { return _nb_of_tuples; }
- MEDCOUPLING_EXPORT int getNbOfElems() const { return ((int)_info_on_compo.size())*_nb_of_tuples; }
+ MEDCOUPLING_EXPORT virtual int getNumberOfTuples() const = 0;
+ MEDCOUPLING_EXPORT int getNbOfElems() const { return ((int)_info_on_compo.size())*getNumberOfTuples(); }
MEDCOUPLING_EXPORT void checkNbOfTuples(int nbOfTuples, const char *msg) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void checkNbOfComps(int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void checkNbOfTuplesAndComp(const DataArray& other, const char *msg) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT static std::string GetUnitFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT virtual void reprCppStream(const char *varName, std::ostream& stream) const = 0;
protected:
- DataArray():_nb_of_tuples(-1) { }
+ DataArray() { }
protected:
static void CheckValueInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception);
static void CheckValueInRangeEx(int value, int start, int end, const char *msg) throw(INTERP_KERNEL::Exception);
static void CheckClosingParInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception);
protected:
- int _nb_of_tuples;
std::string _name;
std::vector<std::string> _info_on_compo;
};
MEDCOUPLING_EXPORT static DataArrayDouble *New();
MEDCOUPLING_EXPORT bool isAllocated() const;
MEDCOUPLING_EXPORT void checkAllocated() const throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT int getNumberOfTuples() const { return _info_on_compo.empty()?0:_mem.getNbOfElem()/getNumberOfComponents(); }
MEDCOUPLING_EXPORT void setInfoAndChangeNbOfCompo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT double doubleValue() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT bool empty() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT static DataArrayInt *New();
MEDCOUPLING_EXPORT bool isAllocated() const;
MEDCOUPLING_EXPORT void checkAllocated() const throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT int getNumberOfTuples() const { return _info_on_compo.empty()?0:_mem.getNbOfElem()/getNumberOfComponents(); }
MEDCOUPLING_EXPORT void setInfoAndChangeNbOfCompo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT int intValue() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT int getHashCode() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT std::vector<DataArrayInt *> partitionByDifferentValues(std::vector<int>& differentIds) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo);
MEDCOUPLING_EXPORT void useExternalArrayWithRWAccess(const int *array, int nbOfTuple, int nbOfCompo);
- MEDCOUPLING_EXPORT void writeOnPlace(int id, int element0, const int *others, int sizeOfOthers) { _nb_of_tuples=std::max<int>(_nb_of_tuples,id+sizeOfOthers+1); _mem.writeOnPlace(id,element0,others,sizeOfOthers); }
+ MEDCOUPLING_EXPORT void writeOnPlace(int id, int element0, const int *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); }
MEDCOUPLING_EXPORT static DataArrayInt *Add(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void addEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT static DataArrayInt *Substract(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception);