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

LibCore: Add a CConfigFile class, a simple INI file parser.

You open the configuration for an app like so:

    auto config = CConfigFile::get_for_app("MyApp");

This will then open ~/MyApp.ini and parse it for you.
Immediately start using it in Minesweeper to load the field size and mine
count from a config file.
This commit is contained in:
Andreas Kling 2019-04-15 02:22:08 +02:00
parent 37c27e2e39
commit bc5148354f
5 changed files with 269 additions and 3 deletions

View file

@ -1,8 +1,9 @@
#pragma once
#include "HashTable.h"
#include "StdLibExtras.h"
#include "kstdio.h"
#include <AK/HashTable.h>
#include <AK/StdLibExtras.h>
#include <AK/Vector.h>
#include <AK/kstdio.h>
namespace AK {
@ -88,6 +89,23 @@ public:
m_table.remove(it);
}
V& ensure(const K& key)
{
auto it = find(key);
if (it == end())
set(key, V());
return find(key)->value;
}
Vector<K> keys() const
{
Vector<K> list;
list.ensure_capacity(size());
for (auto& it : *this)
list.unchecked_append(it.key);
return list;
}
private:
HashTable<Entry, EntryTraits> m_table;
};