mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-19 09:25:28 +00:00
54186c4a89
When we add loki-mq has a dependency we can just alias it, but for now it's easier to copy the header than add the whole submodule library.
55 lines
1.2 KiB
C++
55 lines
1.2 KiB
C++
#ifndef LOKINET_BOOTSERV_CONFIG_HPP
|
|
#define LOKINET_BOOTSERV_CONFIG_HPP
|
|
|
|
#include <util/string_view.hpp>
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
namespace llarp
|
|
{
|
|
struct ConfigParser
|
|
{
|
|
using Section_t = std::unordered_multimap< std::string, std::string >;
|
|
using Config_impl_t = std::unordered_map< std::string, Section_t >;
|
|
/// clear parser
|
|
void
|
|
Clear();
|
|
|
|
/// load config file for bootserv
|
|
/// return true on success
|
|
/// return false on error
|
|
bool
|
|
LoadFile(string_view fname);
|
|
|
|
/// load from string
|
|
/// return true on success
|
|
/// return false on error
|
|
bool
|
|
LoadFromStr(string_view str);
|
|
|
|
/// iterate all sections and thier values
|
|
void
|
|
IterAll(std::function< void(string_view, const Section_t&) > visit);
|
|
|
|
/// 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 Section_t&) > visit) const;
|
|
|
|
private:
|
|
bool
|
|
Parse();
|
|
|
|
std::vector< char > m_Data;
|
|
Config_impl_t m_Config;
|
|
std::string m_FileName;
|
|
};
|
|
|
|
} // namespace llarp
|
|
|
|
#endif
|