MessageDataType.h
Go to the documentation of this file.
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_MESSAGE_DATA_TYPE_H
00024 #define VARIANT_TOPIC_TOOLS_MESSAGE_DATA_TYPE_H
00025 
00026 #include <variant_topic_tools/DataType.h>
00027 #include <variant_topic_tools/DataTypeTraits.h>
00028 #include <variant_topic_tools/MD5Sum.h>
00029 #include <variant_topic_tools/MessageFieldCollection.h>
00030 #include <variant_topic_tools/MessageTypeTraits.h>
00031 
00032 namespace variant_topic_tools {
00035   class MessageDataType :
00036     public DataType {
00037   friend class DataType;
00038   friend class DataTypeRegistry;
00039   friend class MessageVariant;
00040   public:
00043     MessageDataType();
00044 
00047     MessageDataType(const MessageDataType& src);
00048 
00051     MessageDataType(const DataType& src);
00052 
00055     virtual ~MessageDataType();
00056 
00059     std::string getMD5Sum() const;
00060 
00063     const std::string& getDefinition() const;
00064 
00067     size_t getNumMembers() const;
00068 
00072     size_t getNumConstantMembers() const;
00073 
00077     size_t getNumVariableMembers() const;
00078 
00081     const MessageMember& getMember(const std::string& name) const;
00082 
00085     const MessageMember& getMember(int index) const;
00086 
00089     const MessageConstant& getConstantMember(const std::string& name) const;
00090 
00093     const MessageConstant& getConstantMember(int index) const;
00094 
00097     const MessageVariable& getVariableMember(const std::string& name) const;
00098 
00101     const MessageVariable& getVariableMember(int index) const;
00102 
00106     bool hasMember(const std::string& name) const;
00107 
00111     bool hasConstantMember(const std::string& name) const;
00112 
00116     bool hasVariableMember(const std::string& name) const;
00117 
00120     bool hasHeader() const;
00121 
00125     void addConstantMember(const MessageConstant& member);
00126 
00130     MessageConstant addConstantMember(const std::string& name, const
00131       Variant& value);
00132 
00136     template <typename T> MessageConstant addConstantMember(const
00137       std::string& name, const T& value);
00138 
00142     void addVariableMember(const MessageVariable& member);
00143 
00147     MessageVariable addVariableMember(const std::string& name, const
00148       DataType& type);
00149 
00153     template <typename T> MessageVariable addVariableMember(const
00154       std::string& name);
00155 
00158     MessageDataType& operator=(const DataType& src);
00159 
00163     const MessageMember& operator[](int index) const;
00164 
00165   protected:
00168     class Impl :
00169       public DataType::Impl {
00170     public:
00174       Impl(const MessageFieldCollection<MessageConstant>& constantMembers,
00175         const MessageFieldCollection<MessageVariable>& variableMembers);
00176 
00179       Impl(const std::string& identifier, const std::string& definition);
00180 
00183       virtual ~Impl();
00184 
00188       virtual std::string getMD5Sum() const = 0;
00189 
00193       virtual const std::string& getDefinition() const = 0;
00194 
00198       virtual void addConstantMember(const MessageConstant& member) = 0;
00199 
00203       virtual void addVariableMember(const MessageVariable& member) = 0;
00204 
00207       MessageFieldCollection<MessageConstant> constantMembers;
00208 
00211       MessageFieldCollection<MessageVariable> variableMembers;
00212     };
00213 
00216     class ImplV :
00217       public Impl {
00218     public:
00222       ImplV(const std::string& identifier, const MessageFieldCollection<
00223         MessageConstant>& constantMembers, const MessageFieldCollection<
00224         MessageVariable>& variableMembers);
00225 
00229       ImplV(const std::string& identifier, const std::string& definition);
00230 
00233       virtual ~ImplV();
00234 
00238       const std::string& getIdentifier() const;
00239 
00243       std::string getMD5Sum() const;
00244 
00248       const std::string& getDefinition() const;
00249 
00253       size_t getSize() const;
00254 
00258       bool isFixedSize() const;
00259 
00263       bool isSimple() const;
00264 
00267       Serializer createSerializer(const DataType& type) const;
00268 
00271       Variant createVariant(const DataType& type) const;
00272 
00276       void addConstantMember(const MessageConstant& member);
00277 
00281       void addVariableMember(const MessageVariable& member);
00282 
00285       void recalculateMD5Sum();
00286 
00289       std::string identifier;
00290 
00293       MD5Sum md5Sum;
00294 
00297       std::string definition;
00298     };
00299 
00303     template <typename T> class ImplT :
00304       public Impl {
00305     public:
00306       BOOST_STATIC_ASSERT(type_traits::IsMessage<T>::value);
00307 
00310       ImplT();
00311 
00314       virtual ~ImplT();
00315 
00319       const std::string& getIdentifier() const;
00320 
00324       const std::type_info& getTypeInfo() const;
00325 
00329       std::string getMD5Sum() const;
00330 
00334       const std::string& getDefinition() const;
00335 
00339       size_t getSize() const;
00340 
00344       bool isFixedSize() const;
00345 
00349       bool isSimple() const;
00350 
00353       Serializer createSerializer(const DataType& type) const;
00354 
00357       Variant createVariant(const DataType& type) const;
00358 
00362       void addConstantMember(const MessageConstant& member);
00363 
00367       void addVariableMember(const MessageVariable& member);
00368 
00372       template <typename M> void next(const M& member);
00373 
00377       T message;
00378 
00381       size_t memberIndex;
00382     };
00383 
00387     MessageDataType(const std::string& identifier, const
00388       MessageFieldCollection<MessageConstant>& constantMembers, const
00389       MessageFieldCollection<MessageVariable>& variableMembers);
00390 
00394     MessageDataType(const std::string& identifier, const std::string&
00395       definition);
00396 
00400     template <typename T> static MessageDataType create();
00401 
00405     template <typename T, typename M> static void addMember(
00406       MessageVariable& member, size_t offset, typename boost::enable_if<
00407       type_traits::IsArray<M> >::type* = 0, typename boost::enable_if<
00408       typename type_traits::ArrayType<M>::IsDynamic>::type* = 0);
00409 
00413     template <typename T, typename M> static void addMember(
00414       MessageVariable& member, size_t offset, typename boost::enable_if<
00415       type_traits::IsArray<M> >::type* = 0, typename boost::disable_if<
00416       typename type_traits::ArrayType<M>::IsDynamic>::type* = 0);
00417 
00421     template <typename T, typename M> static void addMember(
00422       MessageVariable& member, size_t offset, typename boost::
00423       disable_if<type_traits::IsArray<M> >::type* = 0);
00424   };
00425 };
00426 
00427 #include <variant_topic_tools/MessageDataType.tpp>
00428 
00429 #endif


variant_topic_tools
Author(s): Ralf Kaestner
autogenerated on Fri Aug 5 2016 06:06:27