Loading...
Searching...
No Matches
collection.hpp
// SPDX-FileCopyrightText: 2016 - 2025 Kohei Yoshida
//
// SPDX-License-Identifier: MIT
#pragma once
#include "mdds/multi_type_vector/types.hpp"
#include <type_traits>
#include <vector>
#include <memory>
namespace mdds { namespace mtv {
template<typename _MtvT>
class collection;
namespace detail {
template<typename _MtvT>
class side_iterator
{
typedef _MtvT mtv_type;
friend collection<mtv_type>;
typedef typename mtv_type::size_type size_type;
typedef typename mtv_type::const_iterator const_iterator;
typedef typename mtv_type::const_position_type const_position_type;
struct mtv_item
{
const mtv_type* vector;
const_iterator block_pos;
const_iterator block_end;
mtv_item(const mtv_type* v, const const_iterator& bp, const const_iterator& be)
: vector(v), block_pos(bp), block_end(be)
{}
};
struct node
{
friend class side_iterator;
mdds::mtv::element_t type;
size_type index;
size_type position;
template<typename _Blk>
typename _Blk::value_type get() const
{
return _Blk::get_value(*__position.first->data, __position.second);
}
private:
const_position_type __position;
};
enum begin_state_type
{
begin_state
};
enum end_state_type
{
end_state
};
std::vector<mtv_item> m_vectors;
node m_cur_node;
size_type m_elem_pos;
size_type m_elem_pos_end;
size_type m_index_offset;
uintptr_t m_identity;
side_iterator(
std::vector<mtv_item>&& vectors, size_type elem_pos, size_type elem_size, size_type index_offset,
uintptr_t identity, begin_state_type);
side_iterator(
std::vector<mtv_item>&& vectors, size_type elem_pos, size_type elem_size, size_type index_offset,
uintptr_t identity, end_state_type);
public:
typedef node value_type;
side_iterator();
template<typename _T>
side_iterator(const _T& begin, const _T& end);
const value_type& operator*() const
{
return m_cur_node;
}
const value_type* operator->() const
{
return &m_cur_node;
}
side_iterator& operator++();
side_iterator operator++(int);
bool operator==(const side_iterator& other) const;
bool operator!=(const side_iterator& other) const;
};
} // namespace detail
template<typename _MtvT>
class collection
{
public:
typedef _MtvT mtv_type;
typedef typename mtv_type::size_type size_type;
private:
struct range
{
size_type start;
size_type size;
range() : start(0), size(0)
{}
};
std::vector<const mtv_type*> m_vectors;
size_type m_mtv_size;
uintptr_t m_identity;
range m_elem_range;
range m_col_range;
public:
typedef detail::side_iterator<mtv_type> const_iterator;
collection();
template<typename _T>
collection(const _T& begin, const _T& end);
const_iterator begin() const;
const_iterator end() const;
size_type size() const;
void swap(collection& other);
void set_collection_range(size_type start, size_type size);
void set_element_range(size_type start, size_type size);
private:
void check_collection_range(size_type start, size_type size) const;
void check_element_range(size_type start, size_type size) const;
std::vector<typename const_iterator::mtv_item> build_iterator_state() const;
void init_insert_vector(const std::unique_ptr<mtv_type>& p);
void init_insert_vector(const std::shared_ptr<mtv_type>& p);
template<typename _T>
void init_insert_vector(const _T& t, typename std::enable_if<std::is_pointer<_T>::value>::type* = 0);
template<typename _T>
void init_insert_vector(const _T& t, typename std::enable_if<!std::is_pointer<_T>::value>::type* = 0);
void check_vector_size(const mtv_type& t);
};
}} // namespace mdds::mtv
#include "collection_def.inl"
mdds::mtv::collection
Definition collection.hpp:127
mdds::mtv::collection::end
const_iterator end() const
mdds::mtv::collection::const_iterator
detail::side_iterator< mtv_type > const_iterator
collection range.
Definition collection.hpp:150
mdds::mtv::collection::swap
void swap(collection &other)
mdds::mtv::collection::collection
collection(const _T &begin, const _T &end)
mdds::mtv::collection::size
size_type size() const
mdds::mtv::collection::set_element_range
void set_element_range(size_type start, size_type size)
mdds::mtv::collection::begin
const_iterator begin() const
mdds::mtv::collection::set_collection_range
void set_collection_range(size_type start, size_type size)
mdds::mtv::detail::side_iterator
Definition collection.hpp:22