📄 fixed_array.hpp
字号:
* \ingroup group__library__containers
*
* \param T The value type
* \param A The allocator type
* \param P The construction policy type
*/
template< ss_typename_param_k T
#ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
, ss_typename_param_k A = ss_typename_type_def_k allocator_selector<T>::allocator_type
, ss_typename_param_k P = do_construction<T>
, ss_bool_t R = true
#else /* ? STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
, ss_typename_param_k A
, ss_typename_param_k P
, ss_bool_t R
#endif /* STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
>
// class fixed_array_4d
class fixed_array_4d
: protected A
, public stl_collection_tag
{
public:
typedef fixed_array_4d<T, A, P, R> class_type;
typedef fixed_array_3d<T, A, P, false> dimension_element_type;
typedef A allocator_type;
typedef T value_type;
typedef value_type &reference;
typedef value_type const &const_reference;
typedef value_type *pointer;
typedef value_type const *const_pointer;
typedef ss_size_t size_type;
typedef ss_size_t index_type;
typedef ss_ptrdiff_t difference_type;
typedef
#if !defined(STLSOFT_COMPILER_IS_BORLAND)
ss_typename_type_k
#endif /* compiler */
pointer_iterator < value_type
, pointer
, reference
>::type iterator;
typedef
#if !defined(STLSOFT_COMPILER_IS_BORLAND)
ss_typename_type_k
#endif /* compiler */
pointer_iterator < value_type const
, const_pointer
, const_reference
>::type const_iterator;
#if defined(STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT)
typedef reverse_iterator_base < iterator
, value_type
, reference
, pointer
, difference_type
> reverse_iterator;
typedef const_reverse_iterator_base < const_iterator
, value_type const
, const_reference
, const_pointer
, difference_type
> const_reverse_iterator;
#endif /* STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT */
// Construction
private:
fixed_array_4d(T *data, index_type d0, index_type d1, index_type d2, index_type d3);
public:
fixed_array_4d(index_type d0, index_type d1, index_type d2, index_type d3);
fixed_array_4d(index_type d0, index_type d1, index_type d2, index_type d3, value_type const& t);
fixed_array_4d(class_type const& rhs);
~fixed_array_4d() stlsoft_throw_0();
// Access
public:
reference at(index_type i0, index_type i1, index_type i2, index_type i3);
const_reference at(index_type i0, index_type i1, index_type i2, index_type i3) const;
reference at_unchecked(index_type i0, index_type i1, index_type i2, index_type i3);
const_reference at_unchecked(index_type i0, index_type i1, index_type i2, index_type i3) const;
#ifndef STLSOFT_FIXED_ARRAY_NO_FUNCTION_OP
reference operator ()(index_type i0, index_type i1, index_type i2, index_type i3);
const_reference operator ()(index_type i0, index_type i1, index_type i2, index_type i3) const;
#endif /* !STLSOFT_FIXED_ARRAY_NO_FUNCTION_OP */
dimension_element_type at(index_type i0);
const dimension_element_type at(index_type i0) const;
dimension_element_type at_unchecked(index_type i0);
const dimension_element_type at_unchecked(index_type i0) const;
dimension_element_type operator [](index_type i0);
const dimension_element_type operator [](index_type i0) const;
reference front();
reference back();
const_reference front() const;
const_reference back() const;
// State
public:
index_type dimension0() const;
index_type dimension1() const;
index_type dimension2() const;
index_type dimension3() const;
index_type size() const;
ss_bool_t empty() const;
static size_type max_size();
// Iteration
public:
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
#if defined(STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT)
reverse_iterator rbegin();
reverse_iterator rend();
const_reverse_iterator rbegin() const;
const_reverse_iterator rend() const;
#endif /* STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT */
// Access
public:
value_type const *data() const;
// Implementation
private:
pointer allocate_(size_type n);
void deallocate_(pointer p, size_type n);
pointer data_();
index_type calc_index_(index_type i0, index_type i1, index_type i2, index_type i3) const;
void range_check_(index_type i0, index_type i1, index_type i2, index_type i3) const stlsoft_throw_1(stlsoft_ns_qual_std(out_of_range) );
void range_check_(index_type i0) const stlsoft_throw_1(stlsoft_ns_qual_std(out_of_range) );
// Members
private:
T * const m_data;
const index_type m_d0;
const index_type m_d1;
const index_type m_d2;
const index_type m_d3;
friend class fixed_array_5d<T, A, P, true>;
friend class fixed_array_5d<T, A, P, false>;
// Not to be implemented
private:
class_type const& operator =(class_type const& rhs);
};
////////////////////////////////////////////////////////////////////////////
// Unit-testing
#ifdef STLSOFT_UNITTEST
# include "./unittest/fixed_array_unittest_.h"
#endif /* STLSOFT_UNITTEST */
/* /////////////////////////////////////////////////////////////////////////
* Implementation
*/
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
// fixed_array_1d
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline ss_typename_type_k fixed_array_1d<T, A, P, R>::pointer fixed_array_1d<T, A, P, R>::allocate_(ss_typename_type_k fixed_array_1d<T, A, P, R>::size_type n)
{
allocator_type &ator = *this;
return ator.allocate(n, NULL);
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline void fixed_array_1d<T, A, P, R>::deallocate_(ss_typename_type_k fixed_array_1d<T, A, P, R>::pointer p, ss_typename_type_k fixed_array_1d<T, A, P, R>::size_type n)
{
allocator_type &ator = *this;
ator.deallocate(p, n);
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline ss_typename_type_k fixed_array_1d<T, A, P, R>::pointer fixed_array_1d<T, A, P, R>::data_()
{
return m_data;
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline ss_typename_type_k fixed_array_1d<T, A, P, R>::index_type fixed_array_1d<T, A, P, R>::calc_index_(ss_typename_type_k fixed_array_1d<T, A, P, R>::index_type i0) const
{
return i0;
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline void fixed_array_1d<T, A, P, R>::range_check_(ss_typename_type_k fixed_array_1d<T, A, P, R>::index_type i0) const stlsoft_throw_1(stlsoft_ns_qual_std(out_of_range) )
{
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
if(!(i0 < m_d0))
{
STLSOFT_THROW_X(stlsoft_ns_qual_std(out_of_range)("fixed array index out of range"));
}
#else
STLSOFT_MESSAGE_ASSERT("fixed array index out of range", i0 < m_d0);
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline fixed_array_1d<T, A, P, R>::fixed_array_1d(T *src, ss_typename_type_k fixed_array_1d<T, A, P, R>::index_type d0)
: m_data(src)
, m_d0(d0)
{
STLSOFT_STATIC_ASSERT(!R);
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline fixed_array_1d<T, A, P, R>::fixed_array_1d(ss_typename_type_k fixed_array_1d<T, A, P, R>::index_type d0)
: m_data(allocate_(d0))
, m_d0(d0)
{
STLSOFT_STATIC_ASSERT(R);
array_range_initialiser<T, A, P>::construct(*this, data_(), size());
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline fixed_array_1d<T, A, P, R>::fixed_array_1d(ss_typename_type_k fixed_array_1d<T, A, P, R>::index_type d0, value_type const& t)
: m_data(allocate_(d0))
, m_d0(d0)
{
STLSOFT_STATIC_ASSERT(R);
array_range_initialiser<T, A, P>::construct(*this, data_(), size(), t);
}
#ifdef STLSOFT_MULTIDIM_ARRAY_FEATURE_REQUIRES_COPY_CTOR_WITH_RVO
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline fixed_array_1d<T, A, P, R>::fixed_array_1d(fixed_array_1d<T, A, P, R> const& rhs)
: m_data(R ? allocate_(rhs.dimension0()) : rhs.m_data)
, m_d0(rhs.dimension0())
{
if(R)
{
array_range_initialiser<T, A, P>::copy_construct(*this, data_(), rhs.data(), size());
}
}
#else /* ? STLSOFT_MULTIDIM_ARRAY_FEATURE_REQUIRES_COPY_CTOR_WITH_RVO */
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline fixed_array_1d<T, A, P, R>::fixed_array_1d(fixed_array_1d<T, A, P, R> const& rhs)
: m_data(allocate_(rhs.dimension0()))
, m_d0(rhs.dimension0())
{
STLSOFT_STATIC_ASSERT(R);
array_range_initialiser<T, A, P>::copy_construct(*this, data_(), rhs.data(), size());
}
#endif /* STLSOFT_MULTIDIM_ARRAY_FEATURE_REQUIRES_COPY_CTOR_WITH_RVO */
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline fixed_array_1d<T, A, P, R>::~fixed_array_1d() stlsoft_throw_0()
{
if(R)
{
array_range_initialiser<T, A, P>::destroy(*this, data_(), size());
deallocate_(m_data, size());
}
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline ss_typename_type_k fixed_array_1d<T, A, P, R>::reference fixed_array_1d<T, A, P, R>::at(ss_typename_type_k fixed_array_1d<T, A, P, R>::index_type i0)
{
range_check_(i0);
return m_data[i0];
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline ss_typename_type_k fixed_array_1d<T, A, P, R>::const_reference fixed_array_1d<T, A, P, R>::at(ss_typename_type_k fixed_array_1d<T, A, P, R>::index_type i0) const
{
range_check_(i0);
return m_data[i0];
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline ss_typename_type_k fixed_array_1d<T, A, P, R>::reference fixed_array_1d<T, A, P, R>::at_unchecked(ss_typename_type_k fixed_array_1d<T, A, P, R>::index_type i0)
{
STLSOFT_MESSAGE_ASSERT("fixed array index out of range", i0 < m_d0);
return m_data[i0];
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline ss_typename_type_k fixed_array_1d<T, A, P, R>::const_reference fixed_array_1d<T, A, P, R>::at_unchecked(ss_typename_type_k fixed_array_1d<T, A, P, R>::index_type i0) const
{
STLSOFT_MESSAGE_ASSERT("fixed array index out of range", i0 < m_d0);
return m_data[i0];
}
#ifndef STLSOFT_FIXED_ARRAY_NO_FUNCTION_OP
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline ss_typename_type_k fixed_array_1d<T, A, P, R>::reference fixed_array_1d<T, A, P, R>::operator ()(ss_typename_type_k fixed_array_1d<T, A, P, R>::index_type i0)
{
return at_unchecked(i0);
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -