DataTypeRegistry.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_REGISTRY_H
24 #define VARIANT_TOPIC_TOOLS_DATA_TYPE_REGISTRY_H
25 
26 #include <typeinfo>
27 
28 #include <boost/unordered_map.hpp>
29 #include <boost/type_traits.hpp>
30 
35 
36 namespace variant_topic_tools {
40  friend class DataType;
41  public:
45 
49 
59  DataType getDataType(const std::string& identifier);
60 
67  DataType getDataType(const std::string& identifier) const;
68 
74  DataType getDataType(const std::type_info& typeInfo) const;
75 
83  template <typename T> DataType getDataType();
84 
88  template <typename T> DataType getDataType() const;
89 
92  void write(std::ostream& stream) const;
93 
97  DataType operator[](const std::string& identifier);
98 
102  DataType operator[](const std::string& identifier) const;
103 
107  DataType operator[](const std::type_info& typeInfo) const;
108 
112  ArrayDataType addArrayDataType(const DataType& memberType, size_t
113  numMembers = 0);
114 
118  template <typename T> ArrayDataType addArrayDataType();
119 
124  template <typename T, size_t N> ArrayDataType addArrayDataType();
125 
128  template <typename T> BuiltinDataType addBuiltinDataType(const
129  std::string& identifier);
130 
136  MessageDataType addMessageDataType(const std::string& identifier,
138  constantMembers = MessageFieldCollection<MessageConstant>(),
140  variableMembers = MessageFieldCollection<MessageVariable>());
141 
145  MessageDataType addMessageDataType(const std::string&
146  identifier, const std::string& definition);
147 
151  template <typename T> MessageDataType addMessageDataType();
152 
155  void addDataType(const DataType& dataType);
156 
160  template <typename T> void addDataType();
161 
164  void removeDataType(const DataType& dataType);
165 
168  void clear();
169 
170  protected:
173  class Impl {
174  public:
177  Impl();
178 
181  ~Impl();
182 
185  boost::unordered_map<std::string, DataType> dataTypesByIdentifier;
186 
189  boost::unordered_multimap<const std::type_info*, DataType, TypeInfoHash>
191  };
192 
197 
201  typedef boost::weak_ptr<Impl> ImplWPtr;
202 
205  static ImplPtr impl;
206 
210  template <typename T> static BuiltinDataType createDataType(typename
211  boost::enable_if<type_traits::IsBuiltin<T> >::type* = 0);
212 
216  template <typename T> static ArrayDataType createDataType(typename
217  boost::enable_if<type_traits::IsArray<T> >::type* = 0);
218 
222  template <typename T> static MessageDataType createDataType(typename
223  boost::enable_if<type_traits::IsMessage<T> >::type* = 0);
224  };
225 
228  std::ostream& operator<<(std::ostream& stream, const DataTypeRegistry&
229  dataTypeRegistry);
230 };
231 
232 #include <variant_topic_tools/DataTypeRegistry.tpp>
233 
234 #endif
boost::unordered_map< std::string, DataType > dataTypesByIdentifier
The registered data types by identifier.
boost::weak_ptr< Impl > ImplWPtr
Declaration of the data type registry implementation weak pointer type.
BuiltinDataType addBuiltinDataType(const std::string &identifier)
Add a built-in data type to the data type registry.
boost::unordered_multimap< const std::type_info *, DataType, TypeInfoHash > dataTypesByInfo
The registered data types by type information.
static BuiltinDataType createDataType(typename boost::enable_if< type_traits::IsBuiltin< T > >::type *=0)
Create a data type (overloaded version creating an invalid built-in data type)
Header file providing forward declarations for the variant topic tools.
void clear()
Clear the data type registry.
Header file providing the MessageFieldCollection class interface.
MessageDataType addMessageDataType()
Add a message data type to the data type registry (strong-typed version templated on the message type...
Header file providing the TypeInfoHash class interface.
void write(std::ostream &stream) const
Write the data type registry to a stream.
Header file providing the data type traits.
void removeDataType(const DataType &dataType)
Remove a data type from the data type registry.
DataType operator[](const std::string &identifier)
Operator for retrieving a data type from the registry by identifier (non-const version) ...
std::ostream & operator<<(std::ostream &stream, const DataType &dataType)
Operator for writing the data type to a stream.
Definition: DataType.cpp:190
boost::shared_ptr< Impl > ImplPtr
Declaration of the data type registry implementation pointer type.
void addDataType()
Add a data type to the data type registry (templated version)
static ImplPtr impl
The data type registry&#39;s implementation.
ArrayDataType addArrayDataType()
Add an array data type to the data type registry (strong-typed version templated on the array type) ...
DataType getDataType()
Retrieve a data type from the registry by type information (templated non-const version) ...
Forward declaration of the message field collection.
Definition: Forwards.h:64


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