25#ifndef __BITPIT_PROXY_VECTOR_TPP__
26#define __BITPIT_PROXY_VECTOR_TPP__
33template<
typename value_t,
typename container_t>
47template<
typename value_t,
typename container_t>
48template<typename other_value_t, typename std::enable_if<std::is_const<value_t>::value && !std::is_const<other_value_t>::value && std::is_same<other_value_t, typename std::remove_cv<value_t>::type>::value,
int>::type>
50 : m_position(other.m_position)
60template<
typename value_t,
typename container_t>
63 std::swap(m_position, other.m_position);
69template<
typename value_t,
typename container_t>
80template<
typename value_t,
typename container_t>
93template<
typename value_t,
typename container_t>
104template<
typename value_t,
typename container_t>
119template<
typename value_t,
typename container_t>
122 m_position += increment;
132template<
typename value_t,
typename container_t>
143template<
typename value_t,
typename container_t>
155template<
typename value_t,
typename container_t>
156template<typename other_value_t, typename std::enable_if<std::is_const<value_t>::value && !std::is_const<other_value_t>::value && std::is_same<other_value_t, typename std::remove_cv<value_t>::type>::value,
int>::type>
159 m_position = other.m_position;
168template<
typename value_t,
typename container_t>
170 : m_position(position)
180template<
typename value_t,
typename container_t>
183 return (m_position - other.m_position);
191template<
typename value_t,
typename po
inter_t,
typename const_po
inter_t>
202template<
typename value_t,
typename po
inter_t,
typename const_po
inter_t>
213template<
typename value_t,
typename po
inter_t,
typename const_po
inter_t>
224template<
typename value_t,
typename po
inter_t,
typename const_po
inter_t>
235template<
typename value_t,
typename po
inter_t,
typename const_po
inter_t>
246template<
typename value_t,
typename po
inter_t,
typename const_po
inter_t>
257template<
typename value_t,
typename po
inter_t,
typename const_po
inter_t>
266template<
typename value_t,
typename container_t,
bool thread_safe>
276template<
typename value_t,
typename container_t,
bool thread_safe>
279 if (size == 0 && !allowEmpty) {
280 return std::unique_ptr<container_t>(
nullptr);
284 if (!m_containerPool.empty()) {
285 std::unique_ptr<container_t> container = std::move(m_containerPool.back());
286 if (container->size() < size) {
287 container->resize(size);
290 m_containerPool.resize(m_containerPool.size() - 1);
294 return std::unique_ptr<container_t>(
new container_t(size));
297 return std::unique_ptr<container_t>(
new container_t(size));
309template<
typename value_t,
typename container_t,
bool thread_safe>
310std::unique_ptr<container_t> ProxyVectorStorage<value_t, container_t, thread_safe>::createContainer(
const std::unique_ptr<container_t> &source,
bool allowEmpty)
312 if (!source || source->empty()) {
314 return createContainer(0,
true);
316 return std::unique_ptr<container_t>(
nullptr);
321 if (!m_containerPool.empty()) {
322 std::unique_ptr<container_t> container = createContainer(source->size(),
false);
323 std::copy_n(source->data(), source->size(), container->data());
327 return std::unique_ptr<container_t>(
new container_t(*source));
330 return std::unique_ptr<container_t>(
new container_t(*source));
337template<
typename value_t,
typename container_t,
bool thread_safe>
338void ProxyVectorStorage<value_t, container_t, thread_safe>::destroyContainer(std::unique_ptr<container_t> *container)
345 if (m_containerPool.size() < MEMORY_POOL_VECTOR_COUNT) {
346 if ((*container)->size() > MEMORY_POOL_MAX_CAPACITY) {
347 (*container)->resize(MEMORY_POOL_MAX_CAPACITY);
350 m_containerPool.emplace_back(std::move(*container));
361template<
typename value_t,
typename container_t,
bool thread_safe>
363 : m_container(createContainer(size, false))
373template<
typename value_t,
typename container_t,
bool thread_safe>
375 : m_container(createContainer(other.m_container, false))
385template<
typename value_t,
typename container_t,
bool thread_safe>
389 this->swap(temporary);
397template<
typename value_t,
typename container_t,
bool thread_safe>
400 destroyContainer(&m_container);
410template<
typename value_t,
typename container_t,
bool thread_safe>
413 if (!m_container && forceCreation) {
414 m_container = createContainer(0,
true);
417 return m_container.get();
427template<
typename value_t,
typename container_t,
bool thread_safe>
430 if (!m_container && forceCreation) {
431 m_container = createContainer(0,
true);
434 return m_container.get();
442template<
typename value_t,
typename container_t,
bool thread_safe>
445 m_container.swap(other.m_container);
453template<
typename value_t,
typename container_t,
bool thread_safe>
460 return m_container->data();
468template<
typename value_t,
typename container_t,
bool thread_safe>
475 return m_container->data();
483template<
typename value_t,
typename container_t,
bool thread_safe>
490 return m_container->empty();
498template<
typename value_t,
typename container_t,
bool thread_safe>
505 return m_container->size();
513template<
typename value_t,
typename container_t,
bool thread_safe>
517 destroyContainer(&m_container);
523 m_container->resize(size);
525 m_container = createContainer(size,
false);
532template<
typename value_t,
bool thread_safe>
534 : m_size(0), m_data(nullptr)
550template<
typename value_t,
bool thread_safe>
551template<typename other_value_t, typename std::enable_if<std::is_const<other_value_t>::value,
int>::type>
553 :
ProxyVector<value_t, thread_safe>(INTERNAL_STORAGE, size, size)
573template<
typename value_t,
bool thread_safe>
574template<typename other_value_t, typename std::enable_if<std::is_const<other_value_t>::value,
int>::type>
593template<
typename value_t,
bool thread_safe>
594template<typename other_value_t, typename std::enable_if<std::is_const<other_value_t>::value,
int>::type>
617template<
typename value_t,
bool thread_safe>
618template<typename other_value_t, typename std::enable_if<std::is_const<other_value_t>::value,
int>::type>
620 : m_storage(capacity), m_size(size), m_data((data != INTERNAL_STORAGE) ? data : m_storage.data())
635template<
typename value_t,
bool thread_safe>
636template<typename other_value_t, typename std::enable_if<!std::is_const<other_value_t>::value,
int>::type>
638 : m_storage(0), m_size(size), m_data(data)
648template<
typename value_t,
bool thread_safe>
650 : m_storage(other.m_storage), m_size(other.m_size), m_data(other.storedData() ? m_storage.data() : other.m_data)
665template<
typename value_t,
bool thread_safe>
667 : m_storage(std::move(other.m_storage)), m_size(std::move(other.m_size)), m_data(std::move(other.m_data))
679template<
typename value_t,
bool thread_safe>
682 if (
this != &other) {
684 temporary.
swap(*
this);
704template<
typename value_t,
bool thread_safe>
707 if (
this != &other) {
709 temporary.
swap(*
this);
730template<
typename value_t,
bool thread_safe>
731template<typename other_value_t, typename std::enable_if<std::is_const<other_value_t>::value,
int>::type>
734 std::size_t capacity;
735 if (data != INTERNAL_STORAGE) {
740 set(data, size, capacity);
762template<
typename value_t,
bool thread_safe>
763template<typename other_value_t, typename std::enable_if<std::is_const<other_value_t>::value,
int>::type>
766 m_storage.resize(std::max(size, capacity));
769 if (data == INTERNAL_STORAGE) {
773 m_data = m_storage.data();
793template<
typename value_t,
bool thread_safe>
794template<typename other_value_t, typename std::enable_if<!std::is_const<other_value_t>::value,
int>::type>
797 assert(data != INTERNAL_STORAGE);
813template<
typename value_t,
bool thread_safe>
816 __PXV_STORAGE_POINTER__ internalData = m_storage.data();
819 }
else if (internalData != m_data) {
834template<
typename value_t,
bool thread_safe>
837 __PXV_STORAGE_CONST_POINTER__ internalData = m_storage.data();
840 }
else if (internalData != m_data) {
860template<
typename value_t,
bool thread_safe>
861template<typename U, typename std::enable_if<std::is_const<U>::value,
int>::type>
864 return m_storage.container(forceCreation);
880template<
typename value_t,
bool thread_safe>
881template<typename U, typename std::enable_if<std::is_const<U>::value,
int>::type>
884 return m_storage.container(forceCreation);
892template<
typename value_t,
bool thread_safe>
895 std::swap(m_size, other.m_size);
896 std::swap(m_data, other.m_data);
898 m_storage.swap(other.m_storage);
906template<
typename value_t,
bool thread_safe>
909 if (m_size != other.m_size) {
914 if (m_data != other.m_data) {
919 for (std::size_t i = 0; i < m_size; ++i) {
920 if (m_data[i] != other.m_data[i]) {
933template<
typename value_t,
bool thread_safe>
944template<
typename value_t,
bool thread_safe>
955template<
typename value_t,
bool thread_safe>
956template<typename other_value_t, typename std::enable_if<!std::is_const<other_value_t>::value,
int>::type>
969template<
typename value_t,
bool thread_safe>
981template<
typename value_t,
bool thread_safe>
982template<typename other_value_t, typename std::enable_if<!std::is_const<other_value_t>::value,
int>::type>
994template<
typename value_t,
bool thread_safe>
1006template<
typename value_t,
bool thread_safe>
1007template<typename other_value_t, typename std::enable_if<!std::is_const<other_value_t>::value,
int>::type>
1019template<
typename value_t,
bool thread_safe>
1030template<
typename value_t,
bool thread_safe>
1031template<typename other_value_t, typename std::enable_if<!std::is_const<other_value_t>::value,
int>::type>
1042template<
typename value_t,
bool thread_safe>
1053template<
typename value_t,
bool thread_safe>
1054template<typename other_value_t, typename std::enable_if<!std::is_const<other_value_t>::value,
int>::type>
1057 return m_data[m_size - 1];
1065template<
typename value_t,
bool thread_safe>
1068 return m_data[m_size - 1];
1076template<
typename value_t,
bool thread_safe>
1077template<typename other_value_t, typename std::enable_if<!std::is_const<other_value_t>::value,
int>::type>
1088template<
typename value_t,
bool thread_safe>
1099template<
typename value_t,
bool thread_safe>
1100template<typename other_value_t, typename std::enable_if<!std::is_const<other_value_t>::value,
int>::type>
1113template<
typename value_t,
bool thread_safe>
1124template<
typename value_t,
bool thread_safe>
1138template<
typename value_t,
bool thread_safe>
Metafunction for generating ProxyVector dummy storages.
std::size_t size() const override
void resize(std::size_t size) override
void swap(ProxyVectorDummyStorage &other) noexcept
bool empty() const override
ProxyVectorDummyStorage(std::size_t size=0)
Iterator for the class ProxyVector.
ProxyVectorIterator & operator+=(int increment)
ProxyVectorIterator & operator++()
ProxyVectorIterator & operator--()
__PXI_REFERENCE__ operator*() const
__PXI_POINTER__ operator->() const
void swap(ProxyVectorIterator &other) noexcept
std::size_t operator-(const ProxyVectorIterator &other)
Metafunction for generating ProxyVector storages.
ProxyVectorStorage(std::size_t size=0)
ProxyVectorStorage & operator=(const ProxyVectorStorage &other)
void swap(ProxyVectorStorage &other) noexcept
~ProxyVectorStorage() override
container_t * container(bool forceCreation)
bool empty() const override
std::size_t size() const override
void resize(std::size_t size) override
Metafunction for generating a list of elements that can be either stored in an external vectror or,...
static constexpr __PXV_POINTER__ INTERNAL_STORAGE
ProxyVector & operator=(const ProxyVector &other)
__PXV_CONST_ITERATOR__ cend()
std::vector< value_no_cv_t > container_type
void swap(ProxyVector &other)
__PXV_POINTER__ data() noexcept
__PXV_CONST_ITERATOR__ cbegin()
bool operator==(const ProxyVector &other) const
__PXV_REFERENCE__ operator[](std::size_t n)
__PXV_STORAGE_POINTER__ storedData() noexcept
__PXV_REFERENCE__ at(std::size_t n)
__PXV_REFERENCE__ front()
container_type * storedDataContainer(bool forceCreation=false)
void set(__PXV_POINTER__ data, std::size_t size)
#define BITPIT_UNUSED(variable)