pivaluetreeconversions add file methods
This commit is contained in:
@@ -319,3 +319,28 @@ PIValueTree PIValueTreeConversions::fromText(const PIString & str) {
|
||||
PIIOString dev(str);
|
||||
return fromText(&dev);
|
||||
}
|
||||
|
||||
|
||||
PIValueTree PIValueTreeConversions::fromJSONFile(const PIString & path) {
|
||||
return PIValueTreeConversions::fromJSON(PIJSON::fromJSON(PIString::fromUTF8(PIFile::readAll(path))));
|
||||
}
|
||||
|
||||
|
||||
PIValueTree PIValueTreeConversions::fromTextFile(const PIString & path) {
|
||||
PIFile f(path, PIIODevice::ReadOnly);
|
||||
return PIValueTreeConversions::fromText(&f);
|
||||
}
|
||||
|
||||
|
||||
bool PIValueTreeConversions::toJSONFile(const PIString & path, const PIValueTree & root, Options options) {
|
||||
auto d = toJSON(root, options).toJSON(PIJSON::Tree).toUTF8();
|
||||
int written = PIFile::writeAll(path, d);
|
||||
return written == d.size_s();
|
||||
}
|
||||
|
||||
|
||||
bool PIValueTreeConversions::toTextFile(const PIString & path, const PIValueTree & root, Options options) {
|
||||
auto d = toText(root, options).toUTF8();
|
||||
int written = PIFile::writeAll(path, d);
|
||||
return written == d.size_s();
|
||||
}
|
||||
|
||||
@@ -49,9 +49,16 @@ PIP_EXPORT PIValueTree fromVariantMap(const PIVariantMap & vm);
|
||||
PIP_EXPORT PIValueTree fromJSON(const PIJSON & json);
|
||||
PIP_EXPORT PIValueTree fromText(PIIODevice * device);
|
||||
PIP_EXPORT PIValueTree fromText(const PIString & str);
|
||||
|
||||
PIP_EXPORT PIValueTree fromJSONFile(const PIString & path);
|
||||
PIP_EXPORT PIValueTree fromTextFile(const PIString & path);
|
||||
|
||||
PIP_EXPORT PIJSON toJSON(const PIValueTree & root, Options options = Default);
|
||||
PIP_EXPORT PIString toText(const PIValueTree & root, Options options = Default);
|
||||
|
||||
PIP_EXPORT bool toJSONFile(const PIString & path, const PIValueTree & root, Options options = Default);
|
||||
PIP_EXPORT bool toTextFile(const PIString & path, const PIValueTree & root, Options options = Default);
|
||||
|
||||
} // namespace PIValueTreeConversions
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user