00001 /****************************************************************************** 00002 * Copyright (C) 2014 by Ralf Kaestner * 00003 * ralf.kaestner@gmail.com * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the Lesser GNU General Public License as published by* 00007 * the Free Software Foundation; either version 3 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * Lesser GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the Lesser GNU General Public License * 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 00017 ******************************************************************************/ 00018 00023 #ifndef VARIANT_TOPIC_TOOLS_ARRAY_TYPE_TRAITS_H 00024 #define VARIANT_TOPIC_TOOLS_ARRAY_TYPE_TRAITS_H 00025 00026 #include <vector> 00027 00028 #include <boost/array.hpp> 00029 #include <boost/type_traits.hpp> 00030 00031 #include <variant_topic_tools/BuiltinTypeTraits.h> 00032 #include <variant_topic_tools/MessageTypeTraits.h> 00033 00034 namespace variant_topic_tools { 00035 namespace type_traits { 00036 template <typename T> struct IsArray : 00037 public boost::false_type { 00038 }; 00039 00040 template <typename T> struct IsArray<T[]> : 00041 public boost::true_type { 00042 }; 00043 00044 template <typename T, size_t N> struct IsArray<T[N]> : 00045 public boost::true_type { 00046 }; 00047 00048 template <size_t N> struct IsArray<char[N]> : 00049 public boost::false_type { 00050 }; 00051 00052 template <typename T, typename D = void> struct ArrayMemberType { 00053 typedef T ValueType; 00054 }; 00055 00056 template <typename D> struct ArrayMemberType<bool, D> { 00057 typedef uint8_t ValueType; 00058 }; 00059 00060 template <typename T> struct ArrayType; 00061 00062 template <typename T> struct ArrayType<T[]> { 00063 typedef T MemberType; 00064 typedef typename ArrayMemberType<T>::ValueType MemberValueType; 00065 typedef std::vector<MemberValueType> ValueType; 00066 static const size_t NumMembers = 0; 00067 typedef boost::true_type IsDynamic; 00068 typedef ros::message_traits::IsFixedSize<ValueType> IsFixedSize; 00069 typedef ros::message_traits::IsSimple<ValueType> IsSimple; 00070 }; 00071 00072 template <typename T, size_t N> struct ArrayType<T[N]> { 00073 typedef T MemberType; 00074 typedef typename ArrayMemberType<T>::ValueType MemberValueType; 00075 typedef boost::array<MemberValueType, N> ValueType; 00076 static const size_t NumMembers = N; 00077 typedef boost::false_type IsDynamic; 00078 typedef ros::message_traits::IsFixedSize<ValueType> IsFixedSize; 00079 typedef ros::message_traits::IsSimple<ValueType> IsSimple; 00080 }; 00081 00082 template <typename T> struct ToArrayType { 00083 typedef T ArrayType; 00084 }; 00085 00086 template <typename T> struct ToArrayType<std::vector<T> > { 00087 typedef T ArrayType[]; 00088 }; 00089 00090 template <typename T, size_t N> struct ToArrayType<boost::array<T, N> > { 00091 typedef T ArrayType[N]; 00092 }; 00093 }; 00094 }; 00095 00096 #endif