| 51 | bool showTree = true; |
| 52 | }; |
| 53 | int osvrToStream(std::ostream &os, Options const &opts) { |
| 54 | osvr::clientkit::ClientContext context("com.osvr.tools.pathtreexport"); |
| 55 | |
| 56 | /// Get a non-const copy of the path tree. |
| 57 | osvr::common::PathTree pathTree; |
| 58 | osvr::common::clonePathTree(context.get()->getPathTree(), pathTree); |
| 59 | |
| 60 | /// Resolve all aliases |
| 61 | osvr::common::resolveFullTree(pathTree); |
| 62 | { |
| 63 | auto graph = GraphOutputInterface::createGraphOutputInterface( |
| 64 | os, opts.graphOutputType); |
| 65 | using namespace osvr::common; |
| 66 | |
| 67 | /// Now traverse for tree node output |
| 68 | bool fullPaths = opts.fullPaths; |
| 69 | osvr::util::traverseWith( |
| 70 | pathTree.getRoot(), |
| 71 | [&graph, &pathTree, fullPaths](osvr::common::PathNode const &node) { |
| 72 | auto parent = node.getParent(); |
| 73 | if (nullptr == parent) { |
| 74 | return; |
| 75 | } |
| 76 | auto fullPath = getFullPath(node); |
| 77 | auto &graphNode = graph->addNode( |
| 78 | fullPaths ? fullPath : ("/" + node.getName()), fullPath, |
| 79 | getTypeName(node)); |
| 80 | }); |
| 81 | |
| 82 | if (opts.showTree) { |
| 83 | /// Now traverse for parent link output |
| 84 | graph->enableTreeOrganization(); |
| 85 | osvr::util::traverseWith( |
| 86 | pathTree.getRoot(), [&graph, &pathTree, fullPaths]( |
| 87 | osvr::common::PathNode const &node) { |
| 88 | auto parent = node.getParent(); |
| 89 | if (nullptr == parent) { |
| 90 | return; |
| 91 | } |
| 92 | auto fullPath = getFullPath(node); |
| 93 | auto &graphNode = graph->getNode(getFullPath(node)); |
| 94 | graph->addEdge(graph->getNode(getFullPath(*parent)), |
| 95 | graphNode, "child"); |
| 96 | }); |
| 97 | } |
| 98 | if (opts.showAliases) { |
| 99 | /// Now traverse for aliases |
| 100 | osvr::util::traverseWith( |
| 101 | pathTree.getRoot(), |
| 102 | [&graph, &pathTree](osvr::common::PathNode const &node) { |
| 103 | auto alias = |
| 104 | boost::get<elements::AliasElement>(&node.value()); |
| 105 | if (nullptr == alias) { |
| 106 | return; |
| 107 | } |
| 108 | auto fullPath = getFullPath(node); |
| 109 | ParsedAlias parsed(alias->getSource()); |
| 110 | auto &graphNode = graph->getNode(fullPath); |
no test coverage detected