DNA Calib 1.1
Project brief
Public Types | Public Member Functions | Private Types | Static Private Member Functions | Private Attributes | List of all members
terse::DynArray< T, TAllocator > Class Template Reference

Resizable array-like abstraction for trivial-types only. More...

#include <DynArray.h>

Inheritance diagram for terse::DynArray< T, TAllocator >:
Inheritance graph
Collaboration diagram for terse::DynArray< T, TAllocator >:
Collaboration graph

Public Types

using value_type = T
 
using allocator_type = TAllocator
 

Public Member Functions

 DynArray (const allocator_type &allocator)
 
 DynArray ()
 
 DynArray (std::size_t size, const allocator_type &allocator=allocator_type{})
 
 DynArray (std::size_t size, const value_type &value, const allocator_type &allocator=allocator_type{})
 
 DynArray (const value_type *source, std::size_t size, const allocator_type &allocator=allocator_type{})
 
template<typename TIterator >
 DynArray (TIterator start, TIterator end, const allocator_type &allocator=allocator_type{})
 
 ~DynArray ()=default
 
 DynArray (const DynArray &rhs)
 
DynArrayoperator= (const DynArray &rhs)
 
 DynArray (DynArray &&rhs) noexcept
 
DynArrayoperator= (DynArray &&rhs) noexcept
 
allocator_type get_allocator () const noexcept
 
void clear ()
 
value_typedata ()
 
const value_typedata () const
 
std::size_t size () const
 
bool empty () const
 
value_typeoperator[] (std::size_t index)
 
const value_typeoperator[] (std::size_t index) const
 
value_typebegin ()
 
value_typeend ()
 
const value_typecbegin () const
 
const value_typecend () const
 
const value_typebegin () const
 
const value_typeend () const
 
void resize (std::size_t size, const value_type &value)
 
void resize (std::size_t size)
 
void resize_uninitialized (std::size_t size)
 
template<typename TIterator >
void assign (TIterator start, TIterator end)
 

Private Types

using pointer_type = std::unique_ptr< value_type, std::function< void(value_type *)> >
 

Static Private Member Functions

static pointer_type create (std::size_t size, allocator_type alloc)
 

Private Attributes

allocator_type alloc
 
std::size_t sz
 
pointer_type ptr
 

Detailed Description

template<typename T, class TAllocator>
class terse::DynArray< T, TAllocator >

Resizable array-like abstraction for trivial-types only.

Member Typedef Documentation

◆ allocator_type

template<typename T , class TAllocator >
using terse::DynArray< T, TAllocator >::allocator_type = TAllocator

◆ pointer_type

template<typename T , class TAllocator >
using terse::DynArray< T, TAllocator >::pointer_type = std::unique_ptr<value_type, std::function<void (value_type*)> >
private

◆ value_type

template<typename T , class TAllocator >
using terse::DynArray< T, TAllocator >::value_type = T

Constructor & Destructor Documentation

◆ DynArray() [1/8]

template<typename T , class TAllocator >
terse::DynArray< T, TAllocator >::DynArray ( const allocator_type allocator)
inlineexplicit
38 :
39 alloc{allocator},
40 sz{},
41 ptr{nullptr} {
42 }
allocator_type alloc
Definition: DynArray.h:225
std::size_t sz
Definition: DynArray.h:226
pointer_type ptr
Definition: DynArray.h:227

◆ DynArray() [2/8]

template<typename T , class TAllocator >
terse::DynArray< T, TAllocator >::DynArray ( )
inline
45 }
DynArray()
Definition: DynArray.h:44
TAllocator allocator_type
Definition: DynArray.h:32

◆ DynArray() [3/8]

template<typename T , class TAllocator >
terse::DynArray< T, TAllocator >::DynArray ( std::size_t  size,
const allocator_type allocator = allocator_type{} 
)
inline
47 {}) :
48 alloc{allocator},
49 sz{size},
50 ptr{create(sz, alloc)} {
51 }
std::size_t size() const
Definition: DynArray.h:130
static pointer_type create(std::size_t size, allocator_type alloc)
Definition: DynArray.h:218

◆ DynArray() [4/8]

template<typename T , class TAllocator >
terse::DynArray< T, TAllocator >::DynArray ( std::size_t  size,
const value_type value,
const allocator_type allocator = allocator_type{} 
)
inline
53 {}) :
54 DynArray{size, allocator} {
55
56 std::fill_n(data(), size, value);
57 }
value_type * data()
Definition: DynArray.h:122

◆ DynArray() [5/8]

template<typename T , class TAllocator >
terse::DynArray< T, TAllocator >::DynArray ( const value_type source,
std::size_t  size,
const allocator_type allocator = allocator_type{} 
)
inline
59 {}) :
60 DynArray{size, allocator} {
61
62 if ((data() != nullptr) && (source != nullptr)) {
63 std::memcpy(data(), source, size * sizeof(value_type));
64 }
65 }
T value_type
Definition: DynArray.h:31

◆ DynArray() [6/8]

template<typename T , class TAllocator >
template<typename TIterator >
terse::DynArray< T, TAllocator >::DynArray ( TIterator  start,
TIterator  end,
const allocator_type allocator = allocator_type{} 
)
inline
68 {}) :
69 DynArray{static_cast<std::size_t>(std::distance(start, end)), allocator} {
70
71 #if defined(_MSC_VER) && !defined(__clang__)
72 if (size() != 0ul) {
73 std::copy(start, end, stdext::checked_array_iterator<value_type*>(data(), size()));
74 }
75 #else
76 std::copy(start, end, data());
77 #endif
78 }
value_type * end()
Definition: DynArray.h:152
void copy(const TSource &source, TDestination &destination)
Definition: utils/Extd.h:123

◆ ~DynArray()

template<typename T , class TAllocator >
terse::DynArray< T, TAllocator >::~DynArray ( )
default

◆ DynArray() [7/8]

template<typename T , class TAllocator >
terse::DynArray< T, TAllocator >::DynArray ( const DynArray< T, TAllocator > &  rhs)
inline
82 : DynArray{rhs.size(), rhs.get_allocator()} {
83 if ((data() != nullptr) && (rhs.data() != nullptr)) {
84 std::memcpy(data(), rhs.data(), rhs.size() * sizeof(value_type));
85 }
86 }

References terse::DynArray< T, TAllocator >::data(), and terse::DynArray< T, TAllocator >::size().

◆ DynArray() [8/8]

template<typename T , class TAllocator >
terse::DynArray< T, TAllocator >::DynArray ( DynArray< T, TAllocator > &&  rhs)
inlinenoexcept
96 :
97 alloc{},
98 sz{},
99 ptr{} {
100
101 std::swap(alloc, rhs.alloc);
102 std::swap(ptr, rhs.ptr);
103 std::swap(sz, rhs.sz);
104 }

Member Function Documentation

◆ assign()

template<typename T , class TAllocator >
template<typename TIterator >
void terse::DynArray< T, TAllocator >::assign ( TIterator  start,
TIterator  end 
)
inline
206 {
207 resize_uninitialized(static_cast<std::size_t>(std::distance(start, end)));
208 #if defined(_MSC_VER) && !defined(__clang__)
209 if (size() != 0ul) {
210 std::copy(start, end, stdext::checked_array_iterator<value_type*>(data(), size()));
211 }
212 #else
213 std::copy(start, end, data());
214 #endif
215 }
void resize_uninitialized(std::size_t size)
Definition: DynArray.h:191

References extd::copy(), terse::DynArray< T, TAllocator >::data(), terse::DynArray< T, TAllocator >::end(), terse::DynArray< T, TAllocator >::resize_uninitialized(), and terse::DynArray< T, TAllocator >::size().

◆ begin() [1/2]

template<typename T , class TAllocator >
value_type * terse::DynArray< T, TAllocator >::begin ( )
inline

◆ begin() [2/2]

template<typename T , class TAllocator >
const value_type * terse::DynArray< T, TAllocator >::begin ( ) const
inline
164 {
165 return cbegin();
166 }
const value_type * cbegin() const
Definition: DynArray.h:156

References terse::DynArray< T, TAllocator >::cbegin().

◆ cbegin()

template<typename T , class TAllocator >
const value_type * terse::DynArray< T, TAllocator >::cbegin ( ) const
inline
156 {
157 return data();
158 }

References terse::DynArray< T, TAllocator >::data().

Referenced by terse::DynArray< T, TAllocator >::begin().

◆ cend()

template<typename T , class TAllocator >
const value_type * terse::DynArray< T, TAllocator >::cend ( ) const
inline

◆ clear()

template<typename T , class TAllocator >
void terse::DynArray< T, TAllocator >::clear ( )
inline

◆ create()

template<typename T , class TAllocator >
static pointer_type terse::DynArray< T, TAllocator >::create ( std::size_t  size,
allocator_type  alloc 
)
inlinestaticprivate
218 {
219 return pointer_type{alloc.allocate(size), [alloc, size](value_type* p) mutable {
220 alloc.deallocate(p, size);
221 }};
222 }
std::unique_ptr< value_type, std::function< void(value_type *)> > pointer_type
Definition: DynArray.h:35

References terse::DynArray< T, TAllocator >::alloc, and terse::DynArray< T, TAllocator >::size().

Referenced by terse::DynArray< T, TAllocator >::resize(), and terse::DynArray< T, TAllocator >::resize_uninitialized().

◆ data() [1/2]

template<typename T , class TAllocator >
value_type * terse::DynArray< T, TAllocator >::data ( )
inline

◆ data() [2/2]

template<typename T , class TAllocator >
const value_type * terse::DynArray< T, TAllocator >::data ( ) const
inline
126 {
127 return ptr.get();
128 }

References terse::DynArray< T, TAllocator >::ptr.

◆ empty()

template<typename T , class TAllocator >
bool terse::DynArray< T, TAllocator >::empty ( ) const
inline

◆ end() [1/2]

template<typename T , class TAllocator >
value_type * terse::DynArray< T, TAllocator >::end ( )
inline

◆ end() [2/2]

template<typename T , class TAllocator >
const value_type * terse::DynArray< T, TAllocator >::end ( ) const
inline
168 {
169 return cend();
170 }
const value_type * cend() const
Definition: DynArray.h:160

References terse::DynArray< T, TAllocator >::cend().

◆ get_allocator()

template<typename T , class TAllocator >
allocator_type terse::DynArray< T, TAllocator >::get_allocator ( ) const
inlinenoexcept

◆ operator=() [1/2]

template<typename T , class TAllocator >
DynArray & terse::DynArray< T, TAllocator >::operator= ( const DynArray< T, TAllocator > &  rhs)
inline
88 {
89 DynArray tmp{rhs};
90 std::swap(alloc, tmp.alloc);
91 std::swap(ptr, tmp.ptr);
92 std::swap(sz, tmp.sz);
93 return *this;
94 }

References terse::DynArray< T, TAllocator >::alloc, terse::DynArray< T, TAllocator >::ptr, and terse::DynArray< T, TAllocator >::sz.

◆ operator=() [2/2]

template<typename T , class TAllocator >
DynArray & terse::DynArray< T, TAllocator >::operator= ( DynArray< T, TAllocator > &&  rhs)
inlinenoexcept
106 {
107 std::swap(alloc, rhs.alloc);
108 std::swap(ptr, rhs.ptr);
109 std::swap(sz, rhs.sz);
110 return *this;
111 }

References terse::DynArray< T, TAllocator >::alloc, terse::DynArray< T, TAllocator >::ptr, and terse::DynArray< T, TAllocator >::sz.

◆ operator[]() [1/2]

template<typename T , class TAllocator >
value_type & terse::DynArray< T, TAllocator >::operator[] ( std::size_t  index)
inline
138 {
139 assert(index < size());
140 return data()[index];
141 }

References terse::DynArray< T, TAllocator >::data(), and terse::DynArray< T, TAllocator >::size().

◆ operator[]() [2/2]

template<typename T , class TAllocator >
const value_type & terse::DynArray< T, TAllocator >::operator[] ( std::size_t  index) const
inline
143 {
144 assert(index < size());
145 return data()[index];
146 }

References terse::DynArray< T, TAllocator >::data(), and terse::DynArray< T, TAllocator >::size().

◆ resize() [1/2]

template<typename T , class TAllocator >
void terse::DynArray< T, TAllocator >::resize ( std::size_t  size)
inline
187 {
189 }
void resize(std::size_t size, const value_type &value)
Definition: DynArray.h:172

References terse::DynArray< T, TAllocator >::resize(), and terse::DynArray< T, TAllocator >::size().

◆ resize() [2/2]

template<typename T , class TAllocator >
void terse::DynArray< T, TAllocator >::resize ( std::size_t  size,
const value_type value 
)
inline
172 {
173 if (size > sz) {
174 pointer_type old{ptr.release(), [this](value_type* p) {
175 alloc.deallocate(p, sz);
176 }};
177 ptr = create(size, alloc);
178 assert(ptr != nullptr);
179 if (old != nullptr) {
180 std::memcpy(ptr.get(), old.get(), sz * sizeof(value_type));
181 }
182 std::fill_n(begin() + sz, size - sz, value);
183 }
184 sz = size;
185 }
value_type * begin()
Definition: DynArray.h:148

References terse::DynArray< T, TAllocator >::alloc, terse::DynArray< T, TAllocator >::begin(), terse::DynArray< T, TAllocator >::create(), terse::DynArray< T, TAllocator >::ptr, terse::DynArray< T, TAllocator >::size(), and terse::DynArray< T, TAllocator >::sz.

Referenced by dna::JointFilter::apply(), dnac::JointFilter::apply(), terse::ExtendableJSONInputArchive< TExtender, TStream, TSize, TOffset >::process(), and terse::DynArray< T, TAllocator >::resize().

◆ resize_uninitialized()

template<typename T , class TAllocator >
void terse::DynArray< T, TAllocator >::resize_uninitialized ( std::size_t  size)
inline

◆ size()

template<typename T , class TAllocator >
std::size_t terse::DynArray< T, TAllocator >::size ( ) const
inline

Member Data Documentation

◆ alloc

template<typename T , class TAllocator >
allocator_type terse::DynArray< T, TAllocator >::alloc
private

◆ ptr

template<typename T , class TAllocator >
pointer_type terse::DynArray< T, TAllocator >::ptr
private

◆ sz

template<typename T , class TAllocator >
std::size_t terse::DynArray< T, TAllocator >::sz
private

The documentation for this class was generated from the following file: