JSONValue::JSONValue(const JSONValue &v) { m_type = v.getType(); switch (m_type) { case JSONValue::NULLTYPE: break; // nothing to do case JSONValue::BOOL: if (!v.getValue(m_bool)) throw(JSONCopyException("Failed to copy boolean")); break; case JSONValue::NUMBER: if (!v.getValue(m_num)) throw(JSONCopyException("Failed to copy float")); break; case JSONValue::STRING: mp_string = new string; if (!v.getValue(*mp_string)) { delete mp_string; // Make sure we don't leak memory in the event of a // failure throw(JSONCopyException("Failed to copy string")); } break; case JSONValue::ARRAY: mp_array = new JSONArray; if (!v.getValue(*mp_array)) { delete mp_array; throw(JSONCopyException("Failed to copy array")); } break; case JSONValue::OBJECT: mp_object = new JSONObject; if (!v.getValue(*mp_object)) { delete mp_object; throw(JSONCopyException("Failed to copy object")); } break; default: // Should never hit this! throw(JSONCopyException("Unknown JSON type!!")); } }