Node* DesktopNode::getNodeByModelPath(const ModelPath &path) { if (path.size() <= 0) { return 0; } string root_path = path.front(); if (root_path != absolutePath()) { return 0; } Node* node = this; for (int i = 1; i < path.size(); i++) { if (node == 0) { return 0; } ContainerNode* container = dynamic_cast<ContainerNode*>(node); if (container != 0) { node = container->node(path[i]).get(); } else if (i < path.size() - 1) { return 0; } } return node; }
bool BookStoreFileSystemTree::cdPath(const ModelPath& path) { if (path.size() <= 0) { return false; } string root_path = path.front(); if (root_path != root_node_.absolutePath()) { return false; } Node* node = &root_node_; for (int i = 1; i < path.size(); i++) { if (node == 0) { return false; } ContainerNode* container = dynamic_cast<ContainerNode*>(node); if (container != 0) { node = container->node(path[i]).get(); } else { return false; } } ContainerNode* current_node = dynamic_cast<ContainerNode*>(node); if (current_node != 0) { setCurrentNode(current_node); return true; } return false; }