22 #include "usModuleManifest_p.h"
32 typedef std::map<std::string, Any> AnyMap;
33 typedef std::vector<Any> AnyVector;
35 void ParseJsonObject(
const Json::Value& jsonObject, AnyMap& anyMap);
36 void ParseJsonArray(
const Json::Value& jsonArray, AnyVector& anyVector);
43 ParseJsonObject(jsonValue, ref_any_cast<AnyMap>(any));
48 Any any = AnyVector();
49 ParseJsonArray(jsonValue, ref_any_cast<AnyVector>(any));
56 else if (jsonValue.
isBool())
58 return Any(jsonValue.
asBool());
66 return Any(jsonValue.
asInt());
72 void ParseJsonObject(
const Json::Value& jsonObject, AnyMap& anyMap)
75 it != jsonObject.
end(); ++it)
78 Any anyValue = ParseJsonValue(jsonValue);
79 if (!anyValue.Empty())
81 anyMap.insert(std::make_pair(it.memberName(), anyValue));
86 void ParseJsonArray(
const Json::Value& jsonArray, AnyVector& anyVector)
89 it != jsonArray.
end(); ++it)
92 Any anyValue = ParseJsonValue(jsonValue);
93 if (!anyValue.Empty())
95 anyVector.push_back(anyValue);
102 ModuleManifest::ModuleManifest()
106 void ModuleManifest::Parse(std::istream& is)
110 if (!jsonReader.parse(is, root,
false))
112 throw std::runtime_error(jsonReader.getFormattedErrorMessages());
117 throw std::runtime_error(
"The Json root element must be an object.");
120 ParseJsonObject(root, m_Properties);
123 bool ModuleManifest::Contains(
const std::string& key)
const
125 return m_Properties.count(key) > 0;
128 Any ModuleManifest::GetValue(
const std::string& key)
const
130 AnyMap::const_iterator iter = m_Properties.find(key);
131 if (iter != m_Properties.end())
138 std::vector<std::string> ModuleManifest::GetKeys()
const
140 std::vector<std::string> keys;
141 for (AnyMap::const_iterator iter = m_Properties.begin();
142 iter != m_Properties.end(); ++iter)
144 keys.push_back(iter->first);
149 void ModuleManifest::SetValue(
const std::string& key,
const Any& value)
151 m_Properties[key] = value;
const_iterator begin() const
const_iterator end() const
std::string asString() const
static Features strictMode()
A configuration that is strictly compatible with the JSON specification.
Unserialize a JSON document into a Value.
const iterator for object and array value.