18 #ifndef itkVariableLengthVector_h
19 #define itkVariableLengthVector_h
35 template <
typename TExpr1,
typename TExpr2,
typename TBinaryOp>
92 template<
typename TValue >
129 bool operator()(
unsigned int itkNotUsed(newSize),
unsigned int itkNotUsed(oldSize)) const ITK_NOEXCEPT
156 bool operator()(
unsigned int newSize,
unsigned int oldSize)
const ITK_NOEXCEPT
160 itkAssertInDebugAndIgnoreInReleaseMacro(newSize == oldSize &&
"SetSize is expected to never change the VariableLengthVector size...");
185 bool operator()(
unsigned int newSize,
unsigned int oldSize)
const ITK_NOEXCEPT
186 {
return newSize != oldSize; }
218 bool operator()(
unsigned int newSize,
unsigned int oldSize)
const ITK_NOEXCEPT
219 {
return newSize > oldSize; }
266 template <
typename TValue2>
268 unsigned int newSize,
unsigned int oldSize,
269 TValue2 * oldBuffer, TValue2 * newBuffer)
const ITK_NOEXCEPT
271 itkAssertInDebugAndIgnoreInReleaseMacro(newBuffer);
272 const std::size_t nb = std::min(newSize, oldSize);
273 itkAssertInDebugAndIgnoreInReleaseMacro(nb == 0 || (nb > 0 && oldBuffer != ITK_NULLPTR));
274 std::copy(oldBuffer, oldBuffer+nb, newBuffer);
297 template <
typename TValue2>
299 unsigned int itkNotUsed(newSize),
unsigned int itkNotUsed(oldSize),
300 TValue2 * itkNotUsed(oldBuffer), TValue2 * itkNotUsed(newBuffer)) const ITK_NOEXCEPT
349 bool LetArrayManageMemory =
false);
371 bool LetArrayManageMemory =
false);
392 template<
typename T >
400 itkAssertInDebugAndIgnoreInReleaseMacro(
m_Data != ITK_NULLPTR);
440 #if defined(ITK_HAS_CXX11_RVREF)
458 Self & operator=(
Self && v) ITK_NOEXCEPT;
477 template <
typename TExpr1,
typename TExpr2,
typename TBinaryOp>
499 template <
typename TExpr1,
typename TExpr2,
typename TBinaryOp>
505 void Fill(TValue
const & v) ITK_NOEXCEPT;
519 template<
typename T >
626 template <
typename TReallocatePolicy,
typename TKeepValuesPolicy>
628 TReallocatePolicy reallocatePolicy,
629 TKeepValuesPolicy keepValues);
641 void SetSize(
unsigned int sz,
bool destroyExistingData =
true)
646 if (destroyExistingData)
673 void SetData(TValue *data,
bool LetArrayManageMemory = false) ITK_NOEXCEPT;
689 void SetData(TValue *data,
unsigned int sz,
bool LetArrayManageMemory = false) ITK_NOEXCEPT;
780 template<
typename T >
784 itkAssertInDebugAndIgnoreInReleaseMacro(
m_NumElements == v.GetSize() );
812 template<
typename T >
816 itkAssertInDebugAndIgnoreInReleaseMacro(
m_NumElements == v.GetSize() );
845 template <
typename TExpr1,
typename TExpr2,
typename TBinaryOp>
848 itkAssertInDebugAndIgnoreInReleaseMacro(rhs.Size() ==
Size());
866 template <
typename TExpr1,
typename TExpr2,
typename TBinaryOp>
869 itkAssertInDebugAndIgnoreInReleaseMacro(rhs.Size() ==
Size());
883 template<
typename T >
914 template<
typename T >
934 bool operator==(const
Self & v) const ITK_NOEXCEPT;
936 bool operator!=(const
Self & v) const ITK_NOEXCEPT;
965 template <
typename T>
966 struct IsArray : FalseType {};
969 template <
typename T>
970 struct IsArray<itk::VariableLengthVector<T> > : TrueType {};
972 template <
typename TExpr1,
typename TExpr2,
typename TBinaryOp>
993 template <
typename TExpr>
struct GetType
1000 static Type Load(Type
const& v,
unsigned int idx) ITK_NOEXCEPT
1001 { (void)idx;
return v; }
1015 template <
typename TExpr1,
typename TExpr2>
1017 typename mpl::EnableIf<mpl::And<mpl::IsArray<TExpr1>, mpl::IsArray<TExpr2> >,
unsigned int>::Type
1018 GetSize(TExpr1
const& lhs, TExpr2
const& rhs) ITK_NOEXCEPT
1021 itkAssertInDebugAndIgnoreInReleaseMacro(lhs.Size() == rhs.Size());
1036 template <
typename TExpr1,
typename TExpr2>
1038 typename mpl::EnableIf<mpl::And<mpl::IsArray<TExpr1>, mpl::Not<mpl::IsArray<TExpr2> > >,
unsigned int>::Type
1039 GetSize(TExpr1
const& lhs, TExpr2
const& itkNotUsed(rhs)) ITK_NOEXCEPT
1053 template <
typename TExpr1,
typename TExpr2>
1055 typename mpl::EnableIf<mpl::And<mpl::IsArray<TExpr2>, mpl::Not<mpl::IsArray<TExpr1> > >,
unsigned int>::Type
1056 GetSize(TExpr1
const& itkNotUsed(lhs), TExpr2
const& rhs) ITK_NOEXCEPT
1061 template <
typename T>
1062 struct GetType<VariableLengthVector<T> >
1065 static Type Load(VariableLengthVector<T>
const& v,
unsigned int idx) ITK_NOEXCEPT
1068 template <
typename TExpr1,
typename TExpr2,
typename TBinaryOp>
1069 struct GetType<VariableLengthVectorExpression<TExpr1, TExpr2, TBinaryOp> >
1091 template <
typename TExpr1,
typename TExpr2>
1093 : mpl::Or< mpl::And<mpl::IsArray<TExpr1>, mpl::IsArray<TExpr2> >,
1094 mpl::And<mpl::IsArray<TExpr1>, mpl::IsNumber<TExpr2> >,
1095 mpl::And<mpl::IsNumber<TExpr1>, mpl::IsArray<TExpr2> >
1110 template <
typename TExpr1,
typename TExpr2>
1112 : mpl::Or< mpl::And<mpl::IsArray<TExpr1>, mpl::IsNumber<TExpr2> >,
1113 mpl::And<mpl::IsNumber<TExpr1>, mpl::IsArray<TExpr2> >
1128 template <
typename TExpr1,
typename TExpr2>
1130 : mpl::And<mpl::IsArray<TExpr1>, mpl::IsNumber<TExpr2> >
1161 template <
typename TExpr1,
typename TExpr2,
typename TBinaryOp>
1165 : m_lhs(lhs), m_rhs(rhs)
1170 (itk::mpl::IsBaseOf<Details::op::BinaryOperationConcept, TBinaryOp>::Value),
1171 "The Binary Operation shall inherit from BinaryOperationConcept");
1175 unsigned int Size() const ITK_NOEXCEPT{
return Details::GetSize(m_lhs, m_rhs); }
1178 typedef typename mpl::PromoteType<
1179 typename Details::GetType<TExpr1>::Type,
1180 typename Details::GetType<TExpr2>::Type>::Type
ResType;
1196 itkAssertInDebugAndIgnoreInReleaseMacro(idx < Size());
1197 return TBinaryOp::Apply(
1198 Details::GetType<TExpr1>::Load(m_lhs, idx),
1199 Details::GetType<TExpr2>::Load(m_rhs, idx));
1204 RealValueType
GetNorm() const ITK_NOEXCEPT;
1210 TExpr1 const& m_lhs;
1211 TExpr2 const& m_rhs;
1223 template <typename TExpr1, typename TExpr2>
1225 typename mpl::EnableIf<Details::op::CanBeAddedOrSubstracted<TExpr1,TExpr2>,
VariableLengthVectorExpression<TExpr1, TExpr2, Details::op::Plus> >::Type
1226 operator+(TExpr1 const& lhs, TExpr2 const& rhs) ITK_NOEXCEPT
1238 template <
typename TExpr1,
typename TExpr2>
1241 operator-(TExpr1
const& lhs, TExpr2
const& rhs) ITK_NOEXCEPT
1252 template <
typename TExpr1,
typename TExpr2>
1255 operator*(TExpr1
const& lhs, TExpr2
const& rhs) ITK_NOEXCEPT
1265 template <
typename TExpr1,
typename TExpr2>
1268 operator/(TExpr1
const& lhs, TExpr2
const& rhs) ITK_NOEXCEPT
1274 template <
typename TExpr1,
typename TExpr2,
typename TBinaryOp>
1275 std::ostream & operator<<(std::ostream &os, VariableLengthVectorExpression<TExpr1, TExpr2, TBinaryOp>
const& v)
1281 for (
unsigned int i = 1, N = v.Size(); i != N; ++i)
1295 template <
typename TExpr>
1297 typename mpl::EnableIf<mpl::IsArray<TExpr>,
typename TExpr::RealValueType>::Type
1300 return static_cast<typename TExpr::RealValueType
>(
1309 template <
typename TExpr>
1311 typename mpl::EnableIf<mpl::IsArray<TExpr>,
typename TExpr::RealValueType>::Type
1314 typedef typename TExpr::RealValueType RealValueType;
1315 RealValueType sum = 0.0;
1316 for (
unsigned int i = 0, N=v.Size(); i < N; ++i )
1318 const RealValueType value = v[i];
1319 sum += value * value;
1331 template<
typename TValue >
1332 std::ostream & operator<<(std::ostream & os, const VariableLengthVector< TValue > & arr)
1334 const unsigned int length = arr.Size();
1335 const signed int last = (
unsigned int)length - 1;
1339 for (
signed int i = 0; i < last; ++i )
1341 os << arr[i] <<
", ";
1372 template <
typename T>
1385 #ifndef ITK_MANUAL_INSTANTIATION
1386 #include "itkVariableLengthVector.hxx"
Self & operator/=(T s) noexcept
void swap(VariableLengthVector< T > &l_, VariableLengthVector< T > &r_) noexcept
RealValueType GetNorm() const noexcept
mpl::EnableIf< mpl::IsArray< TExpr >, typename TExpr::RealValueType >::Type GetNorm(TExpr const &v) noexcept
void SetElement(unsigned int i, const TValue &value) noexcept
void operator()(unsigned int, unsigned int, TValue2 *, TValue2 *) const noexcept
void operator()(unsigned int newSize, unsigned int oldSize, TValue2 *oldBuffer, TValue2 *newBuffer) const noexcept
Self & operator++() noexcept
bool operator()(unsigned int newSize, unsigned int oldSize) const noexcept
bool operator()(unsigned int newSize, unsigned int oldSize) const noexcept
mpl::EnableIf< mpl::IsArray< TExpr >, typename TExpr::RealValueType >::Type GetSquaredNorm(TExpr const &v) noexcept
Self & operator+=(TValue s) noexcept
VariableLengthVector(const VariableLengthVector< T > &v)
Self & operator+=(VariableLengthVectorExpression< TExpr1, TExpr2, TBinaryOp > const &rhs) noexcept
const TValue & GetElement(unsigned int i) const noexcept
void Reserve(ElementIdentifier size)
ResType operator[](unsigned int idx) const noexcept
mpl::EnableIf< Details::op::CanBeDivided< TExpr1, TExpr2 >, VariableLengthVectorExpression< TExpr1, TExpr2, Details::op::Div > >::Type operator/(TExpr1 const &lhs, TExpr2 const &rhs) noexcept
unsigned int Size(void) const noexcept
unsigned int Size() const noexcept
Returns the size of the vector expression.
void swap(Array< T > &a, Array< T > &b)
void Fill(TValue const &v) noexcept
Represents an array whose length can be defined at run-time.
Self & FastAssign(const Self &v) noexcept
mpl::EnableIf< Details::op::CanBeAddedOrSubstracted< TExpr1, TExpr2 >, VariableLengthVectorExpression< TExpr1, TExpr2, Details::op::Sub > >::Type operator-(TExpr1 const &lhs, TExpr2 const &rhs) noexcept
TValue & operator[](unsigned int i) noexcept
TValue * AllocateElements(ElementIdentifier size) const
VariableLengthVector Self
bool IsAProxy() const noexcept
ElementIdentifier m_NumElements
void DestroyExistingData() noexcept
const TValue * GetDataPointer() const noexcept
void Swap(Self &v) noexcept
Self & operator=(VariableLengthVectorExpression< TExpr1, TExpr2, TBinaryOp > const &rhs)
TValue const & operator[](unsigned int i) const noexcept
Self & operator=(const VariableLengthVector< T > &v)
Self & operator-=(TValue s) noexcept
NumericTraits< ResType >::RealType RealValueType
Real type of the elements.
unsigned int GetNumberOfElements(void) const noexcept
bool m_LetArrayManageMemory
void SetSize(unsigned int sz, bool destroyExistingData=true)
bool operator()(unsigned int newSize, unsigned int oldSize) const noexcept
RealValueType GetSquaredNorm() const noexcept
void SetData(TValue *data, bool LetArrayManageMemory=false) noexcept
Self & operator-() noexcept
VariableLengthVectorExpression(TExpr1 const &lhs, TExpr2 const &rhs) noexcept
mpl::EnableIf< Details::op::CanBeMultiplied< TExpr1, TExpr2 >, VariableLengthVectorExpression< TExpr1, TExpr2, Details::op::Mult > >::Type operator*(TExpr1 const &lhs, TExpr2 const &rhs) noexcept
NumericTraits< ValueType >::RealType RealValueType
unsigned int GetSize(void) const noexcept
#define itkStaticAssert(expr, str)
Self & operator-=(VariableLengthVectorExpression< TExpr1, TExpr2, TBinaryOp > const &rhs) noexcept
Self & operator--() noexcept
void SetSize(unsigned int sz, TReallocatePolicy reallocatePolicy, TKeepValuesPolicy keepValues)
bool operator()(unsigned int, unsigned int) const noexcept
Self & operator*=(T s) noexcept
mpl::PromoteType< typename Details::GetType< TExpr1 >::Type, typename Details::GetType< TExpr2 >::Type >::Type ResType
Vector type of the Result Expression.
Self & operator*=(TValue s) noexcept
unsigned int ElementIdentifier