Example #1
0
bool GdaJson::findValue(const json_spirit::Value& input,
						json_spirit::Value& output,
						const wxString& name)
{
	if (input.type() != json_spirit::obj_type) return false;
	return GdaJson::findValue(input.get_obj(), output, name);
}
Simulation::Simulation(json_spirit::Value &jsonData)
{
	reset();

	json_spirit::Object jsonObject = jsonData.get_obj();
	
	// It is crucial that the teams are setup before the rules.
	// To achieve that, we just delay rule initialization.
	json_spirit::Array ruleData;

	for (json_spirit::Pair &pair : jsonObject)
	{
		std::string &key = pair.name_;

		if (key == "thread_count") numberOfThreads = pair.value_.get_int();
		else if (key == "run_count") numberOfRuns = pair.value_.get_int();
		else if (key == "tournament_id") tournamentID = pair.value_.get_int();
		else if (key == "tournament_type") tournamentType = pair.value_.get_str();
		else if (key == "teams") setupTeams(pair.value_.get_array());
		else if (key == "rules") ruleData = pair.value_.get_array();
		else if (key == "match_database") setupKnownMatches(pair.value_.get_array());
		else
			std::cerr << "sim::Simulation: invalid property \"" << key << "\"" << std::endl;
	}

	// Finally (after the teams are setup) init the rules.
	if (!ruleData.empty())
		setupRules(ruleData);
}
Example #3
0
bool
jsonGetMember(const json_spirit::Value& value, const char* name, T& out)
{
    using namespace json_spirit;

    if (value.type() == obj_type) {
        // yeah, only objects have values.
        BOOST_FOREACH(const Pair& pair, value.get_obj()) {
            if (pair.name_ == name) {
                out = pair.value_.get_value<T>();
                return true;
            }
        }
    }
Example #4
0
// Convert from a JSON to an AtNode
static AtSmartPtr<AtNode> ConvertNode(json_spirit::Value node)
{
	AtSmartPtr<AtNode> obj (new AtNode());
	
	if (node.type() == json_spirit::str_type)
	{
		obj->value = std::wstring(node.get_str().begin(),node.get_str().end());
	}
	else if (node.type() == json_spirit::int_type || node.type() == json_spirit::real_type)
	{
		std::wstringstream stream;
		if (node.type() == json_spirit::int_type)
			stream << node.get_int();
		if (node.type() == json_spirit::real_type)
			stream << node.get_real();
		
		obj->value = stream.str().c_str();
		obj->children.insert(AtNode::child_pairtype(
			"@number", AtSmartPtr<AtNode>(new AtNode())
		));
	}
	else if (node.type() == json_spirit::bool_type)
	{
		if (node.get_bool())
			obj->value = L"true";
		else
			obj->value = L"false";
		
		obj->children.insert(AtNode::child_pairtype(
			"@boolean", AtSmartPtr<AtNode>(new AtNode())
		));
	}
	else if (node.type() == json_spirit::array_type)
	{
		obj->children.insert(AtNode::child_pairtype(
			"@array", AtSmartPtr<AtNode>(new AtNode())
		));

		json_spirit::Array nodeChildren = node.get_array();
		json_spirit::Array::iterator itr = nodeChildren.begin();
		
		for (; itr != nodeChildren.end(); itr++)
		{
			obj->children.insert(AtNode::child_pairtype(
				"item", ConvertNode(*itr)
			));
		}
	}
	else if (node.type() == json_spirit::obj_type)
	{
		json_spirit::Object objectProperties = node.get_obj();
		json_spirit::Object::iterator itr = objectProperties.begin();
		for (; itr != objectProperties.end(); itr++)
		{
			obj->children.insert(AtNode::child_pairtype(
				itr->name_, ConvertNode(itr->value_)
			));
		}
	}
	else if (node.type() == json_spirit::null_type)
	{
		return obj;
	}
	else
	{
		assert(! "Unimplemented type found when parsing JSON!");
	}
	
	return obj;
}
Example #5
0
bool GdaJson::hasName(const json_spirit::Value& val, const wxString& name)
{
	if (val.type() != json_spirit::obj_type) return false;
	return GdaJson::hasName(val.get_obj(), name);
}
Example #6
0
wxString GdaJson::getStrValFromObj(const json_spirit::Value& val,
								   const wxString& name)
{
	if (val.type() != json_spirit::obj_type) return "";
	return getStrValFromObj(val.get_obj(), name);
}