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_DATA_TYPE_H 00024 #define VARIANT_TOPIC_TOOLS_DATA_TYPE_H 00025 00026 #include <typeinfo> 00027 #include <vector> 00028 00029 #include <ros/ros.h> 00030 00031 #include <variant_topic_tools/Forwards.h> 00032 00033 namespace variant_topic_tools { 00036 class DataType { 00037 friend class DataTypeHash; 00038 friend class DataTypeRegistry; 00039 friend class Serializer; 00040 public: 00043 DataType(); 00044 00051 DataType(const char* identifier); 00052 00059 DataType(const std::string& identifier); 00060 00067 DataType(const std::type_info& typeInfo); 00068 00071 DataType(const DataType& src); 00072 00075 virtual ~DataType(); 00076 00079 const std::string& getIdentifier() const; 00080 00086 const std::type_info& getTypeInfo() const; 00087 00092 size_t getSize() const; 00093 00096 bool isArray() const; 00097 00100 bool isBuiltin() const; 00101 00104 bool isMessage() const; 00105 00109 bool isFixedSize() const; 00110 00115 bool isSimple() const; 00116 00119 bool isValid() const; 00120 00123 bool hasTypeInfo() const; 00124 00127 void clear(); 00128 00131 void write(std::ostream& stream) const; 00132 00135 Serializer createSerializer() const; 00136 00139 Variant createVariant() const; 00140 00143 virtual DataType& operator=(const DataType& src); 00144 00147 inline operator void*() const { 00148 return (impl) ? (void*)1 : (void*)0; 00149 }; 00150 00153 inline bool operator==(const DataType& dataType) const { 00154 return (impl && dataType.impl) ? (*impl == *dataType.impl) : 00155 (impl == dataType.impl); 00156 }; 00157 00160 inline bool operator!=(const DataType& dataType) const { 00161 return (impl && dataType.impl) ? (*impl != *dataType.impl) : 00162 (impl != dataType.impl); 00163 }; 00164 00165 protected: 00168 class Impl { 00169 public: 00172 Impl(); 00173 00176 virtual ~Impl(); 00177 00181 virtual const std::string& getIdentifier() const = 0; 00182 00185 virtual const std::type_info& getTypeInfo() const; 00186 00190 virtual size_t getSize() const = 0; 00191 00195 virtual bool isFixedSize() const = 0; 00196 00200 virtual bool isSimple() const = 0; 00201 00204 virtual Serializer createSerializer(const DataType& type) const = 0; 00205 00208 virtual Variant createVariant(const DataType& type) const = 0; 00209 }; 00210 00217 typedef boost::shared_ptr<boost::shared_ptr<Impl> > ImplPtr; 00218 00222 typedef boost::shared_ptr<boost::weak_ptr<Impl> > ImplWPtr; 00223 00226 ImplPtr impl; 00227 }; 00228 00231 std::ostream& operator<<(std::ostream& stream, const DataType& dataType); 00232 }; 00233 00234 #endif