16#ifndef __BE_MEMORY_AUTOARRAY_H__
17#define __BE_MEMORY_AUTOARRAY_H__
27#include <be_error_exception.h>
28#include <be_memory_autoarrayiterator.h>
30namespace BiometricEvaluation
56 AutoArrayIterator<true, T>;
155 ptrdiff_t index)
const;
382 std::initializer_list<T> ilist);
420 std::swap(std::declval<value_type&>(),
421 std::declval<value_type&>()))
424 std::swap(std::declval<size_type&>(),
425 std::declval<size_type&>())));
509 if (!free && (new_size <= _capacity)) {
514 T* new_data =
nullptr;
516 new_data =
new (std::nothrow) T[new_size];
517 if (new_data ==
nullptr)
522 std::copy(&_data[0], &_data[((new_size < _size) ? new_size : _size)],
526 if (_data !=
nullptr)
529 _size = _capacity = new_size;
537 std::copy(&buffer[0], &buffer[_size], _data);
547 std::copy(&buffer[0], &buffer[size], _data);
553 ptrdiff_t index)
const
556 throw std::out_of_range(
"index");
558 return (_data[index]);
560 throw std::out_of_range(
"index");
569 throw std::out_of_range(
"index");
571 return (_data[index]);
573 throw std::out_of_range(
"index");
577typename std::vector<T>
581 return {this->cbegin(), this->cend()};
608 return (_data[index]);
617 return (_data[index]);
625 if (
this != &other) {
626 _size = _capacity = other._size;
627 if (_data !=
nullptr) {
632 _data =
new (std::nothrow) T[_size];
633 if (_data ==
nullptr)
636 std::copy(&(other._data[0]), &(other._data[_size]),
650 std::swap(std::declval<value_type&>(), std::declval<value_type&>())) &&
652 std::swap(std::declval<size_type&>(), std::declval<size_type&>())))
656 swap(_size, other._size);
657 swap(_capacity, other._capacity);
658 swap(_data, other._data);
678 return (this->cbegin());
693 if (this->size() > std::numeric_limits<
typename BiometricEvaluation::
694 Memory::AutoArrayIterator<false, T>::difference_type>::max())
696 "large to represent end iterator"};
699 static_cast<typename BiometricEvaluation::Memory::
700 AutoArrayIterator<false, T>::difference_type
>(this->size())));
708 return (this->cend());
716 if (this->size() > std::numeric_limits<
typename BiometricEvaluation::
717 Memory::AutoArrayIterator<true, T>::difference_type>::max())
719 "large to represent end iterator"};
722 static_cast<typename BiometricEvaluation::Memory::
723 AutoArrayIterator<true, T>::difference_type
>(this->size())));
737 _data =
new (std::nothrow) T[_size];
738 if (_data ==
nullptr)
748 _capacity(copy._size)
751 _data =
new (std::nothrow) T[_size];
752 if (_data ==
nullptr)
754 std::copy(&(
copy._data[0]), &(
copy._data[_size]), _data);
764 _capacity(rvalue._capacity)
767 rvalue._data =
nullptr;
768 rvalue._capacity = 0;
774 std::initializer_list<T> ilist) :
AutoArray(ilist.size())
776 std::copy(ilist.begin(), ilist.end(), _data);
785 if (_data !=
nullptr)
795BiometricEvaluation::Memory::operator==(
807BiometricEvaluation::Memory::operator!=(
811 return (!(lhs == rhs));
816BiometricEvaluation::Memory::operator<(
820 return (std::lexicographical_compare(lhs.
cbegin(), lhs.
cend(),
826BiometricEvaluation::Memory::operator<=(
830 return (!(rhs < lhs));
835BiometricEvaluation::Memory::operator>(
844BiometricEvaluation::Memory::operator>=(
848 return (!(lhs < rhs));
An error occurred when allocating an object.
Definition: be_error_exception.h:169
A StrategyError object is thrown when the underlying implementation of this interface encounters an e...
Definition: be_error_exception.h:270
A C-style array wrapped in the facade of a C++ STL container.
Definition: be_memory_autoarray.h:45
T & reference
Reference to element.
Definition: be_memory_autoarray.h:59
AutoArray & operator=(const AutoArray &other)
Copy assignment operator overload performing a deep copy.
Definition: be_memory_autoarray.h:622
iterator end()
Obtain an iterator to the end of the AutoArray.
Definition: be_memory_autoarray.h:691
iterator begin()
Obtain an iterator to the beginning of the AutoArray.
Definition: be_memory_autoarray.h:668
AutoArray(size_type size=0)
Construct an AutoArray.
Definition: be_memory_autoarray.h:730
const_iterator cend() const
Obtain an iterator to the end of the AutoArray.
Definition: be_memory_autoarray.h:713
~AutoArray()
Destructor.
Definition: be_memory_autoarray.h:783
void copy(const T *buffer)
Deep-copy the contents of a buffer into this AutoArray.
Definition: be_memory_autoarray.h:534
const_iterator cbegin() const
Obtain an iterator to the beginning of the AutoArray.
Definition: be_memory_autoarray.h:683
const T & const_reference
Const reference element.
Definition: be_memory_autoarray.h:61
size_type size() const
Obtain the number of accessible elements.
Definition: be_memory_autoarray.h:496
AutoArrayIterator< false, T > iterator
Iterator of element.
Definition: be_memory_autoarray.h:53
reference operator[](ptrdiff_t index)
Subscripting operator overload with unchecked access.
Definition: be_memory_autoarray.h:605
std::vector< T > to_vector() const
Obtain a copy of elements in this AutoArray as a vector.
Definition: be_memory_autoarray.h:578
size_t size_type
Type of subscripts, counts, etc.
Definition: be_memory_autoarray.h:50
T value_type
Type of element.
Definition: be_memory_autoarray.h:48
AutoArrayIterator< true, T > const_iterator
Const iterator of element.
Definition: be_memory_autoarray.h:56
reference at(ptrdiff_t index)
Subscript into the AutoArray with checked access.
Definition: be_memory_autoarray.h:565
void resize(size_type new_size, bool free=false)
Change the number of accessible elements.
Definition: be_memory_autoarray.h:504