Loading...
Searching...
No Matches
fsystem.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include <regex>
5#include "indep/common.hpp"
6#include "indep/macro.hpp"
7#include "indep/helper/tmay.inl"
8#ifdef BY_BUILD_PLATFORM_IS_WINDOWS
9# include <direct.h>
10# include <io.h>
11# define getcwd _getcwd
12#else
13# include <dirent.h>
14# include <unistd.h>
15#endif
16#include <vector>
17
18namespace by {
19
52 class _nout fsystem {
53 BY(ME(fsystem))
54
55 struct entry {
56#ifdef BY_BUILD_PLATFORM_IS_WINDOWS
58 intptr_t dir;
59#else
60 DIR* dir;
61#endif
62 std::string path;
63 };
64
65 typedef std::vector<entry> entries;
66
72 class _nout iterator {
73 BY(ME(iterator))
74
75 public:
79 iterator(const std::string& path);
80 ~iterator();
81
82 public:
83 const std::string& operator*();
84 me& operator++(int);
85 operator nbool() const;
86 const std::string* operator->() const;
87
88 public:
89 void rel();
90
96 nbool next();
97
98 const std::string& get() const;
99 std::string getName() const;
100 std::string getDir() const;
101 nbool isEnd() const;
102
103 private:
104 void _addDir(const std::string& dirPath);
105 void _popDir();
106 std::string _filterPath(const std::string& org);
107 nbool _isGlobPattern(const std::string& path);
108 std::regex _convertToRegex(const std::string& globPattern);
109
110 private:
111 entries _entries;
112 std::string _nowPath;
113 tmay<std::regex> _pattern;
114 };
115
116 public:
122 static iterator find(const std::string& path);
123
124 static std::string getCurrentDir();
125 static const std::string& getDelimiter();
126 };
127} // namespace by
Cross-platform filesystem utilities for recursive file traversal.
Definition fsystem.hpp:52
static iterator find(const std::string &path)
Creates iterator for recursive filesystem traversal.
Rich logging support with polymorphic type conversion.
Definition richLog.hpp:34