Direct-BT
2.3.1
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 Storage_type | storage_t |
typedef Storage_ref_type | storage_ref_t |
typedef CoW_container | cow_container_t |
typedef storage_t::iterator | iterator_type |
Actual iterator type of the contained native iterator, probably a simple pointer. More... | |
typedef sub_traits_t::iterator_category | iterator_category |
typedef storage_t::size_type | size_type |
typedef storage_t::difference_type | difference_type |
typedef sub_traits_t::value_type | value_type |
typedef sub_traits_t::reference | reference |
typedef sub_traits_t::pointer | pointer |
Public Member Functions | |
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... | |
constexpr | cow_rw_iterator (const cow_rw_iterator &o) noexcept |
C++ named requirements: LegacyIterator: CopyConstructible. More... | |
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 (cow_rw_iterator &&o) noexcept |
C++ named requirements: LegacyIterator: MoveConstructable. More... | |
constexpr cow_rw_iterator & | operator= (cow_rw_iterator &&o) noexcept |
Assigns identity of given mutable iterator, if they are not identical. More... | |
void | swap (cow_rw_iterator &o) noexcept |
C++ named requirements: LegacyIterator: Swappable. More... | |
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 cow_rw_iterator | begin () const noexcept |
Returns a new iterator pointing to the first element, aka begin. More... | |
constexpr cow_rw_iterator | end () const noexcept |
Returns a new iterator pointing to the element following the last element, aka end. More... | |
constexpr bool | empty () const noexcept |
Returns true if storage is empty(). 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 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... | |
constexpr difference_type | dist_end () const noexcept |
Returns the distance to_end() using zero as first index. More... | |
constexpr bool | is_end () const noexcept |
Returns true, if this iterator points to end(). More... | |
constexpr cow_rw_iterator & | to_end () noexcept |
This iterator is set to the last element, end(). More... | |
constexpr difference_type | dist_begin () const noexcept |
Returns the distance to_begin() using zero as first index. More... | |
constexpr bool | is_begin () const noexcept |
Returns true, if this iterator points to begin(). More... | |
constexpr cow_rw_iterator & | to_begin () noexcept |
This iterator is set to the first element, begin(). More... | |
constexpr iterator_type | base () const noexcept |
Returns a copy of the underlying storage iterator. More... | |
constexpr int | compare (const cow_rw_iterator &rhs) const noexcept |
Returns signum or three-way comparison value. 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 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* () const noexcept |
Dereferencing iterator to value_type reference. More... | |
constexpr const pointer | operator-> () const noexcept |
Pointer to member access. More... | |
constexpr reference | operator* () noexcept |
Dereferencing iterator to value_type reference. More... | |
constexpr pointer | operator-> () noexcept |
Pointer to member access. 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-- () 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 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 cow_rw_iterator & | operator+= (difference_type i) noexcept |
Addition-assignment of 'element_count'; Well performing, return *this. 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-= (difference_type i) noexcept |
Subtraction-assignment of 'element_count'; Well performing, return *this. 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 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_cxx20 std::string | toString () const noexcept |
constexpr_cxx20 std::string | get_info () const noexcept |
constexpr void | pop_back () noexcept |
Removes the last element and sets this iterator to 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... | |
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... | |
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... | |
template<typename... Args> | |
constexpr void | emplace (Args &&... args) |
Like std::vector::emplace(), construct a new element in place. 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 | push_back (const value_type &x) |
Like std::vector::push_back(), copy. More... | |
constexpr void | push_back (value_type &&x) |
Like std::vector::push_back(), move. 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... | |
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... | |
Friends | |
template<typename , typename , typename , bool , 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 47 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 92 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 117 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 114 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 95 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 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 122 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 116 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 91 of file cow_iterator.hpp.
typedef Storage_type jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::storage_t |
Definition at line 90 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 121 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
C++ named requirements: LegacyIterator: CopyConstructible.
Definition at line 166 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
C++ named requirements: LegacyIterator: MoveConstructable.
Definition at line 193 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns a copy of the underlying storage iterator.
Definition at line 332 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 253 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 277 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 346 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 316 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 300 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 545 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 601 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns true if storage is empty().
Definition at line 271 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 265 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 488 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 498 of file cow_iterator.hpp.
|
inlinenoexcept |
Definition at line 468 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 241 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 512 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 559 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 526 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns true, if this iterator points to begin().
Definition at line 321 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns true, if this iterator points to end().
Definition at line 305 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Dereferencing iterator to value_type reference.
Definition at line 377 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Dereferencing iterator to value_type reference.
Definition at line 393 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Binary 'iterator + element_count'; Try to avoid: Low performance due to returning copy-ctor.
Definition at line 443 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Post-increment; Try to avoid: Low performance due to returning copy-ctor.
Definition at line 410 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Addition-assignment of 'element_count'; Well performing, return *this.
Definition at line 439 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Binary 'iterator - iterator -> element_count'; Well performing, return element_count of type difference_type.
Definition at line 457 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Binary 'iterator - element_count'; Try to avoid: Low performance due to returning copy-ctor.
Definition at line 451 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Post-decrement; Try to avoid: Low performance due to returning copy-ctor.
Definition at line 422 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Subtraction-assignment of 'element_count'; Well performing, return *this.
Definition at line 447 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Pointer to member access.
Definition at line 385 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Pointer to member access.
Definition at line 399 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
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 179 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 209 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Subscript of 'element_index', returning immutable Value_type reference.
Definition at line 428 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Subscript of 'element_index', returning mutable Value_type reference.
Definition at line 434 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Removes the last element and sets this iterator to end()
Definition at line 477 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 570 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 617 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 582 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 288 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns this instances' underlying shared storage by reference.
Definition at line 293 of file cow_iterator.hpp.
|
inlinenoexcept |
C++ named requirements: LegacyIterator: Swappable.
Definition at line 223 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
This iterator is set to the first element, begin().
Returns *this;
Definition at line 326 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
This iterator is set to the last element, end().
Returns *this;
Definition at line 310 of file cow_iterator.hpp.
|
inlinenoexcept |
|
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 153 of file cow_iterator.hpp.
|
friend |
Definition at line 86 of file cow_iterator.hpp.
|
friend |
Definition at line 87 of file cow_iterator.hpp.