示例#1
0
string_vector FindFiles(const string_vector &files, time_t changed_since)
{
	string_vector result;
	for (int i = 0; i < files.size(); i++) {
		FindFiles(files[i], &result, changed_since);
	}
	sort(result.begin(), result.end());
	return result;
}
示例#2
0
	void argument_parser::parse(string_vector & tokens)
	{
		for(std::size_t i = 0, end = tokens.size(); i < end; i++)
		{
			std::string const & token = tokens[i];
			if(token.empty())
				continue;

			if(token[0] == '-')
			{
				std::string name = token.substr(1);
				variable_vector::iterator iterator = std::find(variables.begin(), variables.end(), name);
				if(iterator == variables.end())
					continue;
				argument_variable & variable = *iterator;
				i++;
				if(i == end)
					throw exception("Variable \"" + name + "\" is lacking an argument");
				std::string argument = tokens[i];
				switch(variable.type)
				{
					case argument_variable_type_bool:
					{
						bool value;
						if(!string_to_bool(argument, value))
							throw exception("Invalid boolean value specified for variable \"" + name + "\"");
						*reinterpret_cast<bool *>(variable.address) = value;
						break;
					}

					case argument_variable_type_string:
						*reinterpret_cast<std::string *>(variable.address) = argument;
						break;

					default:
						throw exception("Unknown variable type encountered in argument parser");
						break;
				}
				variable.handled = true;
			}
		}

		BOOST_FOREACH(argument_variable & variable, variables)
		{
			if(!variable.handled)
			{
				if(variable.required)
					throw exception("Required variable \"" + variable.name + "\" has not been specified");

				else if(variable.default_value)
				{
					switch(variable.type)
					{
						case argument_variable_type_bool:
							variable.set_default_value<bool>();
							break;

						case argument_variable_type_string:
							variable.set_default_value<std::string>();
							break;
					}
				}
			}
		}
	}
示例#3
0
bool console_command::match(std::string const & match_command, string_vector const & arguments) const
{
	return command == match_command && argument_count == arguments.size();
}