/**
 * Allows to collect all keys in the given path. It does not include section names.
 * @param path
 * @return A vector with all keys or names of the given path.
 */
std::shared_ptr<std::vector<std::string>> Configuration::getNames(const char* path, ...)
{
    va_list ap;
    va_start(ap, path);
    std::shared_ptr<std::vector<std::string>> params = getParams('.', path, ap);
    va_end(ap);

    std::vector<ConfigNode*> nodes;

    collectSections(this->configRoot.get(), params.get(), 0, &nodes);

    std::shared_ptr<std::vector<std::string>> result(new std::vector<std::string>());

    if (nodes.size() == 0) {
        std::cerr << pathNotFound(params.get()) << std::endl;
        throw std::exception();
    }

    for (size_t i = 0; i < nodes.size(); i++) {
        if (nodes[i]->getType() == ConfigNode::Leaf) {
            result->push_back(nodes[i]->getName());
        }
    }
    return result;
}
示例#2
0
	std::vector<std::string> Configuration::getNames(const char *path, ...)
	{
		CONSUME_PARAMS(path);

		// Get relevant nodes
		std::vector<ConfigNode *> nodes;
		collect(this->configRoot.get(), params.get(), 0, &nodes);

		// If there are no nodes, exit
		if (nodes.size() == 0) {
			throw ConfigException(pathNotFound(params.get()));
		}

		// Copy only the keys
		std::vector<std::string> result;
		for (size_t i = 0; i < nodes.size(); i++) {
			if (nodes[i]->getType() == ConfigNode::Leaf) {
				result.push_back(nodes[i]->getName());
			}
		}

		return result;
	}