Luna/libos/include/os/Config.h
apio 7c0ff8c75a
All checks were successful
Build and test / build (push) Successful in 1m50s
libos+init: Add a standard API for config file access
2024-09-01 12:40:37 +02:00

44 lines
1.1 KiB
C++

/**
* @file Config.h
* @author apio (cloudapio.eu)
* @brief Configuration file parsing.
*
* @copyright Copyright (c) 2024, the Luna authors.
*
*/
#pragma once
#include <luna/HashMap.h>
#include <luna/RefString.h>
#include <os/File.h>
#include <os/Path.h>
namespace os
{
class ConfigFile
{
public:
static Result<OwnedPtr<ConfigFile>> open(os::Path path);
Option<StringView> read_string(StringView key);
StringView read_string_or(StringView key, StringView default_value);
Option<i64> read_number(StringView key);
i64 read_number_or(StringView key, i64 default_value);
Option<bool> read_boolean(StringView key);
bool read_boolean_or(StringView key, bool default_value);
Result<void> write_string(StringView key, StringView value);
Result<void> write_number(StringView key, int value);
Result<void> write_boolean(StringView key, bool value);
Result<void> sync();
private:
os::Path m_path { "" };
HashMap<RefString, RefString> m_data;
};
}