summaryrefslogtreecommitdiff
path: root/src/config.hh
blob: 011e8907d9b1cb46e40d9c2c333561cc5c1a1837 (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
// -*- mode: c++; c-basic-offset: 2; -*-

#ifndef CONFIG_HH
#define CONFIG_HH

#include <string>

class Config {
public:
  virtual ~Config() { }

  static Config* create();

  virtual bool load_name(std::string const& name) = 0;
  virtual bool load_file(std::string const& filename) = 0;

  virtual bool good() const = 0;
  virtual std::string const& last_error() const = 0;

  virtual std::string const& get(std::string const& key,
                                 std::string const& fallback) = 0;
  virtual char const* get(std::string const& key, char const* fallback) = 0;
  virtual bool get(std::string const& key, bool fallback) = 0;
  virtual bool is_set(std::string const& key) = 0;

  virtual void set(std::string const& key, std::string const& value) = 0;
  virtual void set(std::string const& key, bool value) {
    set(key, std::string(value ? "true" : "false"));
  }
  virtual void remove(std::string const& key) = 0;

protected:
  Config() { }
  Config(Config const&) = delete;
};

#endif  // CONFIG_HH