MessageTraits.h 5.55 KB
Newer Older
1 2
#pragma once

3
namespace ROSBridge {
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
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(...);

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
public:
    enum { value = sizeof(test<T>(0)) == sizeof(Small) };
};
//! @brief Checks if class T has a member function SetZ.
//!
//! Checks if class T has a member function SetZ. E.g if the class Point has a member function
//! SetZ than HasMemberSetZ<Point>::value is equal to 1 and 0 either.
template <typename T>
class HasMemberSetZ
{
    typedef char Small;
    struct Big { char x[2]; };

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

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
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) };
};

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
//! @brief Checks if class T has a member function SetLabels.
//!
//! Checks if class T has a member function SetLabels. E.g if the class T has a member function
//! SetLabels than HasMemberSetLabels<T>::value is equal to 1 and 0 either.
template <typename T>
class HasMemberSetLabels
{
    typedef char Small;
    struct Big { char x[2]; };

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

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

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
//! @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) };
};

91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
//! @brief Checks if class T has a member function setLikelihood.
//!
//! Checks if class T has a member function setLikelihood. E.g if the class T has a member function
//! setLikelihood than HasMemberSetLikelihood<T>::value is equal to 1 and 0 either.
template <typename T>
class HasMemberSetLikelihood
{
    typedef char Small;
    struct Big { char x[2]; };

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

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

//! @brief Checks if class T has a member function header.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
//!
//! 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) };
};

125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
//! @brief Checks if class T has a member function setHeader.
//!
//! Checks if class T has a member function setHeader. E.g if the class T has a member function
//! setHeader than HasMemberSetHeader<T>::value is equal to 1 and 0 either.
template <typename T>
class HasMemberSetHeader
{
    typedef char Small;
    struct Big { char x[2]; };

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

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

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
//! @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) };
};

159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
//! @brief Checks if class T has a member function setAltitude.
//!
//! Checks if class T has a member function setAltitude. E.g if the class T has a member function
//! setAltitude than HasMemberSetAltitude<T>::value is equal to 1 and 0 either.
template <typename T>
class HasMemberSetAltitude
{
    typedef char Small;
    struct Big { char x[2]; };

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

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

176 177 178 179 180 181 182 183 184 185 186
//! @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 {};
}
}