dir_files.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Directory files observer (The same as dir_enries but subdirs are ignored)
  2. //
  3. // Platform: ISO C++ 98/11 - POSIX
  4. // $Id$
  5. //
  6. // (c) __vic 2011
  7. #ifndef __VIC_POSIX_DIR_FILES_H
  8. #define __VIC_POSIX_DIR_FILES_H
  9. #include<__vic/defs.h>
  10. #include<__vic/posix/dir_entries.h>
  11. #include<__vic/string_buffer.h>
  12. #include<string>
  13. namespace __vic { namespace posix {
  14. //////////////////////////////////////////////////////////////////////////////
  15. class dir_files : private non_copyable
  16. {
  17. dir_entries de;
  18. std::string dir, pattern;
  19. string_buffer tmp; // for full path string building
  20. public:
  21. dir_files();
  22. explicit dir_files(const char * , const char * = nullptr);
  23. ~dir_files();
  24. #if __cpp_rvalue_references
  25. dir_files(dir_files && ) noexcept;
  26. dir_files &operator=(dir_files && ) noexcept;
  27. #endif
  28. bool reopen(const char * , const char * = nullptr);
  29. void close() { de.close(); }
  30. bool is_open() const { return de.is_open(); }
  31. const char *next(); // returns filename without path
  32. void rewind() { de.rewind(); }
  33. };
  34. //////////////////////////////////////////////////////////////////////////////
  35. }} // namespace
  36. #endif // header guard