param_package.h 1.4 KB

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