Added Json() methods to many methods, for loading and saving properties.

This commit is contained in:
Jonathan Thomas
2013-12-06 00:40:26 -06:00
parent 4e730a3f41
commit d8da4cb807
24 changed files with 712 additions and 45 deletions

View File

@@ -58,3 +58,54 @@ void EffectBase::DisplayInfo() {
cout << "----------------------------" << endl;
}
// Generate JSON string of this object
string EffectBase::Json() {
// Return formatted string
return JsonValue().toStyledString();
}
// Generate Json::JsonValue for this object
Json::Value EffectBase::JsonValue() {
// Create root json object
Json::Value root = ClipBase::JsonValue(); // get parent properties
root["order"] = Order();
// return JsonValue
return root;
}
// Load JSON string into this object
void EffectBase::Json(string value) throw(InvalidJSON) {
// Parse JSON string into JSON objects
Json::Value root;
Json::Reader reader;
bool success = reader.parse( value, root );
if (!success)
// Raise exception
throw InvalidJSON("JSON could not be parsed (or is invalid)", "");
try
{
// Set all values that match
Json(root);
}
catch (exception e)
{
// Error parsing JSON (or missing keys)
throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", "");
}
}
// Load Json::JsonValue into this object
void EffectBase::Json(Json::Value root) {
// Set parent data
ClipBase::Json(root);
// Set data from Json (if key is found)
if (root["order"] != Json::nullValue)
Order(root["order"].asInt());
}