mirror of https://github.com/oxen-io/lokinet
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.
58 lines
1.3 KiB
C++
58 lines
1.3 KiB
C++
5 years ago
|
#ifndef LOKINET_BOOTSERV_CONFIG_HPP
|
||
|
#define LOKINET_BOOTSERV_CONFIG_HPP
|
||
5 years ago
|
|
||
5 years ago
|
#include <util/string_view.hpp>
|
||
5 years ago
|
|
||
5 years ago
|
#include <functional>
|
||
|
#include <memory>
|
||
5 years ago
|
#include <unordered_map>
|
||
6 years ago
|
#include <vector>
|
||
7 years ago
|
|
||
5 years ago
|
namespace llarp
|
||
6 years ago
|
{
|
||
5 years ago
|
struct ConfigParser
|
||
6 years ago
|
{
|
||
5 years ago
|
using String_t = llarp::string_view;
|
||
|
using Section_t =
|
||
|
std::unordered_multimap< String_t, String_t, string_view_hash >;
|
||
|
using Config_impl_t =
|
||
|
std::unordered_map< String_t, Section_t, string_view_hash >;
|
||
5 years ago
|
/// clear parser
|
||
|
void
|
||
|
Clear();
|
||
6 years ago
|
|
||
5 years ago
|
/// load config file for bootserv
|
||
|
/// return true on success
|
||
|
/// return false on error
|
||
|
bool
|
||
5 years ago
|
LoadFile(string_view fname);
|
||
6 years ago
|
|
||
5 years ago
|
/// load from string
|
||
|
/// return true on success
|
||
|
/// return false on error
|
||
|
bool
|
||
5 years ago
|
LoadString(string_view str);
|
||
6 years ago
|
|
||
5 years ago
|
/// iterate all sections and thier values
|
||
6 years ago
|
void
|
||
5 years ago
|
IterAll(std::function< void(const String_t&, const Section_t&) > visit);
|
||
6 years ago
|
|
||
5 years ago
|
/// visit a section in config read only by name
|
||
|
/// return false if no section or value propagated from visitor
|
||
6 years ago
|
bool
|
||
5 years ago
|
VisitSection(const char* name,
|
||
|
std::function< bool(const Section_t&) > visit) const;
|
||
6 years ago
|
|
||
|
private:
|
||
5 years ago
|
bool
|
||
|
Parse();
|
||
6 years ago
|
|
||
5 years ago
|
std::vector< char > m_Data;
|
||
|
Config_impl_t m_Config;
|
||
5 years ago
|
std::string m_FileName;
|
||
6 years ago
|
};
|
||
|
|
||
5 years ago
|
} // namespace llarp
|
||
7 years ago
|
|
||
5 years ago
|
#endif
|