fsystem.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include "indep/common.hpp"
5#include "indep/macro.hpp"
6#ifdef BY_BUILD_PLATFORM_IS_WINDOWS
7# include <direct.h>
8# include <io.h>
9# define getcwd _getcwd
10#else
11# include <dirent.h>
12# include <unistd.h>
13#endif
14#include <vector>
15
16namespace by {
17
23 class _nout fsystem {
24 BY(ME(fsystem))
25
26 struct entry {
27#ifdef BY_BUILD_PLATFORM_IS_WINDOWS
28 _finddata_t file;
29 intptr_t dir;
30#else
31 DIR* dir;
32#endif
33 std::string path;
34 };
35
36 typedef std::vector<entry> entries;
37
42 class _nout iterator {
43 BY(ME(iterator))
44 friend class fsystem;
45
46 private:
47 iterator(const std::string& path);
48
49 public:
50 ~iterator();
51
52 public:
54 const std::string& operator*();
56 me& operator++(int);
58 operator nbool() const;
59
60 public:
62 void rel();
64 nbool next();
65 const std::string& get() const;
66 std::string getName() const;
67 std::string getDir() const;
69 nbool isEnd() const;
70
71 private:
72 void _addDir(const std::string& dirPath);
73 void _popDir();
74 std::string _filterPath(const std::string& org);
75
76 private:
77 entries _entries;
78 std::string _nowPath;
79 };
80
81 public:
84 static iterator find(const std::string& path);
86 static std::string getCurrentDir();
88 static const std::string& getDelimiter();
89 };
90} // namespace by
Cross-platform filesystem utilities for byeol language system.
Definition: fsystem.hpp:23
static std::string getCurrentDir()
Get current working directory.
static iterator find(const std::string &path)
Create iterator for filesystem traversal.
static const std::string & getDelimiter()
Get platform-specific path delimiter.