Skip to content

Commit

Permalink
[FEATURE] view::async_buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
h-2 committed Aug 29, 2019
1 parent 9a3642a commit aaa2ffa
Show file tree
Hide file tree
Showing 7 changed files with 738 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ If possible, provide tooling that performs the changes, e.g. a shell-script.
#### Core
* Added traits for "metaprogramming" with `seqan3::type_list` and type packs.

#### Input/Output

* Asynchronous input (background file reading) supported via seqan3::view::async_buffer.

## API changes

#### Argument parser
Expand Down
4 changes: 2 additions & 2 deletions include/seqan3/contrib/parallel/buffer_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class buffer_queue
buffer_queue() : buffer_queue{0u}
{}
buffer_queue(buffer_queue const &) = delete;
buffer_queue(buffer_queue &&) = default;
buffer_queue(buffer_queue &&) = delete;
buffer_queue & operator=(buffer_queue const &) = delete;
buffer_queue & operator=(buffer_queue &&) = default;
buffer_queue & operator=(buffer_queue &&) = delete;
~buffer_queue() = default;

// you can set the initial capacity here
Expand Down
60 changes: 50 additions & 10 deletions include/seqan3/range/detail/inherited_iterator_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ struct empty_type
* \snippet test/unit/range/detail/inherited_iterator_base_test.cpp inherited_iterator_base def
*/
template <typename derived_t, std::Iterator base_t>
class inherited_iterator_base : public std::conditional_t<std::is_pointer_v<base_t>, empty_type, base_t>
class inherited_iterator_base : public std::conditional_t<std::is_pointer_v<base_t> || !std::ForwardIterator<base_t>,
empty_type,
base_t>
{
static constexpr bool wrap_base = std::is_pointer_v<base_t> || !std::ForwardIterator<base_t>;
public:
/*!\name Associated types
* \brief All are derived from the base_t.
Expand Down Expand Up @@ -89,15 +92,15 @@ class inherited_iterator_base : public std::conditional_t<std::is_pointer_v<base
//!\brief Delegate to base class if inheriting from non-pointer iterator.
constexpr inherited_iterator_base(base_t it) noexcept(std::is_nothrow_move_constructible_v<base_t>)
//!\cond
requires !std::is_pointer_v<base_t>
requires !wrap_base
//!\endcond
: base_t{std::move(it)}
{}

//!\brief Initialise member if deriving from pointer.
constexpr inherited_iterator_base(base_t it) noexcept
//!\cond
requires std::is_pointer_v<base_t>
requires wrap_base
//!\endcond
: member{std::move(it)}
{}
Expand Down Expand Up @@ -183,11 +186,20 @@ class inherited_iterator_base : public std::conditional_t<std::is_pointer_v<base
return *this_derived();
}

//!\brief Post-increment, return previous iterator state.
constexpr void operator++(int) noexcept(noexcept(++std::declval<derived_t &>()))
//!\cond
requires std::InputIterator<base_t>
//!\endcond
{
++(*this_derived());
}

//!\brief Post-increment, return previous iterator state.
constexpr derived_t operator++(int) noexcept(noexcept(++std::declval<derived_t &>()) &&
noexcept(derived_t(std::declval<base_t &>())))
//!\cond
requires std::InputIterator<base_t>
requires std::ForwardIterator<base_t>
//!\endcond
{
derived_t cpy{*this_to_base()};
Expand Down Expand Up @@ -294,37 +306,65 @@ class inherited_iterator_base : public std::conditional_t<std::is_pointer_v<base
* \{
*/
//!\brief Dereference operator returns element currently pointed at.
constexpr reference operator*() const noexcept(noexcept(*std::declval<base_t &>()))
constexpr reference operator*() noexcept(noexcept(*std::declval<base_t &>()))
//!\cond
requires std::InputIterator<base_t>
//!\endcond
{
return **this_to_base();
}

//!\brief Dereference operator returns element currently pointed at.
constexpr reference operator*() const noexcept(noexcept(*std::declval<base_t const &>()))
//!\cond
requires std::InputIterator<base_t const>
//!\endcond
{
return **this_to_base();
}

//!\brief Return pointer to this iterator.
constexpr pointer operator->() const noexcept(noexcept(*std::declval<base_t &>()))
constexpr pointer operator->() noexcept(noexcept(*std::declval<base_t &>()))
//!\cond
requires std::InputIterator<base_t>
//!\endcond
{
return &*this_to_base();
}

//!\brief Return pointer to this iterator.
constexpr pointer operator->() const noexcept(noexcept(*std::declval<base_t const &>()))
//!\cond
requires std::InputIterator<base_t const>
//!\endcond
{
return &*this_to_base();
}

//!\brief Return underlying container value currently pointed at.
constexpr decltype(auto) operator[](std::make_signed_t<difference_type> const n) const
constexpr decltype(auto) operator[](std::make_signed_t<difference_type> const n)
noexcept(noexcept(*std::declval<derived_t &>()) && noexcept(std::declval<derived_t &>() + 3))
//!\cond
requires std::RandomAccessIterator<base_t>
//!\endcond
{
return *(*this_derived() + n);
}

//!\brief Return underlying container value currently pointed at.
constexpr decltype(auto) operator[](std::make_signed_t<difference_type> const n) const
noexcept(noexcept(*std::declval<derived_t const &>()) && noexcept(std::declval<derived_t const &>() + 3))
//!\cond
requires std::RandomAccessIterator<base_t const>
//!\endcond
{
return *(*this_derived() + n);
}
//!\}

private:
//!\brief If the base is a pointer, we wrap it instead of inheriting.
std::conditional_t<std::is_pointer_v<base_t>, base_t, empty_type> member;
std::conditional_t<wrap_base, base_t, empty_type> member;

//!\brief Befriend the derived type so it can access the private members.
friend derived_t;
Expand All @@ -344,7 +384,7 @@ class inherited_iterator_base : public std::conditional_t<std::is_pointer_v<base
//!\brief Cast this to base type.
constexpr base_t * this_to_base()
{
if constexpr (std::is_pointer_v<base_t>)
if constexpr (wrap_base)
return &member;
else
return static_cast<base_t*>(this);
Expand All @@ -353,7 +393,7 @@ class inherited_iterator_base : public std::conditional_t<std::is_pointer_v<base
//!\copydoc this_to_base
constexpr base_t const * this_to_base() const
{
if constexpr (std::is_pointer_v<base_t>)
if constexpr (wrap_base)
return &member;
else
return static_cast<base_t const *>(this);
Expand Down
Loading

0 comments on commit aaa2ffa

Please sign in to comment.