示例#1
0
TEST(Generator, addCommand)
{
	std::vector<const char*> cmd1;
	cmd1.push_back("this");
	cmd1.push_back("is");
	cmd1.push_back("a");
	cmd1.push_back("test");

	std::vector<const char*> cmd2;
	cmd2.push_back("this");
	cmd2.push_back("is");
	cmd2.push_back("a");
	cmd2.push_back("second");
	cmd2.push_back("test");

	Generator g;
	g.addCommand(cmd1);

	EXPECT_EQ(1, g.cmds.size());
	EXPECT_EQ(4, g.cmds[0].size());

	g.addCommand(cmd2);
	EXPECT_EQ(2, g.cmds.size());
	EXPECT_EQ(4, g.cmds[0].size());
	EXPECT_EQ(5, g.cmds[1].size());

	g.addCommand(cmd1);
	EXPECT_EQ(3, g.cmds.size());
	EXPECT_EQ(4, g.cmds[0].size());
	EXPECT_EQ(5, g.cmds[1].size());
	EXPECT_EQ(4, g.cmds[2].size());
}
示例#2
0
Generator *Generator::fromXML ( const rapidxml::xml_node<> *src )
{
	using namespace rapidxml;
	std::vector<const char*> cmd;

	Generator *g = new Generator();

	xml_node<> *n = src->first_node(XML::target_generator_descriptionNName);

	if ( n != NULL )
	{
		g->addDescription(n->value());
	}

	if (src->first_node(XML::target_generator_commandNName))
	{
		cmd.empty();

		n = src->first_node(XML::target_generator_commandNName);
		do
		{
			if (n->first_node(XML::target_generator_command_argumentNName))
			{
				xml_node<> *o = n->last_node(XML::target_generator_command_argumentNName);
				// We are going backwords in hope of minimising vector resizes.
				do
				{
					unsigned int pos;
					sscanf(o->last_attribute(XML::target_generator_command_argument_posAName)->value(), "%u", &pos);

					if ( pos >= cmd.size() )
						cmd.resize(pos+1, NULL);

					cmd[pos] = strdup(o->value());
				} while ( o = o->previous_sibling(XML::target_generator_command_argumentNName) );
			}

			g->addCommand(cmd);
		} while ( n = n->next_sibling(XML::target_generator_commandNName) );
	}

	return g;
}