ladybird/Userland/Libraries/LibIPC/Dictionary.h
Lenny Maiorani dcdc62323d Libraries: Use default constructors/destructors in LibIPC
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-13 22:34:38 +01:00

46 lines
931 B
C++

/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/HashMap.h>
#include <AK/String.h>
namespace IPC {
class Dictionary {
public:
Dictionary() = default;
Dictionary(const HashMap<String, String>& initial_entries)
: m_entries(initial_entries)
{
}
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;
};
}