param_package.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // SPDX-FileCopyrightText: 2017 Citra Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <initializer_list>
  5. #include <string>
  6. #include <unordered_map>
  7. namespace Common {
  8. /// A string-based key-value container supporting serializing to and deserializing from a string
  9. class ParamPackage {
  10. public:
  11. using DataType = std::unordered_map<std::string, std::string>;
  12. ParamPackage() = default;
  13. explicit ParamPackage(const std::string& serialized);
  14. ParamPackage(std::initializer_list<DataType::value_type> list);
  15. ParamPackage(const ParamPackage& other) = default;
  16. ParamPackage(ParamPackage&& other) noexcept = default;
  17. ParamPackage& operator=(const ParamPackage& other) = default;
  18. ParamPackage& operator=(ParamPackage&& other) = default;
  19. [[nodiscard]] std::string Serialize() const;
  20. [[nodiscard]] std::string Get(const std::string& key, const std::string& default_value) const;
  21. [[nodiscard]] int Get(const std::string& key, int default_value) const;
  22. [[nodiscard]] float Get(const std::string& key, float default_value) const;
  23. void Set(const std::string& key, std::string value);
  24. void Set(const std::string& key, int value);
  25. void Set(const std::string& key, float value);
  26. [[nodiscard]] bool Has(const std::string& key) const;
  27. void Erase(const std::string& key);
  28. void Clear();
  29. private:
  30. DataType data;
  31. };
  32. } // namespace Common