|
|
@ -35,6 +35,12 @@ Value& Value::operator=(const Value& other) |
|
|
|
return *this; |
|
|
|
return *this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Value::Value(Type type) |
|
|
|
|
|
|
|
: m_type(type) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
create(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Value::Value(bool value) |
|
|
|
Value::Value(bool value) |
|
|
|
: m_type(Type::Bool) |
|
|
|
: m_type(Type::Bool) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -180,16 +186,43 @@ const Value& Value::operator[](const std::string& key) const |
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------
|
|
|
|
// ------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Value::create() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
switch (m_type) { |
|
|
|
|
|
|
|
case Type::Bool: |
|
|
|
|
|
|
|
m_value.asBool = false; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case Type::Number: |
|
|
|
|
|
|
|
m_value.asDouble = 0.0; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case Type::String: |
|
|
|
|
|
|
|
m_value.asString = new std::string; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case Type::Array: |
|
|
|
|
|
|
|
m_value.asArray = new Array; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case Type::Object: |
|
|
|
|
|
|
|
m_value.asObject = new Object; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Value::clear() |
|
|
|
void Value::clear() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (m_type == Type::String) { |
|
|
|
switch (m_type) { |
|
|
|
|
|
|
|
case Type::String: |
|
|
|
delete m_value.asString; |
|
|
|
delete m_value.asString; |
|
|
|
} |
|
|
|
break; |
|
|
|
if (m_type == Type::Array) { |
|
|
|
case Type::Array: |
|
|
|
delete m_value.asArray; |
|
|
|
delete m_value.asArray; |
|
|
|
} |
|
|
|
break; |
|
|
|
if (m_type == Type::Object) { |
|
|
|
case Type::Object: |
|
|
|
delete m_value.asObject; |
|
|
|
delete m_value.asObject; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|