|
- #pragma once
-
- #include <cppfs/directory.h>
-
- #include "directory.h"
-
- namespace asyncpp {
- namespace fs {
- namespace __directory {
-
- struct read_stream
- : public base_stream<
- cppfs::directory::entry,
- read_stream>
- {
- public:
- using value_type = cppfs::directory::entry;
- using this_type = read_stream;
- using base_future_type = base_stream<value_type, this_type>;
- using result_type = typename base_future_type::result_type;
-
- private:
- cppfs::directory::iterator _it;
- cppfs::directory::iterator _end;
-
- public:
- inline read_stream(
- const fs::directory& p_directory)
- {
- auto& d = p_directory.handle;
- if (d.exists())
- {
- _it = d.begin();
- _end = d.end();
- }
- }
-
- public:
- inline result_type poll()
- {
- if (_it == _end)
- return result_type::done();
-
- auto ret = result_type::ready(*_it);
- ++_it;
-
- return ret;
- }
- };
-
- template<
- chaining_mode X_mode,
- typename X_self>
- inline auto read_impl(X_self&& p_self)
- { return read_stream(std::forward<X_self>(p_self)); }
-
- } } }
-
- namespace asyncpp {
- namespace fs {
-
- template<chaining_mode X_mode>
- auto directory
- ::read() &
- {
- return __directory::read_impl<X_mode>(*this);
- }
-
- template<chaining_mode X_mode>
- auto directory
- ::read() &&
- {
- static_assert(
- X_mode != ref,
- "Can not store rvalue reference as lvalue reference!");
-
- return __directory::read_impl<X_mode>(std::move(*this));
- }
-
- } }
|