summaryrefslogtreecommitdiff
path: root/src/config.hh
blob: fd0f067c99d2a58d08c43c343e051cc73594b0df (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
46
47
48
#ifndef CONFIG_HH
#define CONFIG_HH

#include <filesystem>
#include <memory>
#include <optional>
#include <stdint.h>
#include <string>
#include <string_view>
#include <unordered_map>

class Logger;

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

  static std::unique_ptr<Config> create(Logger* logger,
                                        std::filesystem::path const& filepath);

  static std::unique_ptr<Config> create(
      std::unordered_map<std::string, std::string> data,
      std::filesystem::path root);
  static std::unique_ptr<Config> create_empty();

  virtual std::string_view get(std::string const& key,
                               std::string_view default_) const = 0;
  virtual char const* get(std::string const& key,
                          char const* default_) const = 0;
  virtual std::optional<uint64_t> get(std::string const& key,
                                      uint64_t default_) const = 0;

  virtual std::optional<uint64_t> get_size(std::string const& key,
                                           uint64_t default_) const = 0;

  virtual std::optional<double> get_duration(std::string const& key,
                                             double default_) const = 0;

  virtual std::filesystem::path get_path(std::string const& key,
                                         std::string_view default_) const = 0;

protected:
  Config() = default;
  Config(Config const&) = delete;
  Config& operator=(Config const&) = delete;
};

#endif  // CONFIG_HH