39 #include <boost/variant/get.hpp>
69 static inline bool aliasNeedsUpdate(
PathNode &node,
70 std::string
const &source,
71 AliasPriority priority) {
73 boost::get<elements::AliasElement>(&node.value());
90 static inline bool addAliasImpl(
PathNode &node, std::string
const &source,
91 AliasPriority priority) {
93 if (!aliasNeedsUpdate(node, source, priority)) {
104 AliasPriority priority) {
108 OSVR_DEV_VERBOSE(
"Could not parse source: " << source);
111 if (!isPathAbsolute(newSource.
getLeaf())) {
114 "Source contains a relative path, not permitted: " << source);
117 return addAliasImpl(node, newSource.
getAlias(), priority);
120 bool addAliasFromRoute(
PathNode &node, std::string
const &route,
121 AliasPriority priority) {
127 static inline std::string getAbsolutePath(
PathNode &node,
128 std::string
const &path) {
129 if (isPathAbsolute(path)) {
136 std::string
const &source,
137 std::string
const &dest,
138 AliasPriority priority) {
143 OSVR_DEV_VERBOSE(
"Could not parse source: " << source);
146 auto absSource = getAbsolutePath(node, newSource.
getLeaf());
148 return addAliasImpl(aliasNode, newSource.
getAlias(), priority);
151 bool isPathAbsolute(std::string
const &source) {
152 return !source.empty() && source.at(0) == getPathSeparatorCharacter();
A short-lived class for setting up options then processing alias directives to apply to a path tree...
The element type corresponding to a path alias, with a priority level for sorting out whether automat...
Header containing wrappers for some common jsoncpp operations.
bool isValid() const
Did the alias parse in a valid way?
A tree representation, with path/url syntax, of the known OSVR system.
::osvr::util::TreeNode< PathElement > PathNode
The specific tree node type that contains a path element.
AliasPriority & priority()
Get/set whether this alias was automatically set (and thus subject to being override by explicit rout...
std::string & getSource()
Get the source of data for this alias.
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.
void jsonToPathTree(PathTree &tree, Json::Value nodes)
Deserialize a path tree from a JSON array of objects.
std::string getFullPath(PathNode const &node)
Gets the absolute path for the given node.
Json::Value convertRouteToAlias(Json::Value const &val)
Given a single JSON object, if it's an old-fashioned "routing directive", convert it to a normal "ali...
PathNode & getNodeByPath(std::string const &path)
Returns the node indicated by the path, which must be absolute (begin with a /). Any non-existent nod...
Json::Value applyPriorityToAlias(Json::Value const &alias, AliasPriority priority)
Given a JSON object describing one or more aliases, set the priority of the alias(es).
void ifNullReplaceWith(PathElement &dest, PathElement const &src)
If dest is a NullElement, replace it with the provided src element.
void reset()
Reset the path tree to a new, empty root node.
std::string getLeaf() const
Get the ultimate source/leaf of the alias.
std::string getAlias() const
Get the normalized, cleaned, compacted version of the alias.
bool addAlias(PathNode &node, std::string const &source, AliasPriority priority)
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.
void setSource(std::string const &source)
Sets the source of this alias.
Internal, configured header file for verbosity macros.
Json::Value pathTreeToJson(PathTree const &tree, bool keepNulls=false)
Serialize a path tree to a JSON array of objects, one for each node.
boost::variant< NullElement, AliasElement, SensorElement, InterfaceElement, DeviceElement, PluginElement, StringElement > PathElement
The variant type containing a particular kind of path element.
void setLeaf(std::string const &leaf)
Set the leaf of the alias: should be an absolute path.
bool addAliasFromSourceAndRelativeDest(PathNode &node, std::string const &source, std::string const &dest, AliasPriority priority=ALIASPRIORITY_MANUAL)
Json::Value jsonParse(std::string const &str)
Parses a string as JSON, returning a null value if parsing fails.