diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/folder/filelist.h | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/folder/filelist.h')
-rw-r--r-- | util/folder/filelist.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/util/folder/filelist.h b/util/folder/filelist.h new file mode 100644 index 0000000000..3f615fa4c2 --- /dev/null +++ b/util/folder/filelist.h @@ -0,0 +1,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) + { + } +}; |