llarp/config/ini.hpp

Namespaces

Name
llarp
[crypto.hpp]

Classes

Name
struct llarp::ConfigParser

Source code

#pragma once

#include <string_view>
#include <string>
#include <functional>
#include <memory>
#include <unordered_map>
#include <vector>
#include <llarp/util/file.hpp>

namespace llarp
{
  struct ConfigParser
  {
    using SectionValues_t = std::unordered_multimap<std::string, std::string>;
    using Config_impl_t = std::unordered_map<std::string, SectionValues_t>;
    void
    Clear();

    bool
    LoadFile(const fs::path& fname);

    bool
    LoadNewFromStr(std::string_view str);

    bool
    LoadFromStr(std::string_view str);

    void
    IterAll(std::function<void(std::string_view, const SectionValues_t&)> visit);

    bool
    VisitSection(const char* name, std::function<bool(const SectionValues_t&)> visit) const;

    void
    AddOverride(fs::path file, std::string section, std::string key, std::string value);

    void
    Save();

    void
    SaveNew() const;

    inline void
    Filename(fs::path f)
    {
      m_FileName = f;
    };

   private:
    bool
    ParseAll();

    bool
    Parse();

    std::string m_Data;
    Config_impl_t m_Config;
    std::unordered_map<fs::path, Config_impl_t, util::FileHash> m_Overrides;
    fs::path m_FileName;
  };

}  // namespace llarp

Updated on 2026-01-10 at 22:49:45 +0000