Dictionary.h 874 B

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