2020-05-03 22:15:27 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
2022-03-03 11:37:49 -07:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-05-03 22:15:27 +02:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-05-03 22:15:27 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-01-01 23:36:21 -05:00
|
|
|
#include <AK/Concepts.h>
|
2022-12-04 18:02:33 +00:00
|
|
|
#include <AK/DeprecatedString.h>
|
2020-05-03 22:15:27 +02:00
|
|
|
#include <AK/HashMap.h>
|
|
|
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
|
|
|
|
|
|
class Dictionary {
|
|
|
|
|
public:
|
2022-03-03 11:37:49 -07:00
|
|
|
Dictionary() = default;
|
2020-09-05 16:26:22 +02:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
Dictionary(HashMap<DeprecatedString, DeprecatedString> const& initial_entries)
|
2020-09-05 16:26:22 +02:00
|
|
|
: m_entries(initial_entries)
|
|
|
|
|
{
|
|
|
|
|
}
|
2020-05-03 22:15:27 +02:00
|
|
|
|
|
|
|
|
bool is_empty() const { return m_entries.is_empty(); }
|
|
|
|
|
size_t size() const { return m_entries.size(); }
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
void add(DeprecatedString key, DeprecatedString value)
|
2020-05-03 22:15:27 +02:00
|
|
|
{
|
|
|
|
|
m_entries.set(move(key), move(value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Callback>
|
|
|
|
|
void for_each_entry(Callback callback) const
|
|
|
|
|
{
|
|
|
|
|
for (auto& it : m_entries) {
|
|
|
|
|
callback(it.key, it.value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-01 23:36:21 -05:00
|
|
|
template<FallibleFunction<DeprecatedString const&, DeprecatedString const&> Callback>
|
|
|
|
|
ErrorOr<void> try_for_each_entry(Callback&& callback) const
|
|
|
|
|
{
|
|
|
|
|
for (auto const& it : m_entries)
|
|
|
|
|
TRY(callback(it.key, it.value));
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
HashMap<DeprecatedString, DeprecatedString> const& entries() const { return m_entries; }
|
2020-05-03 22:15:27 +02:00
|
|
|
|
|
|
|
|
private:
|
2022-12-04 18:02:33 +00:00
|
|
|
HashMap<DeprecatedString, DeprecatedString> m_entries;
|
2020-05-03 22:15:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|