Пример #1
0
tree_node_<FILE_ITEM>* CFileTree::findNodeFromRootWithPath(char *path)
{
	// No topNode - bail out.
	if (topNode.node == NULL){
		return NULL;
	}
	std::string sPath(path);
	std::string nPath(topNode->path);
	// topNode path and requested path are the same? Use the node.
	if (sPath == nPath) {
		return topNode.node;
	}
	// printf("Did not find node for path : %s\n", path);

	// If the topNode path is part of the requested path this is a subpath.
	// Use the node.
	if (sPath.find(nPath) != std::string::npos) {
		// printf("Found %s is part of %s  \n", sPath.c_str(), topNode->path);
		std::string splittedString = sPath.substr(strlen(topNode->path) + 1);
		return findNodeWithPathFromNode(splittedString, topNode.node);
	}
	else {
		// If the current topNode isn't related to the requested path
		// iterate over all _top_ level elements in the tree to look for
		// a matching item and register it as current top node.

		// printf("NOT found %s is NOT part of %s  \n", sPath.c_str(), topNode->path);
		tree<FILE_ITEM>::sibling_iterator it;
		for (it = filesTree.begin(); it != filesTree.end(); it++)
		{
			std::string itPath(it.node->data.path);
			// Current item path matches the requested path - use the item as topNode.
			if (sPath == itPath) {
				// printf("Found parent node %s \n", it.node->data.path);
				topNode = it;
				return it.node;
			}
			else if (sPath.find(itPath) != std::string::npos) {
				// If the item path is part of the requested path this is a subpath.
				// Use the the item as topNode and continue analyzing.
				// printf("Found root node %s \n", it.node->data.path);
				topNode = it;
				std::string splittedString = sPath.substr(itPath.length() + 1);
				return findNodeWithPathFromNode(splittedString, it.node);
			}
		}
	}
	// Nothing found return NULL.
	return NULL;
}
Пример #2
0
tree_node_<FILE_ITEM>* CFileTree::findNodeWithPathFromNode(std::string path, tree_node_<FILE_ITEM>* node)
{
	tree<FILE_ITEM>::sibling_iterator sib = filesTree.begin(node);
	tree<FILE_ITEM>::sibling_iterator end = filesTree.end(node);
	bool currentLevel = true;

	std::string currentPath = _first_dirname(path);

	size_t position = currentPath.size();
	std::string followingPath = _following_path(path);
	currentLevel = followingPath.empty();

	while (sib != end) {
		// printf("sib->path '%s' lv %d curpath '%s' follow '%s'\n", sib->path, currentLevel, currentPath.c_str(), followingPath.c_str());
		if (strcmp(sib->path, currentPath.c_str()) == 0) {
			if (currentLevel) {
				return sib.node;
			}
			else {
				return findNodeWithPathFromNode(followingPath, sib.node);
			}
		}
		++sib;
	}
	return NULL;
}
Пример #3
0
tree_node_<FILE_ITEM>* CFileTree::findNodeWithPathFromNode(std::string path, tree_node_<FILE_ITEM>* node)
{
	tree<FILE_ITEM>::sibling_iterator sib = filesTree.begin(node);
	tree<FILE_ITEM>::sibling_iterator end = filesTree.end(node);
	bool currentLevel = true;

	std::string currentPath = path.substr(0, path.find('\\'));
	size_t position = path.find('\\');
	std::string followingPath("");
	if (position != std::string::npos) {
		followingPath = path.substr(path.find('\\') + 1);
		currentLevel = false;
	}

	while (sib != end) {
		if (strcmp(sib->path, currentPath.c_str()) == 0) {
			if (currentLevel) {
				return sib.node;
			}
			else {
				return findNodeWithPathFromNode(followingPath, sib.node);
			}
		}
		++sib;
	}
	return NULL;
}
Пример #4
0
tree_node_<FILE_ITEM>* CFileTree::findNodeFromRootWithPath(char *path)
{
	if (topNode.node == NULL){
		return NULL;
	}
	std::string sPath(path);
	if (sPath == std::string(topNode->path)) {
		return topNode.node;
	}
	std::string splittedString = sPath.substr(strlen(topNode->path) + 1);
	return findNodeWithPathFromNode(splittedString, topNode.node);
}
Пример #5
0
tree_node_<FILE_ITEM>* CFileTree::findParentNodeFromRootForPath(char *path) {
	std::string sPath(path);
	std::string currentPath = sPath.substr(strlen(topNode->path) + 1);
	size_t position = currentPath.find('\\');
	std::string followingPath("");
	if (position == std::string::npos) {
		return topNode.node;
	}
	else {
		followingPath = currentPath.substr(0, currentPath.find_last_of('\\'));
		return findNodeWithPathFromNode(followingPath, topNode.node);
	}
}
Пример #6
0
tree_node_<FILE_ITEM>* CFileTree::findParentNodeFromRootForPath(char *path) {
	std::string sPath(path);
	std::string nPath(topNode->path);

	// If the topNode path is not part of the requested path bail out.
	// This avoids also issues with taking substrings of incompatible
	// paths below.
	if (sPath.find(nPath) == std::string::npos) {
		// printf("Path %s doesn't belong to current topNode %s Found %s is part of %s  \n", sPath.c_str(), topNode->path);
		return NULL;
	}
	std::string currentPath = sPath.substr(strlen(topNode->path) + 1);
	std::string followingPath = _dirname_932(currentPath);
	if (followingPath.empty()) {
		return topNode.node;
	} else {
		return findNodeWithPathFromNode(followingPath, topNode.node);
	}
}