You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lokinet/llarp/config/ini.hpp

64 lines
1.5 KiB
C++

5 years ago
#ifndef LOKINET_BOOTSERV_CONFIG_HPP
#define LOKINET_BOOTSERV_CONFIG_HPP
#include <string_view>
#include <string>
5 years ago
#include <functional>
#include <memory>
#include <unordered_map>
#include <vector>
#include <util/fs.hpp>
7 years ago
5 years ago
namespace llarp
{
5 years ago
struct ConfigParser
{
using SectionValues_t = std::unordered_multimap<std::string, std::string>;
using Config_impl_t = std::unordered_map<std::string, SectionValues_t>;
5 years ago
/// clear parser
void
Clear();
5 years ago
/// load config file for bootserv
/// return true on success
/// return false on error
bool
LoadFile(const fs::path fname);
5 years ago
/// load from string
/// return true on success
/// return false on error
bool
LoadFromStr(std::string_view str);
5 years ago
/// iterate all sections and thier values
void
IterAll(std::function<void(std::string_view, const SectionValues_t&)> visit);
5 years ago
/// visit a section in config read only by name
/// return false if no section or value propagated from visitor
bool
VisitSection(const char* name, std::function<bool(const SectionValues_t&)> visit) const;
/// add a config option that is appended at the end of the config buffer with no comments
void
AddOverride(std::string section, std::string key, std::string value);
/// save config and any overrides to the file it was loaded from
void
Save() const;
private:
5 years ago
bool
Parse();
std::vector<char> m_Data;
5 years ago
Config_impl_t m_Config;
Config_impl_t m_Overrides;
fs::path m_FileName;
};
5 years ago
} // namespace llarp
7 years ago
5 years ago
#endif