1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:07:35 +00:00

LibCore: Migrate ConfigFile to Core::Stream API :^)

As part of this, moved the call to `reparse()` out of the constructor
and into the factory methods, to allow the error to propagate.
This commit is contained in:
Sam Atkins 2022-02-06 15:27:17 +00:00 committed by Tim Flynn
parent cd0ffe5460
commit e548aab387
2 changed files with 48 additions and 33 deletions

View file

@ -1,6 +1,7 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Jakob-Niklas See <git@nwex.de>
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -12,7 +13,7 @@
#include <AK/RefPtr.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibCore/File.h>
#include <LibCore/Stream.h>
#include <LibGfx/Color.h>
namespace Core {
@ -57,14 +58,15 @@ public:
void remove_group(String const& group);
void remove_entry(String const& group, String const& key);
String filename() const { return m_file->filename(); }
String const& filename() const { return m_filename; }
private:
ConfigFile(String const& filename, NonnullRefPtr<File> open_file);
ConfigFile(String const& filename, OwnPtr<Stream::BufferedFile> open_file);
void reparse();
ErrorOr<void> reparse();
NonnullRefPtr<File> m_file;
String m_filename;
OwnPtr<Stream::BufferedFile> m_file;
HashMap<String, HashMap<String, String>> m_groups;
bool m_dirty { false };
};