param_package.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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) = default;
  18. ParamPackage& operator=(const ParamPackage& other) = default;
  19. ParamPackage& operator=(ParamPackage&& other) = default;
  20. std::string Serialize() const;
  21. std::string Get(const std::string& key, const std::string& default_value) const;
  22. int Get(const std::string& key, int default_value) const;
  23. float Get(const std::string& key, float default_value) const;
  24. void Set(const std::string& key, const std::string& value);
  25. void Set(const std::string& key, int value);
  26. void Set(const std::string& key, float value);
  27. bool Has(const std::string& key) const;
  28. private:
  29. DataType data;
  30. };
  31. } // namespace Common