DataType.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2014 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
23 #ifndef VARIANT_TOPIC_TOOLS_DATA_TYPE_H
24 #define VARIANT_TOPIC_TOOLS_DATA_TYPE_H
25 
26 #include <typeinfo>
27 #include <vector>
28 
29 #include <ros/ros.h>
30 
32 
33 namespace variant_topic_tools {
36  class DataType {
37  friend class DataTypeHash;
38  friend class DataTypeRegistry;
39  friend class Serializer;
40  public:
43  DataType();
44 
51  DataType(const char* identifier);
52 
59  DataType(const std::string& identifier);
60 
67  DataType(const std::type_info& typeInfo);
68 
71  DataType(const DataType& src);
72 
75  virtual ~DataType();
76 
79  const std::string& getIdentifier() const;
80 
86  const std::type_info& getTypeInfo() const;
87 
92  size_t getSize() const;
93 
96  bool isArray() const;
97 
100  bool isBuiltin() const;
101 
104  bool isMessage() const;
105 
109  bool isFixedSize() const;
110 
115  bool isSimple() const;
116 
119  bool isValid() const;
120 
123  bool hasTypeInfo() const;
124 
127  void clear();
128 
131  void write(std::ostream& stream) const;
132 
136 
139  Variant createVariant() const;
140 
143  virtual DataType& operator=(const DataType& src);
144 
147  inline operator void*() const {
148  return (impl) ? (void*)1 : (void*)0;
149  };
150 
153  inline bool operator==(const DataType& dataType) const {
154  return (impl && dataType.impl) ? (*impl == *dataType.impl) :
155  (impl == dataType.impl);
156  };
157 
160  inline bool operator!=(const DataType& dataType) const {
161  return (impl && dataType.impl) ? (*impl != *dataType.impl) :
162  (impl != dataType.impl);
163  };
164 
165  protected:
168  class Impl {
169  public:
172  Impl();
173 
176  virtual ~Impl();
177 
181  virtual const std::string& getIdentifier() const = 0;
182 
185  virtual const std::type_info& getTypeInfo() const;
186 
190  virtual size_t getSize() const = 0;
191 
195  virtual bool isFixedSize() const = 0;
196 
200  virtual bool isSimple() const = 0;
201 
204  virtual Serializer createSerializer(const DataType& type) const = 0;
205 
208  virtual Variant createVariant(const DataType& type) const = 0;
209  };
210 
218 
223 
226  ImplPtr impl;
227  };
228 
231  std::ostream& operator<<(std::ostream& stream, const DataType& dataType);
232 };
233 
234 #endif
virtual Variant createVariant(const DataType &type) const =0
Create a variant from this data type (abstract declaration)
Serializer createSerializer() const
Create a serializer for this data type.
Definition: DataType.cpp:161
bool hasTypeInfo() const
True, if this data type has type information.
Definition: DataType.cpp:137
Header file providing forward declarations for the variant topic tools.
bool isArray() const
True, if this data type represents an array type.
Definition: DataType.cpp:98
bool isSimple() const
True, if this data type represents a simple data type, i.e., a data type such that an array of its in...
Definition: DataType.cpp:126
bool isMessage() const
True, if this data type represents a message type.
Definition: DataType.cpp:112
virtual Serializer createSerializer(const DataType &type) const =0
Create a serializer for this data type (abstract declaration)
bool operator==(const DataType &dataType) const
Equality comparison operator.
Definition: DataType.h:153
const std::type_info & getTypeInfo() const
Retrieve the type information associated with this data type.
Definition: DataType.cpp:84
bool isValid() const
True, if this data type is valid.
Definition: DataType.cpp:133
ImplPtr impl
The data type&#39;s implementation adapter.
Definition: DataType.h:226
boost::shared_ptr< boost::shared_ptr< Impl > > ImplPtr
Declaration of the data type implementation pointer type.
Definition: DataType.h:217
const std::string & getIdentifier() const
Retrieve the identifier representing this data type.
Definition: DataType.cpp:75
virtual ~DataType()
Destructor.
Definition: DataType.cpp:62
virtual const std::type_info & getTypeInfo() const
Retrieve the type information associated with this data type.
Definition: DataType.cpp:144
virtual DataType & operator=(const DataType &src)
Assignment operator.
Definition: DataType.cpp:179
std::ostream & operator<<(std::ostream &stream, const DataType &dataType)
Operator for writing the data type to a stream.
Definition: DataType.cpp:190
virtual bool isSimple() const =0
True, if this data type represents a simple data type (abstract declaration)
void write(std::ostream &stream) const
Write the data type to a stream.
Definition: DataType.cpp:156
boost::shared_ptr< boost::weak_ptr< Impl > > ImplWPtr
Declaration of the data type implementation weak pointer type.
Definition: DataType.h:222
bool operator!=(const DataType &dataType) const
Inequality comparison operator.
Definition: DataType.h:160
Data type implementation.
Definition: DataType.h:168
bool isFixedSize() const
True, if this data type represents a fixed-size data type, as opposed to a variable-size data type...
Definition: DataType.cpp:119
size_t getSize() const
Retrieve the size of the instances of this data type.
Definition: DataType.cpp:91
Variant createVariant() const
Create a variant from this data type.
Definition: DataType.cpp:168
bool isBuiltin() const
True, if this data type represents a built-in type.
Definition: DataType.cpp:105
void clear()
Clear the data type.
Definition: DataType.cpp:152
virtual const std::string & getIdentifier() const =0
Retrieve the identifier representing this data type (abstract declaration)
virtual bool isFixedSize() const =0
True, if this data type represents a fixed-size data type (abstract declaration)
virtual ~Impl()
Destructor.
Definition: DataType.cpp:68
DataType()
Default constructor.
Definition: DataType.cpp:33
virtual size_t getSize() const =0
Retrieve the size of the instances of this data type (abstract declaration)


variant_topic_tools
Author(s): Ralf Kaestner
autogenerated on Sat Jan 9 2021 03:56:49