Behind-the-scenes code tidying for Json data handling #396
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes several sweeping (but fairly minor) changes to the way Json data-passing is implemented across the codebase:
std::string
toJson::Value
is now done by a new utility functionopenshot::stringToJson()
, which in turn lives in a new source filesrc/Json.cpp
. AllSetJson()
methods in the library now call that function instead of repeating the same parsing boilerplate everywhere.openshot::stringToJson()
is now the only place in thesrc/
directory where theJson::Value::parse()
method is called, and the only place where the code builds aJson::CharReader
object fromJson::CharReaderBuilder
. (There's one method insrc/ChunkReader.cpp
which parses an input file stream using aJson::CharReaderBuilder
withJson::parseFromStream()
.)src/
directory" qualifier above is becausetests/Clip_tests.cpp
still does its own parsing, rather than usingopenshot::stringToJson()
, for sanity-checking purposes.SetJson()
methods, though not as much as I'd like. (It really feels like it should be possible to template them away completely, to be honest.)const
member functions and args is greatly expanded where appropriate.std::stringstream
solely to format numeric values as strings now does so directly, with C++11'sstd::to_string()
.Json::JsonValue
, which has been corrected toJson::Value
.Abstract base class changes
Item 2 on the above list applies to (some of) the abstract base classes as well, like
ClipBase
andReaderBase
. Because the pure virtual class methodsJson()
andJsonValue()
of the abstract base classes were changed to have aconst
signature, their derived classes have to declare the concrete overrides for those methodsconst
as well or the signatures won't match.This doesn't really affect users of the code (I simply changed all of the relevant declarations in the derived classes as well), but it will impact any library consumers if they declare their own classes derived from the base classes. For instance, the only change I had to make to any of the unit test files was in
tests/ReaderBase_tests.cpp
:Without that change, the
ReaderBase_Derived_Class
test fails to compile, because theTestReader
class fails to implement the pure virtualconst
methods inReaderBase
.Like I said, this won't affect OpenShot, or normal consumers of the library, but it might affect @DylanC, @jeffski, or other users of
libopenshot
if they declare their own classes derived from our abstract base classes. That's kind of unfortunate, and if anyone knows a good way around that, so that derived classes will continue to compile without changes despite these changes to the base class definitions, I'd love to incorporate a fix.