JODA  0.13.1 (59b41972)
JSON On-Demand Analysis
DirectoryRegister.h
Go to the documentation of this file.
1 //
2 // Created by Nico Schäfer on 08/01/18.
3 //
4 
5 #ifndef JODA_DIRECTORYREGISTER_H
6 #define JODA_DIRECTORYREGISTER_H
7 
8 #include <boost/optional.hpp>
9 #include <filesystem>
10 #include <mutex>
11 #include <unordered_set>
12 
13 namespace fs = std::filesystem;
14 
15 namespace joda::filesystem {
20 class DirectoryAlreadyInUseException : std::exception {};
21 
27  public:
29  static DirectoryRegister instance; // Guaranteed to be destroyed.
30  // Instantiated on first use.
31  return instance;
32  }
33 
35  void operator=(DirectoryRegister const&) = delete;
36 
40  virtual ~DirectoryRegister();
41 
42  // Register new directory
51  bool registerDirectory(const std::string& dir, bool checkDuplicate);
60  bool registerDirectory(const fs::path& dir, bool checkDuplicate);
61 
68  bool removeDirectory(const std::string& dir);
75  bool removeDirectory(const fs::path& dir);
76 
82  boost::optional<std::string> getTMPDir(const std::string& name);
89  std::string getUniqueDir();
90 
91  protected:
92  bool createDir(const fs::path& dir, bool checkExisting = false);
93  bool removeDir(const fs::path& dir);
94  std::unordered_set<std::string> dirs{};
95  unsigned long currID = 0;
96  std::mutex mut;
97 
98  private:
100 };
101 } // namespace joda::filesystem
102 
103 #endif // JODA_DIRECTORYREGISTER_H
Definition: DirectoryRegister.h:20
Definition: DirectoryRegister.h:26
bool removeDirectory(const std::string &dir)
Definition: DirectoryRegister.cpp:74
bool removeDir(const fs::path &dir)
Definition: DirectoryRegister.cpp:80
virtual ~DirectoryRegister()
Definition: DirectoryRegister.cpp:9
bool registerDirectory(const std::string &dir, bool checkDuplicate)
Definition: DirectoryRegister.cpp:52
std::string getUniqueDir()
Definition: DirectoryRegister.cpp:93
void operator=(DirectoryRegister const &)=delete
DirectoryRegister(DirectoryRegister const &)=delete
boost::optional< std::string > getTMPDir(const std::string &name)
Definition: DirectoryRegister.cpp:98
std::unordered_set< std::string > dirs
Definition: DirectoryRegister.h:94
bool createDir(const fs::path &dir, bool checkExisting=false)
Definition: DirectoryRegister.cpp:34
std::mutex mut
Definition: DirectoryRegister.h:96
static DirectoryRegister & getInstance()
Definition: DirectoryRegister.h:28
unsigned long currID
Definition: DirectoryRegister.h:95
Definition: DirectoryFileScanner.h:10