ROSMessageTraits.h 2.94 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
#pragma once

namespace ros_bridge {
namespace traits {


//! @brief Checks if class T has a member function z.
//!
//! Checks if class T has a member function z. E.g if the class Point has a member function
//! z than HasMemberZ<Point>::value is equal to 1 and 0 either.
template <typename T>
class HasMemberZ
{
    typedef char Small;
    struct Big { char x[2]; };

    template <typename C> static Small test( typeof(&C::z) ) ;
    template <typename C> static Big test(...);

public:
    enum { value = sizeof(test<T>(0)) == sizeof(Small) };
};

//! @brief Checks if class T has a member function labels.
//!
//! Checks if class T has a member function labels. E.g if the class T has a member function
//! labels than HasMemberLabels<T>::value is equal to 1 and 0 either.
template <typename T>
class HasMemberLabels
{
    typedef char Small;
    struct Big { char x[2]; };

    template <typename C> static Small test( typeof(&C::labels) ) ;
    template <typename C> static Big test(...);

public:
    enum { value = sizeof(test<T>(0)) == sizeof(Small) };
};

//! @brief Checks if class T has a member function labels.
//!
//! Checks if class T has a member function likelihood. E.g if the class T has a member function
//! likelihood than HasMemberLikelihood<T>::value is equal to 1 and 0 either.
template <typename T>
class HasMemberLikelihood
{
    typedef char Small;
    struct Big { char x[2]; };

    template <typename C> static Small test( typeof(&C::likelihood) ) ;
    template <typename C> static Big test(...);

public:
    enum { value = sizeof(test<T>(0)) == sizeof(Small) };
};

//! @brief Checks if class T has a member function labels.
//!
//! Checks if class T has a member function header. E.g if the class T has a member function
//! header than HasMemberHeader<T>::value is equal to 1 and 0 either.
template <typename T>
class HasMemberHeader
{
    typedef char Small;
    struct Big { char x[2]; };

    template <typename C> static Small test( typeof(&C::header) ) ;
    template <typename C> static Big test(...);

public:
    enum { value = sizeof(test<T>(0)) == sizeof(Small) };
};

//! @brief Checks if class T has a member function altitude.
//!
//! Checks if class T has a member function altitude. E.g if the class T has a member function
//! altitude than HasMemberAltitude<T>::value is equal to 1 and 0 either.
template <typename T>
class HasMemberAltitude
{
    typedef char Small;
    struct Big { char x[2]; };

    template <typename C> static Small test( typeof(&C::altitude) ) ;
    template <typename C> static Big test(...);

public:
    enum { value = sizeof(test<T>(0)) == sizeof(Small) };
};

//! @brief Selects the Type T or U depending on flag and stores it inside Result.
template <int flag, typename T, typename U>
struct Select {typedef T Result;};
template <typename T, typename U>
struct Select<0, T, U> {typedef U Result;};

struct HasComponents {};
struct Has3Components : public HasComponents {};
struct Has2Components : public HasComponents {};
}
}