Dictionary.h 931 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/HashMap.h>
  9. #include <AK/String.h>
  10. namespace IPC {
  11. class Dictionary {
  12. public:
  13. Dictionary() = default;
  14. Dictionary(HashMap<String, String> const& initial_entries)
  15. : m_entries(initial_entries)
  16. {
  17. }
  18. bool is_empty() const { return m_entries.is_empty(); }
  19. size_t size() const { return m_entries.size(); }
  20. void add(String key, String value)
  21. {
  22. m_entries.set(move(key), move(value));
  23. }
  24. template<typename Callback>
  25. void for_each_entry(Callback callback) const
  26. {
  27. for (auto& it : m_entries) {
  28. callback(it.key, it.value);
  29. }
  30. }
  31. HashMap<String, String> const& entries() const { return m_entries; }
  32. private:
  33. HashMap<String, String> m_entries;
  34. };
  35. }