summaryrefslogtreecommitdiff
path: root/src/cfg.hh
blob: a4a7865fe3007e08dff0b01fb684b1c59a900543 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef CFG_HH
#define CFG_HH

#include <memory>
#include <optional>
#include <string_view>
#include <vector>

namespace cfg {

class Config {
 public:
  virtual ~Config() = default;

  [[nodiscard]]
  virtual std::optional<std::string_view> get(std::string_view name) const = 0;

  [[nodiscard]]
  bool has(std::string_view name) const;
  [[nodiscard]]
  std::optional<int64_t> get_int64(std::string_view name) const;
  [[nodiscard]]
  std::optional<uint64_t> get_uint64(std::string_view name) const;
  [[nodiscard]]
  std::optional<bool> get_bool(std::string_view name) const;

  [[nodiscard]]
  static std::unique_ptr<Config> load(std::string_view name,
                                      std::vector<std::string>& errors);

 protected:
  Config() = default;

  Config(Config const&) = delete;
  Config& operator=(Config const&) = delete;
};

}  // namespace cfg

#endif  // CFG_HH