diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-04-15 02:22:08 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-04-15 02:23:20 +0200 |
commit | bc5148354f6ad777ed9ba2988bd0547b16956102 (patch) | |
tree | e688f5f1ca70dd6da6a08527bf49a8021046bae1 /AK | |
parent | 37c27e2e39e4f862574aca44076c5693c1befdad (diff) | |
download | serenity-bc5148354f6ad777ed9ba2988bd0547b16956102.zip |
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.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/HashMap.h | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/AK/HashMap.h b/AK/HashMap.h index 952777ab34..df802f6702 100644 --- a/AK/HashMap.h +++ b/AK/HashMap.h @@ -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; }; |