Exemple #1
0
void JSONTest::testTemplate()
{
	Template tpl;
	tpl.parse("Hello world! From <?= person.name ?>\n<?if person.toOld ?>You're too old<?endif?>\n");

	Object::Ptr data = new Object();
	Object::Ptr person = new Object();
	data->set("person", person);
	person->set("name", "Franky");
	person->set("toOld", true);
	tpl.render(data, std::cout);
}
Exemple #2
0
void ParseHandler::startArray()
{
	Array::Ptr newArr = new Array();

	if ( _stack.empty() ) // The first array
	{
		_result = newArr;
	}
	else
	{
		Var parent = _stack.top();

		if ( parent.type() == typeid(Array::Ptr) )
		{
			Array::Ptr arr = parent.extract<Array::Ptr>();
			arr->add(newArr);
		}
		else if ( parent.type() == typeid(Object::Ptr) )
		{
			poco_assert_dbg(!_key.empty());
			Object::Ptr obj = parent.extract<Object::Ptr>();
			obj->set(_key, newArr);
			_key.clear();
		}
	}

	_stack.push(newArr);
}
Exemple #3
0
void ParseHandler::setValue(const Var& value)
{
	Var parent = _stack.top();

	if ( parent.type() == typeid(Array::Ptr) )
	{
		Array::Ptr arr = parent.extract<Array::Ptr>();
		arr->add(value);
	}
	else if ( parent.type() == typeid(Object::Ptr) )
	{
		poco_assert_dbg(!_key.empty());
		Object::Ptr obj = parent.extract<Object::Ptr>();
		obj->set(_key, value);
		_key.clear();
	}
}