Enhance Json data handling

- Parsing from string to Json::Value is now done by utility function
  openshot::stringToJson() in Json.cpp, all SetJson() methods call it.
- Expand use of const member functions and args where appropriate.
- Use std::to_string() to format int/float values as strings.
- Correct mentions of nonexistent Json::JsonValue type in docstrings
This commit is contained in:
FeRD (Frank Dana)
2019-12-27 08:51:51 -05:00
parent a1158ee278
commit 22bf6edfba
81 changed files with 483 additions and 945 deletions

View File

@@ -187,14 +187,14 @@ std::shared_ptr<Frame> TextReader::GetFrame(int64_t requested_frame)
}
// Generate JSON string of this object
std::string TextReader::Json() {
std::string TextReader::Json() const {
// Return formatted string
return JsonValue().toStyledString();
}
// Generate Json::JsonValue for this object
Json::Value TextReader::JsonValue() {
// Generate Json::Value for this object
Json::Value TextReader::JsonValue() const {
// Create root json object
Json::Value root = ReaderBase::JsonValue(); // get parent properties
@@ -216,24 +216,10 @@ Json::Value TextReader::JsonValue() {
}
// Load JSON string into this object
void TextReader::SetJson(std::string value) {
// Parse JSON string into JSON objects
Json::Value root;
Json::CharReaderBuilder rbuilder;
Json::CharReader* reader(rbuilder.newCharReader());
std::string errors;
bool success = reader->parse( value.c_str(),
value.c_str() + value.size(), &root, &errors );
delete reader;
if (!success)
// Raise exception
throw InvalidJSON("JSON could not be parsed (or is invalid)");
void TextReader::SetJson(const std::string value) {
try
{
Json::Value root = openshot::stringToJson(value);
// Set all values that match
SetJsonValue(root);
}
@@ -244,8 +230,8 @@ void TextReader::SetJson(std::string value) {
}
}
// Load Json::JsonValue into this object
void TextReader::SetJsonValue(Json::Value root) {
// Load Json::Value into this object
void TextReader::SetJsonValue(const Json::Value root) {
// Set parent data
ReaderBase::SetJsonValue(root);