Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
|
Implementation of a Copy-On-Write (CoW) read-write iterator over mutable value_type storage. More...
#include <cow_iterator.hpp>
Public Types | |
typedef CoW_container | cow_container_t |
typedef storage_t::difference_type | difference_type |
typedef sub_traits_t::iterator_category | iterator_category |
typedef storage_t::iterator | iterator_type |
Actual iterator type of the contained native iterator, probably a simple pointer. More... | |
typedef sub_traits_t::pointer | pointer |
typedef sub_traits_t::reference | reference |
typedef storage_t::size_type | size_type |
typedef Storage_ref_type | storage_ref_t |
typedef Storage_type | storage_t |
typedef sub_traits_t::value_type | value_type |
Public Member Functions | |
constexpr | cow_rw_iterator (const cow_rw_iterator &o) noexcept |
C++ named requirements: LegacyIterator: CopyConstructible. More... | |
constexpr | cow_rw_iterator (cow_rw_iterator &&o) noexcept |
C++ named requirements: LegacyIterator: MoveConstructable. More... | |
constexpr iterator_type | base () const noexcept |
Returns a copy of the underlying storage iterator. More... | |
constexpr cow_rw_iterator | begin () const noexcept |
Returns a new iterator pointing to the first element, aka begin. More... | |
constexpr bool | capacity_reached () const noexcept |
Returns true if storage capacity has been reached and the next push_back() will grow the storage and invalidates all iterators and references. More... | |
constexpr int | compare (const cow_rw_iterator &rhs) const noexcept |
Returns signum or three-way comparison value. More... | |
constexpr difference_type | dist_begin () const noexcept |
Returns the distance to_begin() using zero as first index. More... | |
constexpr difference_type | dist_end () const noexcept |
Returns the distance to_end() using zero as first index. More... | |
template<typename... Args> | |
constexpr void | emplace (Args &&... args) |
Like std::vector::emplace(), construct a new element in place. More... | |
template<typename... Args> | |
constexpr reference | emplace_back (Args &&... args) |
Like std::vector::emplace_back(), construct a new element in place at the end(). More... | |
constexpr bool | empty () const noexcept |
Returns true if storage is empty(). More... | |
constexpr cow_rw_iterator | end () const noexcept |
Returns a new iterator pointing to the element following the last element, aka end. More... | |
constexpr void | erase () |
Erases the element at the current position. More... | |
constexpr void | erase (size_type count) |
Like std::vector::erase(), removes the elements in the range [current, current+count). More... | |
std::string | get_info () const noexcept |
constexpr cow_ro_iterator< Storage_type, Storage_ref_type, CoW_container > | immutable () const noexcept |
Returns a new const_iterator pointing to the current position. More... | |
constexpr void | insert (const value_type &x) |
Inserts the element before the current position and moves all elements from there to the right beforehand. More... | |
template<class InputIt > | |
constexpr void | insert (InputIt first, InputIt last) |
Like std::vector::insert(), inserting the value_type range [first, last). More... | |
constexpr void | insert (value_type &&x) |
Inserts the element before the current position (std::move operation) and moves all elements from there to the right beforehand. More... | |
constexpr bool | is_begin () const noexcept |
Returns true, if this iterator points to begin(). More... | |
constexpr bool | is_end () const noexcept |
Returns true, if this iterator points to end(). More... | |
constexpr bool | operator!= (const cow_rw_iterator &rhs) const noexcept |
constexpr const reference | operator* () const noexcept |
Dereferencing iterator to value_type reference. More... | |
constexpr reference | operator* () noexcept |
Dereferencing iterator to value_type reference. More... | |
constexpr cow_rw_iterator | operator+ (difference_type rhs) const noexcept |
Binary 'iterator + element_count'; Try to avoid: Low performance due to returning copy-ctor. More... | |
constexpr cow_rw_iterator & | operator++ () noexcept |
Pre-increment; Well performing, return *this. More... | |
constexpr cow_rw_iterator | operator++ (int) noexcept |
Post-increment; Try to avoid: Low performance due to returning copy-ctor. More... | |
constexpr cow_rw_iterator & | operator+= (difference_type i) noexcept |
Addition-assignment of 'element_count'; Well performing, return *this. More... | |
constexpr difference_type | operator- (const cow_rw_iterator &rhs) const noexcept |
Binary 'iterator - iterator -> element_count'; Well performing, return element_count of type difference_type. More... | |
constexpr cow_rw_iterator | operator- (difference_type rhs) const noexcept |
Binary 'iterator - element_count'; Try to avoid: Low performance due to returning copy-ctor. More... | |
constexpr cow_rw_iterator & | operator-- () noexcept |
Pre-decrement; Well performing, return *this. More... | |
constexpr cow_rw_iterator | operator-- (int) noexcept |
Post-decrement; Try to avoid: Low performance due to returning copy-ctor. More... | |
constexpr cow_rw_iterator & | operator-= (difference_type i) noexcept |
Subtraction-assignment of 'element_count'; Well performing, return *this. More... | |
constexpr const pointer | operator-> () const noexcept |
Pointer to member access. More... | |
constexpr pointer | operator-> () noexcept |
Pointer to member access. More... | |
constexpr bool | operator< (const cow_rw_iterator &rhs) const noexcept |
constexpr bool | operator<= (const cow_rw_iterator &rhs) const noexcept |
constexpr cow_rw_iterator & | operator= (const cow_rw_iterator &o) noexcept |
Assigns content of other mutable iterator to this one, if they are not identical. More... | |
constexpr cow_rw_iterator & | operator= (cow_rw_iterator &&o) noexcept |
Assigns identity of given mutable iterator, if they are not identical. More... | |
constexpr bool | operator== (const cow_rw_iterator &rhs) const noexcept |
constexpr bool | operator> (const cow_rw_iterator &rhs) const noexcept |
constexpr bool | operator>= (const cow_rw_iterator &rhs) const noexcept |
constexpr const reference | operator[] (difference_type i) const noexcept |
Subscript of 'element_index', returning immutable Value_type reference. More... | |
constexpr reference | operator[] (difference_type i) noexcept |
Subscript of 'element_index', returning mutable Value_type reference. More... | |
constexpr void | pop_back () noexcept |
Removes the last element and sets this iterator to end() More... | |
constexpr void | push_back (const value_type &x) |
Like std::vector::push_back(), copy. More... | |
template<class InputIt > | |
constexpr void | push_back (InputIt first, InputIt last) |
Like std::vector::push_back(), but appends the value_type range [first, last). More... | |
constexpr void | push_back (value_type &&x) |
Like std::vector::push_back(), move. More... | |
constexpr size_type | size () const noexcept |
Return the size of the underlying value_type store. More... | |
constexpr storage_t & | storage () const noexcept |
Returns this instances' underlying shared storage by reference. More... | |
void | swap (cow_rw_iterator &o) noexcept |
C++ named requirements: LegacyIterator: Swappable. More... | |
constexpr cow_rw_iterator & | to_begin () noexcept |
This iterator is set to the first element, begin(). More... | |
constexpr cow_rw_iterator & | to_end () noexcept |
This iterator is set to the last element, end(). More... | |
std::string | toString () const noexcept |
void | write_back () noexcept |
Replace the parent's current store with this iterators' instance, unlock the CoW parents' write lock and discard all storage references. More... | |
Friends | |
template<typename , typename , typename , bool , bool > | |
class | cow_darray |
template<typename , typename > | |
class | cow_vector |
Implementation of a Copy-On-Write (CoW) read-write iterator over mutable value_type storage.
Instance holds a copy of the parents' CoW storage and locks its write mutex until write_back() or destruction.
Implementation complies with Type Traits iterator_category 'random_access_iterator_tag'
This iterator wraps the native iterator of type 'iterator_type' and manages the CoW related resource lifecycle.
After completing all mutable operations but before this iterator's destruction, the user might want to write back this iterators' storage to its parents' CoW using write_back()
Due to the costly nature of mutable CoW resource management, consider using jau::cow_ro_iterator if elements won't get mutated or any changes can be discarded.
To allow data-race free operations on this iterator's data copy from a potentially mutated CoW, only one begin iterator should be retrieved from CoW and all further operations shall use jau::cow_rw_iterator::size(), jau::cow_rw_iterator::begin() and jau::cow_rw_iterator::end().
Definition at line 86 of file cow_iterator.hpp.
typedef Storage_type jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::storage_t |
Definition at line 92 of file cow_iterator.hpp.
typedef Storage_ref_type jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::storage_ref_t |
Definition at line 93 of file cow_iterator.hpp.
typedef CoW_container jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::cow_container_t |
Definition at line 94 of file cow_iterator.hpp.
typedef storage_t::iterator jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::iterator_type |
Actual iterator type of the contained native iterator, probably a simple pointer.
Definition at line 97 of file cow_iterator.hpp.
typedef sub_traits_t::iterator_category jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::iterator_category |
Definition at line 116 of file cow_iterator.hpp.
typedef storage_t::size_type jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::size_type |
Definition at line 118 of file cow_iterator.hpp.
typedef storage_t::difference_type jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::difference_type |
Definition at line 119 of file cow_iterator.hpp.
typedef sub_traits_t::value_type jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::value_type |
Definition at line 123 of file cow_iterator.hpp.
typedef sub_traits_t::reference jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::reference |
Definition at line 124 of file cow_iterator.hpp.
typedef sub_traits_t::pointer jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::pointer |
Definition at line 125 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
C++ named requirements: LegacyIterator: CopyConstructible.
Definition at line 169 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
C++ named requirements: LegacyIterator: MoveConstructable.
Definition at line 196 of file cow_iterator.hpp.
|
inlinenoexcept |
Replace the parent's current store with this iterators' instance, unlock the CoW parents' write lock and discard all storage references.
After calling write_back(), this iterator is invalidated and no more operational.
It is the user's responsibility to issue call this method to update the CoW parents' storage.
It is not feasible nor effective to automatically earmark a dirty state on mutable operations.
This is due to the ambiguous semantics of like operator*()
.
Also usage of multiple iterators to one CoW instance during a mutable operation complicates such an automated task, especially as we wish to only realize one storage replacement at the end.
Lastly, the user probably wants to issue the CoW storage sync in a programmatic deterministic fashion at the end.
Definition at line 156 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Assigns content of other mutable iterator to this one, if they are not identical.
C++ named requirements: LegacyIterator: CopyAssignable
o | the new identity value to be copied into this iterator |
Definition at line 182 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Assigns identity of given mutable iterator, if they are not identical.
C++ named requirements: LegacyIterator: MoveAssignable
o | the new identity to be taken |
Definition at line 212 of file cow_iterator.hpp.
|
inlinenoexcept |
C++ named requirements: LegacyIterator: Swappable.
Definition at line 226 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns a new const_iterator pointing to the current position.
This is the only explicit conversion operation of mutable -> immutable iterator, see below.
Be aware that the resulting cow_ro_iterator points to transient storage of this immutable iterator. In case write_back() won't be called and this iterator destructs, the returned immutable iterator is invalidated.
Definition at line 244 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns a new iterator pointing to the first element, aka begin.
This is an addition API entry, allowing data-race free operations on this iterator's data snapshot from a potentially mutated CoW.
Definition at line 256 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns a new iterator pointing to the element following the last element, aka end.
This is an addition API entry, allowing data-race free operations on this iterator's data snapshot from a potentially mutated CoW.
Definition at line 268 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns true if storage is empty().
Definition at line 274 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns true if storage capacity has been reached and the next push_back() will grow the storage and invalidates all iterators and references.
Definition at line 280 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Return the size of the underlying value_type store.
This is an addition API entry, allowing data-race free arithmetic on this iterator's data snapshot from a potentially mutated CoW.
Definition at line 291 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns this instances' underlying shared storage by reference.
Definition at line 296 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns the distance to_end() using zero as first index.
A.k.a the remaining elements iterable.
Definition at line 303 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns true, if this iterator points to end().
Definition at line 308 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
This iterator is set to the last element, end().
Returns *this;
Definition at line 313 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns the distance to_begin() using zero as first index.
A.k.a the index from start.
Definition at line 319 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns true, if this iterator points to begin().
Definition at line 324 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
This iterator is set to the first element, begin().
Returns *this;
Definition at line 329 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns a copy of the underlying storage iterator.
Definition at line 335 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns signum or three-way comparison value.
0 if equal (both, store and iteratore), -1 if this->iterator_ < rhs_iter and 1 if this->iterator_ > rhs_iter (otherwise)
rhs_store | right-hand side store |
rhs_iter | right-hand side iterator |
Definition at line 349 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Definition at line 354 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Definition at line 357 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Definition at line 362 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Definition at line 365 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Definition at line 368 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Definition at line 371 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Dereferencing iterator to value_type reference.
Definition at line 380 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Pointer to member access.
Definition at line 388 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Dereferencing iterator to value_type reference.
Definition at line 396 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Pointer to member access.
Definition at line 402 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Post-increment; Try to avoid: Low performance due to returning copy-ctor.
Definition at line 413 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Post-decrement; Try to avoid: Low performance due to returning copy-ctor.
Definition at line 425 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Subscript of 'element_index', returning immutable Value_type reference.
Definition at line 431 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Subscript of 'element_index', returning mutable Value_type reference.
Definition at line 437 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Addition-assignment of 'element_count'; Well performing, return *this.
Definition at line 442 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Binary 'iterator + element_count'; Try to avoid: Low performance due to returning copy-ctor.
Definition at line 446 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Subtraction-assignment of 'element_count'; Well performing, return *this.
Definition at line 450 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Binary 'iterator - element_count'; Try to avoid: Low performance due to returning copy-ctor.
Definition at line 454 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Binary 'iterator - iterator -> element_count'; Well performing, return element_count of type difference_type.
Definition at line 460 of file cow_iterator.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
Definition at line 471 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Removes the last element and sets this iterator to end()
Definition at line 480 of file cow_iterator.hpp.
|
inlineconstexpr |
Erases the element at the current position.
This iterator is set to the element following the last removed element.
Definition at line 491 of file cow_iterator.hpp.
|
inlineconstexpr |
Like std::vector::erase(), removes the elements in the range [current, current+count).
This iterator is set to the element following the last removed element.
Definition at line 501 of file cow_iterator.hpp.
|
inlineconstexpr |
Inserts the element before the current position and moves all elements from there to the right beforehand.
size will be increased by one.
This iterator is set to the inserted element.
Definition at line 515 of file cow_iterator.hpp.
|
inlineconstexpr |
Inserts the element before the current position (std::move operation) and moves all elements from there to the right beforehand.
size will be increased by one.
This iterator is set to the inserted element.
Definition at line 529 of file cow_iterator.hpp.
|
inlineconstexpr |
Like std::vector::emplace(), construct a new element in place.
Constructs the element before the current position using placement new and moves all elements from there to the right beforehand.
size will be increased by one.
This iterator is set to the inserted element.
args | arguments to forward to the constructor of the element |
Definition at line 548 of file cow_iterator.hpp.
|
inlineconstexpr |
Like std::vector::insert(), inserting the value_type range [first, last).
This iterator is set to the first element inserted, or pos if first==last.
InputIt | foreign input-iterator to range of value_type [first, last) |
first | first foreign input-iterator to range of value_type [first, last) |
last | last foreign input-iterator to range of value_type [first, last) |
Definition at line 562 of file cow_iterator.hpp.
|
inlineconstexpr |
Like std::vector::push_back(), copy.
This iterator is set to the end.
x | the value to be added at the tail. |
Definition at line 573 of file cow_iterator.hpp.
|
inlineconstexpr |
Like std::vector::push_back(), move.
This iterator is set to the end.
x | the value to be added at the tail. |
Definition at line 585 of file cow_iterator.hpp.
|
inlineconstexpr |
Like std::vector::emplace_back(), construct a new element in place at the end().
Constructs the element at the end() using placement new.
size will be increased by one.
This iterator is set to the end.
args | arguments to forward to the constructor of the element |
Definition at line 604 of file cow_iterator.hpp.
|
inlineconstexpr |
Like std::vector::push_back(), but appends the value_type range [first, last).
This iterator is set to the end.
InputIt | foreign input-iterator to range of value_type [first, last) |
first | first foreign input-iterator to range of value_type [first, last) |
last | last foreign input-iterator to range of value_type [first, last) |
Definition at line 620 of file cow_iterator.hpp.
|
friend |
Definition at line 88 of file cow_iterator.hpp.
|
friend |
Definition at line 89 of file cow_iterator.hpp.