44 lines
1.3 KiB
C++
44 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
|
|
namespace ddkit {
|
|
namespace base {
|
|
|
|
class IConfig {
|
|
public:
|
|
virtual ~IConfig() = default;
|
|
|
|
virtual bool hasKey(const std::string& key) const = 0;
|
|
|
|
// getters which throw if the key does not exist
|
|
virtual std::string getStringValue(const std::string& key) const = 0;
|
|
virtual int getIntValue(const std::string& key) const = 0;
|
|
virtual int64_t getInt64Value(const std::string& key) const = 0;
|
|
virtual bool getBoolValue(const std::string& key) const = 0;
|
|
|
|
// getters which return a default if the key does not exist
|
|
std::string getStringValue(const std::string& key, const std::string& defaultValue) const {
|
|
if (hasKey(key)) return getStringValue(key);
|
|
return defaultValue;
|
|
}
|
|
|
|
int getIntValue(const std::string& key, int defaultValue) const {
|
|
if (hasKey(key)) return getIntValue(key);
|
|
return defaultValue;
|
|
}
|
|
|
|
int64_t getInt64Value(const std::string& key, int64_t defaultValue) const {
|
|
if (hasKey(key)) return getInt64Value(key);
|
|
return defaultValue;
|
|
}
|
|
|
|
bool getBoolValue(const std::string& key, bool defaultValue) const {
|
|
if (hasKey(key)) return getBoolValue(key);
|
|
return defaultValue;
|
|
}
|
|
};
|
|
|
|
} // namespace base
|
|
} // namespace ddkit
|