30 #include <boost/variant/static_visitor.hpp>
31 #include <boost/variant/apply_visitor.hpp>
32 #include <boost/variant/get.hpp>
33 #include <boost/mpl/for_each.hpp>
44 template <
typename ElementType>
struct ElementTypeName {
45 static const char *
get();
50 #define OSVR_ROUTING_TYPENAME_HANDLER(CLASS) \
51 template <> struct ElementTypeName<CLASS> { \
52 static const char *get() { return #CLASS; } \
64 #undef OSVR_ROUTING_TYPENAME_HANDLER
67 class TypeNameVisitor :
public boost::static_visitor<const char *> {
69 template <
typename ElementType>
70 const char *operator()(ElementType
const &)
const {
71 return ElementTypeName<ElementType>::get();
77 return boost::apply_visitor(TypeNameVisitor(), elt);
81 if (boost::get<NullElement>(&dest)) {
87 return (
nullptr != boost::get<NullElement>(&elt));
91 class MaxTypeNameLength {
93 MaxTypeNameLength(
size_t &maxLen) : m_maxLen(maxLen) {}
96 operator=(MaxTypeNameLength
const &) =
delete;
97 template <
typename T>
void operator()(T
const &) {
99 (std::max)(m_maxLen, strlen(ElementTypeName<T>::get()));
109 boost::mpl::for_each<elements::PathElement::types>(
110 MaxTypeNameLength(maxLen));
size_t getMaxTypeNameLength()
Gets the length of the longest type name.
const char * getTypeName(PathElement const &elt)
Gets a string that indicates the type of path element. Do not use this for conditionals/comparisons u...
bool isNull(PathElement const &elt)
Returns true if the path element provided is a NullElement.
Namespace for the various element types that may constitute a node in the path tree.
void ifNullReplaceWith(PathElement &dest, PathElement const &src)
If dest is a NullElement, replace it with the provided src element.
boost::variant< NullElement, AliasElement, SensorElement, InterfaceElement, DeviceElement, PluginElement, StringElement > PathElement
The variant type containing a particular kind of path element.