2020-05-03 22:15:27 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-05-03 22:15:27 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/HashMap.h>
|
|
|
|
|
#include <AK/String.h>
|
|
|
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
|
|
|
|
|
|
class Dictionary {
|
|
|
|
|
public:
|
2020-09-05 16:26:22 +02:00
|
|
|
Dictionary() { }
|
|
|
|
|
|
|
|
|
|
Dictionary(const HashMap<String, String>& initial_entries)
|
|
|
|
|
: 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(); }
|
|
|
|
|
|
|
|
|
|
void add(String key, String value)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const HashMap<String, String>& entries() const { return m_entries; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
HashMap<String, String> m_entries;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|