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
73
74
75
76
77
78
79
80
81
|
#pragma once
#include <util/generic/buffer.h>
#include <util/generic/string.h>
#include <util/generic/strbuf.h>
#include <util/generic/flags.h>
class TFileEntitiesList {
public:
enum EMaskFlag {
EM_FILES = 1,
EM_DIRS = 2,
EM_SLINKS = 4,
EM_FILES_DIRS = EM_FILES | EM_DIRS,
EM_FILES_SLINKS = EM_FILES | EM_SLINKS,
EM_DIRS_SLINKS = EM_DIRS | EM_SLINKS,
EM_FILES_DIRS_SLINKS = EM_FILES | EM_DIRS | EM_SLINKS
};
Y_DECLARE_FLAGS(EMask, EMaskFlag)
TFileEntitiesList(EMask mask)
: Mask(mask)
{
Clear();
}
void Clear() {
Cur = nullptr;
FileNamesSize = CurName = 0;
FileNames.Clear();
FileNames.Append("", 1);
}
const char* Next() {
return Cur = (CurName++ < FileNamesSize ? strchr(Cur, 0) + 1 : nullptr);
}
size_t Size() {
return FileNamesSize;
}
inline void Fill(const TString& dirname, bool sort = false) {
Fill(dirname, TStringBuf(), sort);
}
inline void Fill(const TString& dirname, TStringBuf prefix, bool sort = false) {
Fill(dirname, prefix, TStringBuf(), 1, sort);
}
void Fill(const TString& dirname, TStringBuf prefix, TStringBuf suffix, int depth, bool sort = false);
void Restart() {
Cur = FileNames.Data();
CurName = 0;
}
protected:
TBuffer FileNames;
size_t FileNamesSize, CurName;
const char* Cur;
EMask Mask;
};
Y_DECLARE_OPERATORS_FOR_FLAGS(TFileEntitiesList::EMask)
class TFileList: public TFileEntitiesList {
public:
TFileList()
: TFileEntitiesList(TFileEntitiesList::EM_FILES)
{
}
};
class TDirsList: public TFileEntitiesList {
public:
TDirsList()
: TFileEntitiesList(TFileEntitiesList::EM_DIRS)
{
}
};
|