- HashMap<String, String> m_stringValues;
- HashMap<String, bool> m_boolValues;
- HashMap<String, uint32_t> m_uint32Values;
- HashMap<String, double> m_doubleValues;
- HashMap<String, float> m_floatValues;
+ struct Value {
+ enum class Type {
+ None,
+ String,
+ Bool,
+ UInt32,
+ Double,
+ };
+
+ void encode(IPC::ArgumentEncoder&) const;
+ static bool decode(IPC::ArgumentDecoder&, Value&);
+
+ explicit Value() : m_type(Type::None) { }
+ explicit Value(const String& value) : m_type(Type::String), m_string(value) { }
+ explicit Value(bool value) : m_type(Type::Bool), m_bool(value) { }
+ explicit Value(uint32_t value) : m_type(Type::UInt32), m_uint32(value) { }
+ explicit Value(double value) : m_type(Type::Double), m_double(value) { }
+
+ Value(Value&& value)
+ : m_type(value.m_type)
+ {
+ switch (m_type) {
+ case Type::None:
+ break;
+ case Type::String:
+ new (&m_string) String(std::move(value.m_string));
+ break;
+ case Type::Bool:
+ m_bool = value.m_bool;
+ break;
+ case Type::UInt32:
+ m_uint32 = value.m_uint32;
+ break;
+ case Type::Double:
+ m_double = value.m_double;
+ break;
+ }
+ }
+
+ Value& operator=(const Value& other)
+ {
+ if (this == &other)
+ return *this;
+
+ destroy();
+
+ m_type = other.m_type;
+ switch (m_type) {
+ case Type::None:
+ break;
+ case Type::String:
+ new (&m_string) String(other.m_string);
+ break;
+ case Type::Bool:
+ m_bool = other.m_bool;
+ break;
+ case Type::UInt32:
+ m_uint32 = other.m_uint32;
+ break;
+ case Type::Double:
+ m_double = other.m_double;
+ break;
+ }
+
+ return *this;
+ }
+
+ ~Value()
+ {
+ destroy();
+ }
+
+ Type type() const { return m_type; }
+
+ String asString() const
+ {
+ ASSERT(m_type == Type::String);
+ return m_string;
+ }
+
+ bool asBool() const
+ {
+ ASSERT(m_type == Type::Bool);
+ return m_bool;
+ }
+
+ uint32_t asUInt32() const
+ {
+ ASSERT(m_type == Type::UInt32);
+ return m_uint32;
+ }
+
+ double asDouble() const
+ {
+ ASSERT(m_type == Type::Double);
+ return m_double;
+ }
+
+ private:
+ void destroy()
+ {
+ if (m_type == Type::String)
+ m_string.~String();
+ }
+
+ Type m_type;
+ union {
+ String m_string;
+ bool m_bool;
+ uint32_t m_uint32;
+ double m_double;
+ };
+ };
+
+ typedef HashMap<String, Value> ValueMap;
+ ValueMap m_values;
+ ValueMap m_overridenDefaults;