Commit 97b716c5 authored by Reza  ANSARI's avatar Reza ANSARI
Browse files

Amelioration de la classe Range (ajout du constructeur de copie, operateur de...

Amelioration de la classe Range (ajout du constructeur de copie, operateur de copie et test d'egalite, en vue de faciliter l'implementation de la lecture partielle de tableaux avec HDF5, Reza
parent 2160a418
......@@ -426,15 +426,27 @@ Range::Range(sa_size_t start, sa_size_t end, sa_size_t size, sa_size_t step)
}
}
/*
Range::Range(Range const& a)
/* --Methode-- */
Range::Range(Range const & a)
: start_(a.start_), end_(a.end_), size_(a.size_), step_(a.step_)
{
start_ = a.start_;
end_ = a.end_;
size_ = a.size_;
step_ = a.step_;
}
*/
/* --Methode-- */
Range& Range::operator = (Range const & a)
{
start_=a.start_; end_=a.end_;
size_=a.size_; step_=a.step_;
return *this;
}
/* --Methode-- */
bool Range::IsEqual(Range const & a) const
{
if ((start_!=a.start_)||(end_!=a.end_)||(size_!=a.size_)||(step_!=a.step_)) return false;
return true;
}
/*!
This method is called to recompute index ranges, specifying the original array size
......@@ -492,5 +504,7 @@ IdentityMatrix::IdentityMatrix(double diag, sa_size_t n)
diag_ = diag;
}
} // FIN namespace SOPHYA
......@@ -144,14 +144,28 @@ public:
Range(sa_size_t start, sa_size_t end, sa_size_t step);
//! General Index range specification, using size or start/end and increment
Range(sa_size_t start, sa_size_t end, sa_size_t size, sa_size_t step);
//! Return the start index
//! copy constructor
Range(Range const & a);
//! copy (equal) operator
Range& operator = (Range const & a);
//! equality between two Range object - return true if equal
bool IsEqual(Range const & a) const;
//! Return a reference to the start index
inline sa_size_t & Start() { return start_; }
//! Return the last index
//! Return a reference to the last index
inline sa_size_t & End() { return end_; }
//! Return the size
//! Return a reference to the size
inline sa_size_t & Size() { return size_; }
//! Return the step
//! Return a reference to the step
inline sa_size_t & Step() { return step_; }
//! Return the start index (const version)
inline sa_size_t Start() const { return start_; }
//! Return the last index (const version)
inline sa_size_t End() const { return end_; }
//! Return the size (const version)
inline sa_size_t Size() const { return size_; }
//! Return the step (const version)
inline sa_size_t Step() const { return step_; }
//! return a constant value defining the first element
inline static sa_size_t firstIndex() { return 0; }
//! return a constant value as a placeholder for the last valid index
......@@ -176,6 +190,14 @@ protected:
sa_size_t step_; //!< step
};
//! \brief equality comparison operator between two ranges
inline bool operator == (Range const& a1, Range const& a2)
{ return a1.IsEqual(a2); }
//! \brief equality comparison operator between two ranges
inline bool operator != (Range const& a1, Range const& a2)
{ return !(a1.IsEqual(a2)); }
//////////////////////////////////////////////////////////
//! Class to define an identity matrix
class IdentityMatrix {
......@@ -190,6 +212,83 @@ protected:
double diag_; //!< value of the diagonal elements
};
/*!
\class SOPHYA::Range_Array_Grp
\ingroup TArray
\brief A utiliy class to gather an array and set of Range specification
This class is a utility object returned by SOPHYA::RangeArrayGroup() functions,
and specify the portion of a multi-dimensional data set.
*/
template <class T> class TArray;
template <class T>
class Range_Array_Grp {
public:
explicit Range_Array_Grp() : arrp_(nullptr) { }
explicit Range_Array_Grp(TArray<T> & arr) : arrp_(&arr) { }
TArray<T> * arrp_;
std::vector<Range> vr_;
};
/*!
\fn SOPHYA::RangeArrayGroup
\ingroup TArray
\brief A utiliy function to ease creation of Range_Array_Grp from Ranges and an array
Note that the optional flag \b fgrevdim, reverses the order of Ranges put in the corresponding
vector in Range_Array_Grp<T> if put to true.
The default order (fgrevdim=false) correspond to the SOPHYA::TArray<T> convention. The first element
in the vector correspond to SizeX/OffsetX.
*/
//! Creates a Range_Array_Grp<T> corresponding to a one-dimensional array
template <class T>
inline Range_Array_Grp<T> RangeArrayGroup(Range const & r1, TArray<T> & arr)
{
Range_Array_Grp<T> sa(arr); sa.vr_.push_back(r1); return sa;
}
//! Creates a Range_Array_Grp<T> corresponding to a two-dimensional array
template <class T>
inline Range_Array_Grp<T> RangeArrayGroup(Range const & r1, Range const & r2, TArray<T> & arr, bool fgrevdim=false)
{
Range_Array_Grp<T> sa(arr);
if (fgrevdim) { sa.vr_.push_back(r1); sa.vr_.push_back(r2); }
else { sa.vr_.push_back(r2); sa.vr_.push_back(r1); }
return sa;
}
//! Creates a Range_Array_Grp<T> corresponding to a three-dimensional array
template <class T>
inline Range_Array_Grp<T> RangeArrayGroup(Range const & r1, Range const & r2, Range const & r3,
TArray<T> & arr, bool fgrevdim=false)
{
Range_Array_Grp<T> sa(arr);
if (fgrevdim) { sa.vr_.push_back(r1); sa.vr_.push_back(r2); sa.vr_.push_back(r3); }
else { sa.vr_.push_back(r3); sa.vr_.push_back(r2); sa.vr_.push_back(r1); }
return sa;
}
//! Creates a Range_Array_Grp<T> corresponding to a four-dimensional array
template <class T>
inline Range_Array_Grp<T> RangeArrayGroup(Range const & r1, Range const & r2, Range const & r3, Range const & r4,
TArray<T> & arr, bool fgrevdim=false)
{
Range_Array_Grp<T> sa(arr);
if (fgrevdim) { sa.vr_.push_back(r1); sa.vr_.push_back(r2); sa.vr_.push_back(r3); sa.vr_.push_back(r4); }
else { sa.vr_.push_back(r4); sa.vr_.push_back(r3); sa.vr_.push_back(r2); sa.vr_.push_back(r1); }
return sa;
}
//! Creates a Range_Array_Grp<T> corresponding to a five-dimensional array
template <class T>
inline Range_Array_Grp<T> RangeArrayGroup(Range const & r1, Range const & r2, Range const & r3, Range const & r4,
Range const & r5, TArray<T> & arr, bool fgrevdim=false)
{
Range_Array_Grp<T> sa(arr);
if (fgrevdim) { sa.vr_.push_back(r1); sa.vr_.push_back(r2); sa.vr_.push_back(r3); sa.vr_.push_back(r4); sa.vr_.push_back(r5); }
else { sa.vr_.push_back(r5); sa.vr_.push_back(r4); sa.vr_.push_back(r3); sa.vr_.push_back(r2); sa.vr_.push_back(r1); }
return sa;
}
} // Fin du namespace
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment