Horizon
tree_writer.hpp
1 #pragma once
2 #include <iostream>
3 #include <filesystem>
4 
5 namespace horizon {
6 namespace fs = std::filesystem;
7 class TreeWriter {
8  friend class TreeWriterPrefixed;
9 
10 public:
11  class FileProxy {
12  friend TreeWriter;
13 
14  private:
15  FileProxy(TreeWriter &writer, const fs::path &p);
16  TreeWriter &writer;
17 
18  public:
19  std::ostream &stream;
20 
21  ~FileProxy();
22 
23  FileProxy(FileProxy &&) = delete;
24  FileProxy &operator=(FileProxy &&) = delete;
25 
26  FileProxy(FileProxy const &) = delete;
27  FileProxy &operator=(FileProxy const &) = delete;
28  };
29 
30  [[nodiscard]] FileProxy create_file(const fs::path &path)
31  {
32  return FileProxy(*this, path);
33  }
34 
35 private:
36  virtual std::ostream &create_file_internal(const fs::path &path) = 0;
37  virtual void close_file() = 0;
38 };
39 
41 public:
42  TreeWriterPrefixed(TreeWriter &parent, const fs::path &prefix);
43 
44 private:
45  std::ostream &create_file_internal(const fs::path &path) override;
46  void close_file() override;
47 
48  TreeWriter &parent;
49  const fs::path prefix;
50 };
51 
52 } // namespace horizon
Definition: tree_writer.hpp:40
Definition: tree_writer.hpp:11
Definition: tree_writer.hpp:7