JsonUtil: Adapt functions to vanilla jsoncpp

This commit is contained in:
Martin Kröning
2020-06-18 20:56:40 +02:00
parent 76f805fe9c
commit f075d6a617
3 changed files with 16 additions and 68 deletions
+13
View File
@@ -75,6 +75,19 @@ bool JsonUtil::WriteFile(const Json::Value &root, const RString &sFile, bool bMi
return true;
}
std::vector<RString> JsonUtil::DeserializeArrayStrings(const Json::Value &value)
{
std::vector<RString> values;
for(auto &&inner_value : value)
{
if(inner_value.isConvertibleTo(Json::stringValue))
{
values.push_back(inner_value.asString());
}
}
return values;
}
/*
* (c) 2001-2004 Chris Danford
* All rights reserved.
+2 -67
View File
@@ -14,6 +14,8 @@ namespace JsonUtil
bool WriteFile(const Json::Value &root, const RString &sFile, bool bMinified);
std::vector<RString> DeserializeArrayStrings(const Json::Value &array);
template<class T>
static void SerializeVectorObjects(const vector<T> &v, void fn(const T &, Json::Value &), Json::Value &root)
{
@@ -195,57 +197,6 @@ namespace JsonUtil
}
}
template<class T>
static void DeserializeArrayValues(vector<T> &v, const Json::Value &root)
{
v.clear();
for( unsigned i=0; i<root.size(); i++ )
{
T t;
if( root[i].TryGet( t ) )
v.push_back( t );
}
}
// don't pull in the set header here
template<typename S, typename T>
static void DeserializeArrayValuesIntoSet(S &s, const Json::Value &root)
{
s.clear();
for( unsigned i=0; i<root.size(); i++ )
{
T t;
if( root[i].TryGet( t ) )
s.insert( t );
}
}
template<typename T>
static void DeserializeArrayValuesIntoVector(vector<T> &v, const Json::Value &root)
{
v.clear();
for( unsigned i=0; i<root.size(); i++ )
{
T t;
if( root[i].TryGet( t ) )
v.push_back( t );
}
}
template <typename M>
static void DeserializeValueToValueMap(M &m, const Json::Value &root)
{
for( Json::Value::const_iterator iter = root.begin(); iter != root.end(); iter++ )
(*iter).TryGet( m[ iter.memberName() ] );
}
template <typename M, typename E, typename F>
static void DeserializeStringToValueMap(M &m, F fnToValue(E e), const Json::Value &root)
{
for( Json::Value::const_iterator iter = root.begin(); iter != root.end(); iter++ )
(*iter).TryGet( m[ fnToValue(iter.memberName()) ] );
}
template <typename M, typename E, typename F>
static void DeserializeStringToObjectMap(M &m, F fnToValue(E e), const Json::Value &root)
{
@@ -272,22 +223,6 @@ namespace JsonUtil
}
}
template <typename K, typename V>
static void DeserializeObjectToValueMapAsArray(map<K,V> &m, const RString &sKeyName, const RString &sValueName, const Json::Value &root)
{
for( unsigned i=0; i<root.size(); i++ )
{
const Json::Value &root2 = root[i];
K k;
if( !k.Deserialize( root2[sKeyName] ) )
continue;
V v;
if( !root2[sValueName].TryGet(v) )
continue;
m[k] = v;
}
}
template<class T>
static void DeserializeVectorValues(vector<T> &v, const Json::Value &root)
{
+1 -1
View File
@@ -214,7 +214,7 @@ static void Deserialize( Song &out, const Json::Value &root )
JsonUtil::DeserializeVectorObjects( vBgc, Deserialize, root["ForegroundChanges"] );
}
JsonUtil::DeserializeArrayValuesIntoVector( out.m_vsKeysoundFile, root["KeySounds"] );
out.m_vsKeysoundFile = JsonUtil::DeserializeArrayStrings(root["KeySounds"]);
{
vector<Steps*> vpSteps;