numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
num_collect::util::bidirectional_vector< Value, Container > Class Template Reference

Class to save data in a sequence which can be extended even toward negative direction. More...

#include <num_collect/util/bidirectional_vector.h>

+ Inheritance diagram for num_collect::util::bidirectional_vector< Value, Container >:
+ Collaboration diagram for num_collect::util::bidirectional_vector< Value, Container >:

Public Types

using container_type = Container
 Type of the internal container.
 
using value_type = Value
 Type of values.
 

Public Member Functions

 bidirectional_vector ()=default
 Constructor.
 
 bidirectional_vector (container_type container, index_type origin_index)
 Constructor.
 
auto at (index_type index) -> value_type &
 Access a value with checks.
 
auto at (index_type index) const -> const value_type &
 Access a value with checks.
 
auto container () const noexcept -> const container_type &
 Get the internal container.
 
auto empty () const noexcept -> bool
 Check whether this object is empty.
 
auto get_or_prepare (index_type index) -> value_type &
 Access a value preparing it if needed.
 
auto max_index () const noexcept -> index_type
 Get the maximum index.
 
auto min_index () const noexcept -> index_type
 Get the minimum index. (Equal to the index of the origin.)
 
void move_position (index_type offset)
 Move the position of this object.
 
auto operator[] (index_type index) -> value_type &
 Access a value without checks.
 
auto operator[] (index_type index) const -> const value_type &
 Access a value without checks.
 
void push_back (const value_type &value)
 Add a value to the end.
 
void push_front (const value_type &value)
 Add a value to the beginning.
 
void resize (index_type min_index, index_type max_index, const value_type &value=value_type())
 Change the position of this object.
 

Private Member Functions

auto container_index (index_type index) const -> std::size_t
 Calculate the index in the container with checks.
 
auto is_safe_offset (index_type offset) const noexcept -> bool
 Check whether the given offset is safe to move.
 
void prepare_for (index_type index)
 Prepare space for an index.
 
void throw_out_of_range (index_type index) const
 Throw exception for indices out of range.
 
auto unsafe_container_index (index_type index) const noexcept -> std::size_t
 Calculate the index in the container without checks.
 

Private Attributes

container_type container_ {}
 Internal container.
 
index_type origin_index_ {0}
 Index of origin.
 

Detailed Description

template<typename Value, typename Container = std::deque<Value>>
class num_collect::util::bidirectional_vector< Value, Container >

Class to save data in a sequence which can be extended even toward negative direction.

This class generalizes std::vector class. Indices can be positive integers, zero, or negative integers.

Template Parameters
ValueType of values.
ContainerType of the internal container. (Assumed to be std::deque.)

Definition at line 47 of file bidirectional_vector.h.

Member Typedef Documentation

◆ container_type

template<typename Value , typename Container = std::deque<Value>>
using num_collect::util::bidirectional_vector< Value, Container >::container_type = Container

Type of the internal container.

Definition at line 53 of file bidirectional_vector.h.

◆ value_type

template<typename Value , typename Container = std::deque<Value>>
using num_collect::util::bidirectional_vector< Value, Container >::value_type = Value

Type of values.

Definition at line 50 of file bidirectional_vector.h.

Constructor & Destructor Documentation

◆ bidirectional_vector()

template<typename Value , typename Container = std::deque<Value>>
num_collect::util::bidirectional_vector< Value, Container >::bidirectional_vector ( container_type container,
index_type origin_index )
inline

Constructor.

Parameters
[in]containerInternal container.
[in]origin_indexIndex of origin.

Definition at line 66 of file bidirectional_vector.h.

Member Function Documentation

◆ at() [1/2]

template<typename Value , typename Container = std::deque<Value>>
auto num_collect::util::bidirectional_vector< Value, Container >::at ( index_type index) -> value_type&
inlinenodiscard

Access a value with checks.

This version throws for indices out of range.

Parameters
[in]indexIndex.
Returns
Value.

Definition at line 125 of file bidirectional_vector.h.

◆ at() [2/2]

template<typename Value , typename Container = std::deque<Value>>
auto num_collect::util::bidirectional_vector< Value, Container >::at ( index_type index) const -> const value_type&
inlinenodiscard

Access a value with checks.

This version throws for indices out of range.

Parameters
[in]indexIndex.
Returns
Value.

Definition at line 113 of file bidirectional_vector.h.

◆ container()

template<typename Value , typename Container = std::deque<Value>>
auto num_collect::util::bidirectional_vector< Value, Container >::container ( ) const -> const container_type&
inlinenodiscardnoexcept

Get the internal container.

Returns
Internal container.

Definition at line 74 of file bidirectional_vector.h.

◆ container_index()

template<typename Value , typename Container = std::deque<Value>>
auto num_collect::util::bidirectional_vector< Value, Container >::container_index ( index_type index) const -> std::size_t
inlinenodiscardprivate

Calculate the index in the container with checks.

Parameters
[in]indexIndex for this object.
Returns
Index in the container.

Definition at line 250 of file bidirectional_vector.h.

◆ empty()

template<typename Value , typename Container = std::deque<Value>>
auto num_collect::util::bidirectional_vector< Value, Container >::empty ( ) const -> bool
inlinenodiscardnoexcept

Check whether this object is empty.

Returns
Result.

Definition at line 83 of file bidirectional_vector.h.

◆ get_or_prepare()

template<typename Value , typename Container = std::deque<Value>>
auto num_collect::util::bidirectional_vector< Value, Container >::get_or_prepare ( index_type index) -> value_type&
inlinenodiscard

Access a value preparing it if needed.

Parameters
[in]indexIndex.
Returns
Value.

Definition at line 159 of file bidirectional_vector.h.

◆ is_safe_offset()

template<typename Value , typename Container = std::deque<Value>>
auto num_collect::util::bidirectional_vector< Value, Container >::is_safe_offset ( index_type offset) const -> bool
inlinenodiscardprivatenoexcept

Check whether the given offset is safe to move.

Parameters
[in]offsetOffset.
Returns
Result.

Definition at line 317 of file bidirectional_vector.h.

◆ max_index()

template<typename Value , typename Container = std::deque<Value>>
auto num_collect::util::bidirectional_vector< Value, Container >::max_index ( ) const -> index_type
inlinenodiscardnoexcept

Get the maximum index.

Returns
Maximum index.

Definition at line 101 of file bidirectional_vector.h.

◆ min_index()

template<typename Value , typename Container = std::deque<Value>>
auto num_collect::util::bidirectional_vector< Value, Container >::min_index ( ) const -> index_type
inlinenodiscardnoexcept

Get the minimum index. (Equal to the index of the origin.)

Returns
Minimum index.

Definition at line 92 of file bidirectional_vector.h.

◆ move_position()

template<typename Value , typename Container = std::deque<Value>>
void num_collect::util::bidirectional_vector< Value, Container >::move_position ( index_type offset)
inline

Move the position of this object.

Parameters
[in]offsetOffset from the current position.

Definition at line 232 of file bidirectional_vector.h.

◆ operator[]() [1/2]

template<typename Value , typename Container = std::deque<Value>>
auto num_collect::util::bidirectional_vector< Value, Container >::operator[] ( index_type index) -> value_type&
inlinenodiscard

Access a value without checks.

Access to indices out of range causes undefined behaviour.

Parameters
[in]indexIndex.
Returns
Value.

Definition at line 149 of file bidirectional_vector.h.

◆ operator[]() [2/2]

template<typename Value , typename Container = std::deque<Value>>
auto num_collect::util::bidirectional_vector< Value, Container >::operator[] ( index_type index) const -> const value_type&
inlinenodiscard

Access a value without checks.

Access to indices out of range causes undefined behaviour.

Parameters
[in]indexIndex.
Returns
Value.

Definition at line 137 of file bidirectional_vector.h.

◆ prepare_for()

template<typename Value , typename Container = std::deque<Value>>
void num_collect::util::bidirectional_vector< Value, Container >::prepare_for ( index_type index)
inlineprivate

Prepare space for an index.

Parameters
[in]indexIndex.

Definition at line 288 of file bidirectional_vector.h.

◆ push_back()

template<typename Value , typename Container = std::deque<Value>>
void num_collect::util::bidirectional_vector< Value, Container >::push_back ( const value_type & value)
inline

Add a value to the end.

Parameters
[in]valueValue.

Definition at line 225 of file bidirectional_vector.h.

◆ push_front()

template<typename Value , typename Container = std::deque<Value>>
void num_collect::util::bidirectional_vector< Value, Container >::push_front ( const value_type & value)
inline

Add a value to the beginning.

Parameters
[in]valueValue.

Definition at line 213 of file bidirectional_vector.h.

◆ resize()

template<typename Value , typename Container = std::deque<Value>>
void num_collect::util::bidirectional_vector< Value, Container >::resize ( index_type min_index,
index_type max_index,
const value_type & value = value_type() )
inline

Change the position of this object.

Parameters
[in]min_indexMinimum index.
[in]max_indexMaximum index.
[in]valueAdditional values.

Definition at line 171 of file bidirectional_vector.h.

◆ throw_out_of_range()

template<typename Value , typename Container = std::deque<Value>>
void num_collect::util::bidirectional_vector< Value, Container >::throw_out_of_range ( index_type index) const
inlineprivate

Throw exception for indices out of range.

Parameters
[in]indexIndex.

Definition at line 277 of file bidirectional_vector.h.

◆ unsafe_container_index()

template<typename Value , typename Container = std::deque<Value>>
auto num_collect::util::bidirectional_vector< Value, Container >::unsafe_container_index ( index_type index) const -> std::size_t
inlinenodiscardprivatenoexcept

Calculate the index in the container without checks.

Parameters
[in]indexIndex for this object.
Returns
Index in the container.

Definition at line 267 of file bidirectional_vector.h.

Member Data Documentation

◆ container_

template<typename Value , typename Container = std::deque<Value>>
container_type num_collect::util::bidirectional_vector< Value, Container >::container_ {}
private

Internal container.

Definition at line 239 of file bidirectional_vector.h.

◆ origin_index_

template<typename Value , typename Container = std::deque<Value>>
index_type num_collect::util::bidirectional_vector< Value, Container >::origin_index_ {0}
private

Index of origin.

Definition at line 242 of file bidirectional_vector.h.


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