CatapultServer  v0.5.0.1 (Elephant)
CatapultDataDirectory.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include <boost/filesystem/path.hpp>
23 #include <boost/filesystem.hpp>
24 
25 namespace catapult { namespace config {
26 
27  // region CatapultDirectory
28 
31  public:
33  explicit CatapultDirectory(const boost::filesystem::path& directory) : m_directory(directory)
34  {}
35 
36  public:
38  std::string str() const {
39  return m_directory.generic_string();
40  }
41 
43  const boost::filesystem::path& path() const {
44  return m_directory;
45  }
46 
48  std::string file(const std::string& name) const {
49  return (m_directory / name).generic_string();
50  }
51 
52  private:
53  boost::filesystem::path m_directory;
54  };
55 
56  // endregion
57 
58  // region CatapultDataDirectory
59 
62  public:
64  explicit CatapultDataDirectory(const boost::filesystem::path& directory) : m_directory(directory)
65  {}
66 
67  public:
71  }
72 
74  CatapultDirectory dir(const std::string& name) const {
75  return CatapultDirectory(m_directory / name);
76  }
77 
79  CatapultDirectory spoolDir(const std::string& name) const {
80  return CatapultDirectory(m_directory / "spool" / name);
81  }
82 
83  private:
84  boost::filesystem::path m_directory;
85  };
86 
87  // endregion
88 
89  // region CatapultDataDirectoryPreparer
90 
93  public:
95  static CatapultDataDirectory Prepare(const boost::filesystem::path& directory) {
96  CreateDirectory(directory / "spool");
97  return CatapultDataDirectory(directory);
98  }
99 
100  private:
101  static void CreateDirectory(const boost::filesystem::path& directory) {
102  if (!boost::filesystem::exists(directory))
103  boost::filesystem::create_directory(directory);
104  }
105  };
106 
107  // endregion
108 }}
catapult::config::CatapultDirectory::path
const boost::filesystem::path & path() const
Gets the directory path (as filesystem::path).
Definition: CatapultDataDirectory.h:43
catapult::config::CatapultDataDirectory::m_directory
boost::filesystem::path m_directory
Definition: CatapultDataDirectory.h:84
catapult::config::CatapultDataDirectory
Catapult data directory.
Definition: CatapultDataDirectory.h:61
catapult::config::CatapultDataDirectoryPreparer::Prepare
static CatapultDataDirectory Prepare(const boost::filesystem::path &directory)
Creates a data directory around directory.
Definition: CatapultDataDirectory.h:95
catapult::config::CatapultDataDirectory::CatapultDataDirectory
CatapultDataDirectory(const boost::filesystem::path &directory)
Creates a data directory around directory.
Definition: CatapultDataDirectory.h:64
catapult::config::CatapultDirectory::file
std::string file(const std::string &name) const
Gets the path for the file with name.
Definition: CatapultDataDirectory.h:48
catapult::config::CatapultDirectory::CatapultDirectory
CatapultDirectory(const boost::filesystem::path &directory)
Creates a directory around directory.
Definition: CatapultDataDirectory.h:33
catapult::config::CatapultDataDirectory::rootDir
CatapultDirectory rootDir() const
Gets the root data directory.
Definition: CatapultDataDirectory.h:69
catapult::config::CatapultDirectory::m_directory
boost::filesystem::path m_directory
Definition: CatapultDataDirectory.h:53
catapult::config::CatapultDirectory
Catapult directory.
Definition: CatapultDataDirectory.h:30
catapult::config::CatapultDirectory::str
std::string str() const
Gets the directory path (as string).
Definition: CatapultDataDirectory.h:38
catapult::config::CatapultDataDirectoryPreparer
Catapult data directory factory that automatically creates subdirectories.
Definition: CatapultDataDirectory.h:92
catapult::config::CatapultDataDirectory::dir
CatapultDirectory dir(const std::string &name) const
Gets the directory with name.
Definition: CatapultDataDirectory.h:74
catapult::config::CatapultDataDirectory::spoolDir
CatapultDirectory spoolDir(const std::string &name) const
Gets the spooling directory with name.
Definition: CatapultDataDirectory.h:79
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::config::CatapultDataDirectoryPreparer::CreateDirectory
static void CreateDirectory(const boost::filesystem::path &directory)
Definition: CatapultDataDirectory.h:101