You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

81 lines
1.7 KiB

  1. #pragma once
  2. #include <cppfs/directory.h>
  3. #include "directory.h"
  4. namespace asyncpp {
  5. namespace fs {
  6. namespace __directory {
  7. struct read_stream
  8. : public base_stream<
  9. cppfs::directory::entry,
  10. read_stream>
  11. {
  12. public:
  13. using value_type = cppfs::directory::entry;
  14. using this_type = read_stream;
  15. using base_future_type = base_stream<value_type, this_type>;
  16. using result_type = typename base_future_type::result_type;
  17. private:
  18. cppfs::directory::iterator _it;
  19. cppfs::directory::iterator _end;
  20. public:
  21. inline read_stream(
  22. const fs::directory& p_directory)
  23. {
  24. auto& d = p_directory.handle;
  25. if (d.exists())
  26. {
  27. _it = d.begin();
  28. _end = d.end();
  29. }
  30. }
  31. public:
  32. inline result_type poll()
  33. {
  34. if (_it == _end)
  35. return result_type::done();
  36. auto ret = result_type::ready(*_it);
  37. ++_it;
  38. return ret;
  39. }
  40. };
  41. template<
  42. chaining_mode X_mode,
  43. typename X_self>
  44. inline auto read_impl(X_self&& p_self)
  45. { return read_stream(std::forward<X_self>(p_self)); }
  46. } } }
  47. namespace asyncpp {
  48. namespace fs {
  49. template<chaining_mode X_mode>
  50. auto directory
  51. ::read() &
  52. {
  53. return __directory::read_impl<X_mode>(*this);
  54. }
  55. template<chaining_mode X_mode>
  56. auto directory
  57. ::read() &&
  58. {
  59. static_assert(
  60. X_mode != ref,
  61. "Can not store rvalue reference as lvalue reference!");
  62. return __directory::read_impl<X_mode>(std::move(*this));
  63. }
  64. } }