Horizon
structured_text_writer.hpp
1 #pragma once
2 #include <ostream>
3 
4 namespace horizon {
6 public:
7  StructuredTextWriter(std::ostream &s);
8  void write_line(const std::string &var, const std::string &value);
9  void write_line(const std::string &var, int value);
10  template <typename T> void write_line_enum(const std::string &var, const T &value)
11  {
12  write_line(var, enum_to_string(value));
13  }
14 
15  class ArrayProxy {
16  friend StructuredTextWriter;
17 
18  public:
19  ~ArrayProxy();
20 
21  private:
22  ArrayProxy(StructuredTextWriter &writer, const std::string &a);
23 
24  StructuredTextWriter &writer;
25 
26  ArrayProxy(ArrayProxy &&) = delete;
27  ArrayProxy &operator=(ArrayProxy &&) = delete;
28 
29  ArrayProxy(ArrayProxy const &) = delete;
30  ArrayProxy &operator=(ArrayProxy const &) = delete;
31  };
32 
33  [[nodiscard]] ArrayProxy make_array_proxy(const std::string &a)
34  {
35  return ArrayProxy(*this, a);
36  }
37 
38 private:
39  void write_indent();
40  void begin_array(const std::string &a);
41  void end_array();
42  std::ostream &ost;
43  bool in_array = false;
44 };
45 } // namespace horizon
Definition: structured_text_writer.hpp:15
Definition: structured_text_writer.hpp:5