25 #ifndef INCLUDED_PathParseAndRetrieve_h_GUID_C451663C_0711_4B85_2011_61D26E5C237C 26 #define INCLUDED_PathParseAndRetrieve_h_GUID_C451663C_0711_4B85_2011_61D26E5C237C 34 #include <boost/assert.hpp> 35 #include <boost/algorithm/string/find_iterator.hpp> 36 #include <boost/algorithm/string/finder.hpp> 37 #include <boost/range/adaptor/sliced.hpp> 46 template <
typename Node>
47 Node *operator()(Node *node, std::string
const &component)
const {
48 return &(node->getOrCreateChildByName(component));
53 template <
typename Node>
54 Node
const *operator()(Node
const *node,
55 std::string
const &component)
const {
56 return &(node->getChildByName(component));
59 enum ParentPolicy { GETPARENT_PERMIT, GETPARENT_DENY };
60 enum AbsolutePolicy { ABSOLUTEPATH_PERMIT, ABSOLUTEPATH_DENY };
62 template <
typename GetChildFunctor,
typename Node>
63 inline Node &treePathRetrieveImplementation(
65 ParentPolicy permitParent = GETPARENT_DENY,
66 AbsolutePolicy permitAbsolute = ABSOLUTEPATH_PERMIT) {
74 if (path.at(0) == getPathSeparatorCharacter()) {
75 if (ABSOLUTEPATH_PERMIT != permitAbsolute) {
79 while (!ret->isRoot()) {
80 ret = ret->getParent();
87 path.erase(begin(path));
91 if (path.back() == getPathSeparatorCharacter()) {
99 auto begin = boost::algorithm::make_split_iterator(
104 auto end = decltype(begin)();
108 std::string component;
112 for (
auto rangeIt : boost::make_iterator_range(begin, end)) {
114 component = boost::copy_range<std::string>(rangeIt);
117 if (component.empty()) {
120 }
else if (component ==
".") {
124 }
else if (component ==
"..") {
127 if (GETPARENT_PERMIT != permitParent) {
133 ret = ret->getParent();
136 ret = f(ret, component);
164 template <
typename ValueType>
167 bool permitParent =
false) {
168 return detail::treePathRetrieveImplementation(
170 permitParent ? detail::GETPARENT_PERMIT : detail::GETPARENT_DENY);
177 template <
typename ValueType>
180 bool permitParent =
false) {
181 return detail::treePathRetrieveImplementation(
183 permitParent ? detail::GETPARENT_PERMIT : detail::GETPARENT_DENY);
199 template <
typename ValueType>
202 std::string
const &path) {
203 BOOST_ASSERT_MSG(root.
isRoot(),
"Must pass the root node!");
210 if (path.at(0) != getPathSeparatorCharacter()) {
218 template <
typename ValueType>
221 std::string
const &path) {
222 BOOST_ASSERT_MSG(root.
isRoot(),
"Must pass the root node!");
229 if (path.at(0) != getPathSeparatorCharacter()) {
238 #endif // INCLUDED_PathParseAndRetrieve_h_GUID_C451663C_0711_4B85_2011_61D26E5C237C Thrown when attempting to use a path with an empty component.
Definition: RoutingExceptions.h:54
Handles spatial transformations.
Definition: SerializationTraitExample_Complicated.h:40
A node in a generic tree, which can contain an object by value.
Definition: TreeNode.h:72
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Definition: PathParseAndRetrieve.h:45
util::TreeNode< ValueType > & treePathRetrieve(util::TreeNode< ValueType > &node, std::string path, bool permitParent=false)
Internal method for parsing a path and getting or creating the nodes along it.
Definition: PathParseAndRetrieve.h:166
Thrown when attempting to go to the parent path when forbidden.
Definition: RoutingExceptions.h:77
Definition: PathParseAndRetrieve.h:52
Definition: newuoa.h:1888
Thrown when attempting to go use an absolute path when forbidden.
Definition: RoutingExceptions.h:69
Thrown when attempting to use a path with no leading slash where an absolute path is required...
Definition: RoutingExceptions.h:91
Thrown when attempting to go to the parent path from the root.
Definition: RoutingExceptions.h:61
Thrown when attempting to use an empty path.
Definition: RoutingExceptions.h:84
util::TreeNode< ValueType > & pathParseAndRetrieve(util::TreeNode< ValueType > &root, std::string const &path)
Internal method for parsing a path and getting or creating the nodes along it.
Definition: PathParseAndRetrieve.h:201
bool isRoot() const
Is the current node a root node?
Definition: TreeNode.h:276
OSVR_COMMON_EXPORT const char * getPathSeparator()
Gets the path separator - a slash - as a null-terminated string.
Definition: RoutingConstants.cpp:38