summaryrefslogtreecommitdiff
path: root/src/cfg.hh
blob: 3be9a006e02847fe09d80ecae01b6eec7348fbb2 (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
41
42
43
44
45
#ifndef CFG_HH
#define CFG_HH

#include <filesystem>
#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;

 protected:
  Config() = default;

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

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

[[nodiscard]]
std::unique_ptr<Config> load_one(std::filesystem::path const& path,
                                 std::vector<std::string>& errors);

}  // namespace cfg

#endif  // CFG_HH