-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectory.hpp
More file actions
72 lines (60 loc) · 2.07 KB
/
Directory.hpp
File metadata and controls
72 lines (60 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*******************************************************************************
* libunix++: C++ wrapper for Linux system calls
* Directory operations
*
* © 2019—2023, Sauron <libunixpp@saur0n.science>
******************************************************************************/
#ifndef __UNIXPP_DIRECTORY_HPP
#define __UNIXPP_DIRECTORY_HPP
#include <sys/types.h>
#include <dirent.h>
namespace upp {
class File;
/**/
class Directory {
public:
/**/
typedef struct dirent Entry;
/** Open a directory stream **/
explicit Directory(const char * directory);
/** Open a directory based on file opened with O_DIRECTORY flag **/
explicit Directory(File &file);
/** Close the directory stream **/
~Directory();
/** Read a directory entry from the directory **/
Entry * read();
/** Rewind to the beginning of the directory **/
void rewind();
/** Returns current location in the directory stream **/
long tell();
/** Seek to the given position on a directory **/
void seek(long position);
private:
Directory(DIR * dirp);
Directory(const Directory &other)=delete;
Directory &operator =(const Directory &other)=delete;
DIR * dirp;
};
/** List of files in the directory **/
class DirectoryList {
public:
/** Filter function **/
using Filter=int(const Directory::Entry *);
/** Comparison function **/
using Compare=int(const Directory::Entry **, const Directory::Entry **);
/** Scan a directory for matching entries **/
DirectoryList(const char * name, Filter filter=nullptr, Compare compare=nullptr);
/** Free the directory list **/
~DirectoryList();
/** Returns the length of the list **/
unsigned length() const { return count; }
/** Returns the i-th directory entry **/
const Directory::Entry &operator [](unsigned index) const { return *namelist[index]; }
private:
explicit DirectoryList(const DirectoryList &other)=delete;
DirectoryList &operator =(const DirectoryList &other)=delete;
unsigned count;
Directory::Entry ** namelist;
};
}
#endif