source: rrlib_rtti/detail/tDataTypeInfo.h @ 115:1b996ddfb1cc

17.03
Last change on this file since 115:1b996ddfb1cc was 115:1b996ddfb1cc, checked in by Max Reichardt <max.reichardt@…>, 17 months ago

Makes associative containers no longer auto-register their element types (currently no use (case); std::pair elements with const element type(s) would cause issues in generic handling)

File size: 35.0 KB
Line 
1//
2// You received this file as part of RRLib
3// Robotics Research Library
4//
5// Copyright (C) Finroc GbR (finroc.org)
6//
7// This program is free software; you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation; either version 2 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License along
18// with this program; if not, write to the Free Software Foundation, Inc.,
19// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20//
21//----------------------------------------------------------------------
22/*!\file    rrlib/rtti/detail/tDataTypeInfo.h
23 *
24 * \author  Max Reichardt
25 *
26 * \date    2016-07-23
27 *
28 * \brief   Contains tDataTypeInfo
29 *
30 * \b tDataTypeInfo
31 *
32 * Type info for a specific data type T - provided mostly as compile-time constant
33 *
34 */
35//----------------------------------------------------------------------
36#ifndef __rrlib__rtti__detail__tDataTypeInfo_h__
37#define __rrlib__rtti__detail__tDataTypeInfo_h__
38
39//----------------------------------------------------------------------
40// External includes (system with <>, local with "")
41//----------------------------------------------------------------------
42
43//----------------------------------------------------------------------
44// Internal includes with ""
45//----------------------------------------------------------------------
46#include "rrlib/rtti/detail/tTypeInfo.h"
47#include "rrlib/rtti/type_traits.h"
48#include "rrlib/rtti/detail/generic_operations.h"
49
50//----------------------------------------------------------------------
51// Namespace declaration
52//----------------------------------------------------------------------
53namespace rrlib
54{
55namespace rtti
56{
57namespace detail
58{
59
60enum tTableLayoutFlags
61{
62  eTLF_BINARY_OPS = 1,
63  eTLF_BINARY_SERIALIZATION = 2,
64  eTLF_OTHER_SERIALIZATION = 4,
65  eTLF_VECTOR_TYPE = 8,
66  eTLF_ENUM = 16,
67  eTLF_TUPLE = 32
68};
69
70//----------------------------------------------------------------------
71// Forward declarations / typedefs / enums
72//----------------------------------------------------------------------
73template <typename T>
74struct TableLayoutFlags
75{
76  enum { value = std::is_enum<T>::value ? eTLF_ENUM :
77                 (((IsStdPair<T>::value || IsStdTuple<T>::value) ? eTLF_TUPLE : 0) |
78                  (IsStdVector<T>::value ? eTLF_VECTOR_TYPE : 0) |
79                  (!(SupportsBitwiseCopy<T>::value && IsDefaultConstructionZeroMemory<T>::value) ? eTLF_BINARY_OPS : 0) |
80                  (serialization::IsBinarySerializable<T>::value ? eTLF_BINARY_SERIALIZATION : 0) |
81                  ((serialization::IsXMLSerializable<T>::value || serialization::IsStringSerializable<T>::value) && (!(IsStdPair<T>::value || IsStdTuple<T>::value)) ? eTLF_OTHER_SERIALIZATION : 0))
82       };
83};
84
85struct Empty
86{};
87
88//----------------------------------------------------------------------
89// Class declaration
90//----------------------------------------------------------------------
91//! Data Type Info
92/*!
93 * Type info for a specific data type T - provided mostly as compile-time constant
94 */
95template <typename T, unsigned int Tflags = TableLayoutFlags<T>::value>
96struct tDataTypeInfo
97{
98  static_assert(!std::is_same<T, T>::value, "This should not be instantiated");
99  static tTypeInfo::tSharedInfo shared_info;
100  struct tTable
101  {};
102  static constexpr tTable value = {};
103};
104
105template <typename T>
106struct tDataTypeInfo<T, 0>
107{
108  static tTypeInfo::tSharedInfo shared_info;
109  typedef typename NormalizedType<typename ElementType<typename std::conditional<serialization::IsAssociativeContainer<T>::value, void, T>::type>::type>::type tElement;
110  typedef typename std::conditional<std::is_same<typename UnderlyingType<T>::type, T>::value, void, typename UnderlyingType<T>::type>::type tUnderlying;
111  struct tTable
112  {
113    tTypeInfo data_type_info;
114  } static constexpr value =
115  {
116    tTypeInfo(typeid(T), TypeTraitsVector<T>::value, std::is_same<void, tUnderlying>::value ? nullptr : &tDataTypeInfo<tUnderlying>::value.data_type_info, std::is_same<tElement, void>::value ? &tTypeInfo::cNULL_TYPE_INFO : &tDataTypeInfo<tElement>::value.data_type_info, &shared_info, sizeof(T)) // Type info
117  };
118};
119
120template <typename T>
121struct tDataTypeInfo<T, eTLF_BINARY_OPS>
122{
123  static tTypeInfo::tSharedInfo shared_info;
124  typedef typename NormalizedType<typename ElementType<typename std::conditional<serialization::IsAssociativeContainer<T>::value, void, T>::type>::type>::type tElement;
125  typedef typename std::conditional<std::is_same<typename UnderlyingType<T>::type, T>::value, void, typename UnderlyingType<T>::type>::type tUnderlying;
126  struct tTable
127  {
128    tTypeInfo data_type_info;
129    tBinaryOperations binary_operations;
130  } static constexpr value =
131  {
132    tTypeInfo(typeid(T), TypeTraitsVector<T>::value, std::is_same<void, tUnderlying>::value ? nullptr : &tDataTypeInfo<tUnderlying>::value.data_type_info, std::is_same<tElement, void>::value ? &tTypeInfo::cNULL_TYPE_INFO : &tDataTypeInfo<tElement>::value.data_type_info, &shared_info, sizeof(T)), // Type info
133    { rtti::ConstructorFunction<T>::value, rtti::DestructorFunction<T>::value, rtti::DeepCopyFunction<T>::value, EqualsFunction<T>::value } // Binary operations
134  };
135};
136
137template <typename T>
138struct tDataTypeInfo<T, eTLF_BINARY_SERIALIZATION>
139{
140  static tTypeInfo::tSharedInfo shared_info;
141  typedef typename NormalizedType<typename ElementType<typename std::conditional<serialization::IsAssociativeContainer<T>::value, void, T>::type>::type>::type tElement;
142  typedef typename std::conditional<std::is_same<typename UnderlyingType<T>::type, T>::value, void, typename UnderlyingType<T>::type>::type tUnderlying;
143  struct tTable
144  {
145    tTypeInfo data_type_info;
146    tBinarySerializationOperations binary_serialization_operations;
147  } static constexpr value =
148  {
149    tTypeInfo(typeid(T), TypeTraitsVector<T>::value, std::is_same<void, tUnderlying>::value ? nullptr : &tDataTypeInfo<tUnderlying>::value.data_type_info, std::is_same<tElement, void>::value ? &tTypeInfo::cNULL_TYPE_INFO : &tDataTypeInfo<tElement>::value.data_type_info, &shared_info, sizeof(T)), // Type info
150    { rtti::DeserializeFromBinaryFunction<T>::value, rtti::SerializeToBinaryFunction<T>::value } // Binary serialization
151  };
152};
153
154template <typename T>
155struct tDataTypeInfo < T, eTLF_BINARY_SERIALIZATION | eTLF_BINARY_OPS >
156{
157  static tTypeInfo::tSharedInfo shared_info;
158  typedef typename NormalizedType<typename ElementType<typename std::conditional<serialization::IsAssociativeContainer<T>::value, void, T>::type>::type>::type tElement;
159  typedef typename std::conditional<std::is_same<typename UnderlyingType<T>::type, T>::value, void, typename UnderlyingType<T>::type>::type tUnderlying;
160  struct tTable
161  {
162    tTypeInfo data_type_info;
163    tBinaryOperations binary_operations;
164    tBinarySerializationOperations binary_serialization_operations;
165  } static constexpr value =
166  {
167    tTypeInfo(typeid(T), TypeTraitsVector<T>::value, std::is_same<void, tUnderlying>::value ? nullptr : &tDataTypeInfo<tUnderlying>::value.data_type_info, std::is_same<tElement, void>::value ? &tTypeInfo::cNULL_TYPE_INFO : &tDataTypeInfo<tElement>::value.data_type_info, &shared_info, sizeof(T)), // Type info
168    { rtti::ConstructorFunction<T>::value, rtti::DestructorFunction<T>::value, rtti::DeepCopyFunction<T>::value, EqualsFunction<T>::value }, // Binary operations
169    { rtti::DeserializeFromBinaryFunction<T>::value, rtti::SerializeToBinaryFunction<T>::value } // Binary serialization
170  };
171};
172
173template <typename T>
174struct tDataTypeInfo<T, eTLF_OTHER_SERIALIZATION>
175{
176  static tTypeInfo::tSharedInfo shared_info;
177  typedef typename NormalizedType<typename ElementType<typename std::conditional<serialization::IsAssociativeContainer<T>::value, void, T>::type>::type>::type tElement;
178  typedef typename std::conditional<std::is_same<typename UnderlyingType<T>::type, T>::value, void, typename UnderlyingType<T>::type>::type tUnderlying;
179  struct tTable
180  {
181    tTypeInfo data_type_info;
182    typename std::conditional<serialization::IsStringSerializable<T>::value, tStringSerializationOperations, tXMLSerializationOperations>::type other_serialization_operations;
183  } static constexpr value =
184  {
185    tTypeInfo(typeid(T), TypeTraitsVector<T>::value, std::is_same<void, tUnderlying>::value ? nullptr : &tDataTypeInfo<tUnderlying>::value.data_type_info, std::is_same<tElement, void>::value ? &tTypeInfo::cNULL_TYPE_INFO : &tDataTypeInfo<tElement>::value.data_type_info, &shared_info, sizeof(T)), // Type info
186    { std::conditional<serialization::IsStringSerializable<T>::value, rtti::DeserializeFromStringFunction<T>, rtti::DeserializeFromXMLFunction<T>>::type::value, std::conditional<serialization::IsStringSerializable<T>::value, rtti::SerializeToStringFunction<T>, rtti::SerializeToXMLFunction<T>>::type::value } // Other serialization
187  };
188};
189
190template <typename T>
191struct tDataTypeInfo < T, eTLF_OTHER_SERIALIZATION | eTLF_BINARY_OPS >
192{
193  static tTypeInfo::tSharedInfo shared_info;
194  typedef typename NormalizedType<typename ElementType<typename std::conditional<serialization::IsAssociativeContainer<T>::value, void, T>::type>::type>::type tElement;
195  typedef typename std::conditional<std::is_same<typename UnderlyingType<T>::type, T>::value, void, typename UnderlyingType<T>::type>::type tUnderlying;
196  struct tTable
197  {
198    tTypeInfo data_type_info;
199    tBinaryOperations binary_operations;
200    typename std::conditional<serialization::IsStringSerializable<T>::value, tStringSerializationOperations, tXMLSerializationOperations>::type other_serialization_operations;
201  } static constexpr value =
202  {
203    tTypeInfo(typeid(T), TypeTraitsVector<T>::value, std::is_same<void, tUnderlying>::value ? nullptr : &tDataTypeInfo<tUnderlying>::value.data_type_info, std::is_same<tElement, void>::value ? &tTypeInfo::cNULL_TYPE_INFO : &tDataTypeInfo<tElement>::value.data_type_info, &shared_info, sizeof(T)), // Type info
204    { rtti::ConstructorFunction<T>::value, rtti::DestructorFunction<T>::value, rtti::DeepCopyFunction<T>::value, EqualsFunction<T>::value }, // Binary operations
205    { std::conditional<serialization::IsStringSerializable<T>::value, rtti::DeserializeFromStringFunction<T>, rtti::DeserializeFromXMLFunction<T>>::type::value, std::conditional<serialization::IsStringSerializable<T>::value, rtti::SerializeToStringFunction<T>, rtti::SerializeToXMLFunction<T>>::type::value } // Other serialization
206  };
207};
208
209template <typename T>
210struct tDataTypeInfo < T, eTLF_OTHER_SERIALIZATION | eTLF_BINARY_SERIALIZATION >
211{
212  static tTypeInfo::tSharedInfo shared_info;
213  typedef typename NormalizedType<typename ElementType<typename std::conditional<serialization::IsAssociativeContainer<T>::value, void, T>::type>::type>::type tElement;
214  typedef typename std::conditional<std::is_same<typename UnderlyingType<T>::type, T>::value, void, typename UnderlyingType<T>::type>::type tUnderlying;
215  struct tTable
216  {
217    tTypeInfo data_type_info;
218    tBinarySerializationOperations binary_serialization_operations;
219    typename std::conditional<serialization::IsStringSerializable<T>::value, tStringSerializationOperations, tXMLSerializationOperations>::type other_serialization_operations;
220  } static constexpr value =
221  {
222    tTypeInfo(typeid(T), TypeTraitsVector<T>::value, std::is_same<void, tUnderlying>::value ? nullptr : &tDataTypeInfo<tUnderlying>::value.data_type_info, std::is_same<tElement, void>::value ? &tTypeInfo::cNULL_TYPE_INFO : &tDataTypeInfo<tElement>::value.data_type_info, &shared_info, sizeof(T)), // Type info
223    { rtti::DeserializeFromBinaryFunction<T>::value, rtti::SerializeToBinaryFunction<T>::value }, // Binary serialization
224    { std::conditional<serialization::IsStringSerializable<T>::value, rtti::DeserializeFromStringFunction<T>, rtti::DeserializeFromXMLFunction<T>>::type::value, std::conditional<serialization::IsStringSerializable<T>::value, rtti::SerializeToStringFunction<T>, rtti::SerializeToXMLFunction<T>>::type::value } // Other serialization
225  };
226};
227
228template <typename T>
229struct tDataTypeInfo < T, eTLF_OTHER_SERIALIZATION | eTLF_BINARY_SERIALIZATION | eTLF_BINARY_OPS >
230{
231  static tTypeInfo::tSharedInfo shared_info;
232  typedef typename NormalizedType<typename ElementType<typename std::conditional<serialization::IsAssociativeContainer<T>::value, void, T>::type>::type>::type tElement;
233  typedef typename std::conditional<std::is_same<typename UnderlyingType<T>::type, T>::value, void, typename UnderlyingType<T>::type>::type tUnderlying;
234  struct tTable
235  {
236    tTypeInfo data_type_info;
237    tBinaryOperations binary_operations;
238    tBinarySerializationOperations binary_serialization_operations;
239    typename std::conditional<serialization::IsStringSerializable<T>::value, tStringSerializationOperations, tXMLSerializationOperations>::type other_serialization_operations;
240  } static constexpr value =
241  {
242    tTypeInfo(typeid(T), TypeTraitsVector<T>::value, std::is_same<void, tUnderlying>::value ? nullptr : &tDataTypeInfo<tUnderlying>::value.data_type_info, std::is_same<tElement, void>::value ? &tTypeInfo::cNULL_TYPE_INFO : &tDataTypeInfo<tElement>::value.data_type_info, &shared_info, sizeof(T)), // Type info
243    { rtti::ConstructorFunction<T>::value, rtti::DestructorFunction<T>::value, rtti::DeepCopyFunction<T>::value, EqualsFunction<T>::value }, // Binary operations
244    { rtti::DeserializeFromBinaryFunction<T>::value, rtti::SerializeToBinaryFunction<T>::value }, // Binary serialization
245    { std::conditional<serialization::IsStringSerializable<T>::value, rtti::DeserializeFromStringFunction<T>, rtti::DeserializeFromXMLFunction<T>>::type::value, std::conditional<serialization::IsStringSerializable<T>::value, rtti::SerializeToStringFunction<T>, rtti::SerializeToXMLFunction<T>>::type::value } // Other serialization
246  };
247};
248
249template <typename T>
250struct tDataTypeInfo < T, eTLF_VECTOR_TYPE | eTLF_BINARY_OPS >
251{
252  static tTypeInfo::tSharedInfo shared_info;
253  typedef typename NormalizedType<typename ElementType<T>::type>::type tElement;
254  typedef typename std::conditional<std::is_same<typename UnderlyingType<T>::type, T>::value, void, typename UnderlyingType<T>::type>::type tUnderlying;
255  struct tTable
256  {
257    tTypeInfo data_type_info;
258    tBinaryOperations binary_operations_list_1;
259    tBinaryOperationsVector binary_operations_list_2;
260  } static constexpr value =
261  {
262    tTypeInfo(typeid(T), TypeTraitsVector<T>::value, std::is_same<void, tUnderlying>::value ? nullptr : &tDataTypeInfo<tUnderlying>::value.data_type_info, std::is_same<tElement, void>::value ? &tTypeInfo::cNULL_TYPE_INFO : &tDataTypeInfo<tElement>::value.data_type_info, &shared_info, sizeof(T)), // Type info
263    { rtti::ConstructorFunction<T>::value, rtti::DestructorFunction<T>::value, rtti::DeepCopyFunction<T>::value, EqualsFunction<T>::value }, // Vector binary operations 1
264    { rtti::GetVectorElementFunction<T>::value, rtti::GetVectorSizeFunction<T>::value, rtti::ResizeVectorFunction<T>::value } // Vectory binary operations 2
265  };
266};
267
268template <typename T>
269struct tDataTypeInfo < T, eTLF_VECTOR_TYPE | eTLF_BINARY_SERIALIZATION | eTLF_BINARY_OPS >
270{
271  static tTypeInfo::tSharedInfo shared_info;
272  typedef typename NormalizedType<typename ElementType<T>::type>::type tElement;
273  typedef typename std::conditional<std::is_same<typename UnderlyingType<T>::type, T>::value, void, typename UnderlyingType<T>::type>::type tUnderlying;
274  struct tTable
275  {
276    tTypeInfo data_type_info;
277    tBinaryOperations binary_operations_list_1;
278    tBinaryOperationsVector binary_operations_list_2;
279    tBinarySerializationOperations binary_serialization_operations_list;
280  } static constexpr value =
281  {
282    tTypeInfo(typeid(T), TypeTraitsVector<T>::value, std::is_same<void, tUnderlying>::value ? nullptr : &tDataTypeInfo<tUnderlying>::value.data_type_info, std::is_same<tElement, void>::value ? &tTypeInfo::cNULL_TYPE_INFO : &tDataTypeInfo<tElement>::value.data_type_info, &shared_info, sizeof(T)), // Type info
283    { rtti::ConstructorFunction<T>::value, rtti::DestructorFunction<T>::value, rtti::DeepCopyFunction<T>::value, EqualsFunction<T>::value }, // Vector binary operations 1
284    { rtti::GetVectorElementFunction<T>::value, rtti::GetVectorSizeFunction<T>::value, rtti::ResizeVectorFunction<T>::value }, // Vectory binary operations 2
285    { rtti::DeserializeFromBinaryFunction<T>::value, rtti::SerializeToBinaryFunction<T>::value } // Binary serialization
286  };
287};
288
289template <typename T>
290struct tDataTypeInfo < T, eTLF_VECTOR_TYPE | eTLF_OTHER_SERIALIZATION | eTLF_BINARY_OPS >
291{
292  static tTypeInfo::tSharedInfo shared_info;
293  typedef typename NormalizedType<typename ElementType<T>::type>::type tElement;
294  typedef typename std::conditional<std::is_same<typename UnderlyingType<T>::type, T>::value, void, typename UnderlyingType<T>::type>::type tUnderlying;
295  struct tTable
296  {
297    tTypeInfo data_type_info;
298    tBinaryOperations binary_operations_list_1;
299    tBinaryOperationsVector binary_operations_list_2;
300    tXMLSerializationOperations xml_serialization_operations_list;
301  } static constexpr value =
302  {
303    tTypeInfo(typeid(T), TypeTraitsVector<T>::value, std::is_same<void, tUnderlying>::value ? nullptr : &tDataTypeInfo<tUnderlying>::value.data_type_info, std::is_same<tElement, void>::value ? &tTypeInfo::cNULL_TYPE_INFO : &tDataTypeInfo<tElement>::value.data_type_info, &shared_info, sizeof(T)), // Type info
304    { rtti::ConstructorFunction<T>::value, rtti::DestructorFunction<T>::value, rtti::DeepCopyFunction<T>::value, EqualsFunction<T>::value }, // Vector binary operations 1
305    { rtti::GetVectorElementFunction<T>::value, rtti::GetVectorSizeFunction<T>::value, rtti::ResizeVectorFunction<T>::value }, // Vectory binary operations 2
306    { rtti::DeserializeFromXMLFunction<T>::value, rtti::SerializeToXMLFunction<T>::value } // XML serialization
307  };
308};
309
310template <typename T>
311struct tDataTypeInfo < T, eTLF_VECTOR_TYPE | eTLF_OTHER_SERIALIZATION | eTLF_BINARY_SERIALIZATION | eTLF_BINARY_OPS >
312{
313  static tTypeInfo::tSharedInfo shared_info;
314  typedef typename NormalizedType<typename ElementType<T>::type>::type tElement;
315  typedef typename std::conditional<std::is_same<typename UnderlyingType<T>::type, T>::value, void, typename UnderlyingType<T>::type>::type tUnderlying;
316  struct tTable
317  {
318    tTypeInfo data_type_info;
319    tBinaryOperations binary_operations_list_1;
320    tBinaryOperationsVector binary_operations_list_2;
321    tBinarySerializationOperations binary_serialization_operations_list;
322    tXMLSerializationOperations xml_serialization_operations_list;
323  } static constexpr value =
324  {
325    tTypeInfo(typeid(T), TypeTraitsVector<T>::value, std::is_same<void, tUnderlying>::value ? nullptr : &tDataTypeInfo<tUnderlying>::value.data_type_info, std::is_same<tElement, void>::value ? &tTypeInfo::cNULL_TYPE_INFO : &tDataTypeInfo<tElement>::value.data_type_info, &shared_info, sizeof(T)), // Type info
326    { rtti::ConstructorFunction<T>::value, rtti::DestructorFunction<T>::value, rtti::DeepCopyFunction<T>::value, EqualsFunction<T>::value }, // Vector binary operations 1
327    { rtti::GetVectorElementFunction<T>::value, rtti::GetVectorSizeFunction<T>::value, rtti::ResizeVectorFunction<T>::value }, // Vectory binary operations 2
328    { rtti::DeserializeFromBinaryFunction<T>::value, rtti::SerializeToBinaryFunction<T>::value }, // Binary serialization
329    { rtti::DeserializeFromXMLFunction<T>::value, rtti::SerializeToXMLFunction<T>::value } // XML serialization
330  };
331};
332
333template <typename T>
334struct tDataTypeInfo<T, eTLF_ENUM>
335{
336  static tTypeInfo::tSharedInfoEnum shared_info;
337  static_assert(SupportsBitwiseCopy<T>::value, "Enums must support bitwise copy");
338  typedef std::vector<T> V;
339  typedef typename NormalizedType<typename ElementType<T>::type>::type tElement;
340  typedef typename std::conditional<std::is_same<typename UnderlyingType<T>::type, T>::value, void, typename UnderlyingType<T>::type>::type tUnderlying;
341  struct tTable
342  {
343    tTypeInfo data_type_info;
344    tBinaryOperations binary_operations;
345    tBinarySerializationOperations binary_serialization_operations;
346    typename std::conditional<serialization::IsStringSerializable<T>::value, tStringSerializationOperations, tXMLSerializationOperations>::type other_serialization_operations;
347  } static constexpr value =
348  {
349    tTypeInfo(typeid(T), TypeTraitsVector<T>::value, std::is_same<void, tUnderlying>::value ? nullptr : &tDataTypeInfo<tUnderlying>::value.data_type_info, std::is_same<tElement, void>::value ? &tTypeInfo::cNULL_TYPE_INFO : &tDataTypeInfo<tElement>::value.data_type_info, &shared_info, sizeof(T)), // Type info
350    { rtti::ConstructorFunction<T>::value, rtti::DestructorFunction<T>::value, rtti::DeepCopyFunction<T>::value, EqualsFunction<T>::value }, // Binary operations
351    { rtti::DeserializeFromBinaryFunction<T>::value, rtti::SerializeToBinaryFunction<T>::value }, // Binary serialization
352    { std::conditional<serialization::IsStringSerializable<T>::value, rtti::DeserializeFromStringFunction<T>, rtti::DeserializeFromXMLFunction<T>>::type::value, std::conditional<serialization::IsStringSerializable<T>::value, rtti::SerializeToStringFunction<T>, rtti::SerializeToXMLFunction<T>>::type::value } // Other serialization
353  };
354};
355
356template <typename T>
357struct tDataTypeInfo<T, eTLF_TUPLE>
358{
359  static tTypeInfo::tSharedInfoTuple shared_info;
360  typedef typename std::conditional<std::is_same<typename UnderlyingType<T>::type, T>::value, void, typename UnderlyingType<T>::type>::type tUnderlying;
361  struct tTable
362  {
363    tTypeInfo data_type_info;
364  } static constexpr value =
365  {
366    tTypeInfo(typeid(T), TypeTraitsVector<T>::value, std::is_same<void, tUnderlying>::value ? nullptr : &tDataTypeInfo<tUnderlying>::value.data_type_info, &tTypeInfo::cNULL_TYPE_INFO, &shared_info, sizeof(T)) // Type info
367  };
368};
369
370template <typename T>
371struct tDataTypeInfo < T, eTLF_TUPLE | eTLF_BINARY_OPS >
372{
373  static tTypeInfo::tSharedInfoTuple shared_info;
374  typedef typename std::conditional<std::is_same<typename UnderlyingType<T>::type, T>::value, void, typename UnderlyingType<T>::type>::type tUnderlying;
375  struct tTable
376  {
377    tTypeInfo data_type_info;
378    tBinaryOperations binary_operations;
379  } static constexpr value =
380  {
381    tTypeInfo(typeid(T), TypeTraitsVector<T>::value, std::is_same<void, tUnderlying>::value ? nullptr : &tDataTypeInfo<tUnderlying>::value.data_type_info, &tTypeInfo::cNULL_TYPE_INFO, &shared_info, sizeof(T)), // Type info
382    { rtti::ConstructorFunction<T>::value, rtti::DestructorFunction<T>::value, rtti::DeepCopyFunction<T>::value, EqualsFunction<T>::value } // Binary operations
383  };
384};
385
386template <typename T>
387struct tDataTypeInfo < T, eTLF_TUPLE | eTLF_BINARY_SERIALIZATION >
388{
389  static tTypeInfo::tSharedInfoTuple shared_info;
390  typedef typename std::conditional<std::is_same<typename UnderlyingType<T>::type, T>::value, void, typename UnderlyingType<T>::type>::type tUnderlying;
391  struct tTable
392  {
393    tTypeInfo data_type_info;
394    tBinarySerializationOperations binary_serialization_operations;
395  } static constexpr value =
396  {
397    tTypeInfo(typeid(T), TypeTraitsVector<T>::value, std::is_same<void, tUnderlying>::value ? nullptr : &tDataTypeInfo<tUnderlying>::value.data_type_info, &tTypeInfo::cNULL_TYPE_INFO, &shared_info, sizeof(T)), // Type info
398    { rtti::DeserializeFromBinaryFunction<T>::value, rtti::SerializeToBinaryFunction<T>::value } // Binary serialization
399  };
400};
401
402template <typename T>
403struct tDataTypeInfo < T, eTLF_TUPLE | eTLF_BINARY_SERIALIZATION | eTLF_BINARY_OPS >
404{
405  static tTypeInfo::tSharedInfoTuple shared_info;
406  typedef typename std::conditional<std::is_same<typename UnderlyingType<T>::type, T>::value, void, typename UnderlyingType<T>::type>::type tUnderlying;
407  struct tTable
408  {
409    tTypeInfo data_type_info;
410    tBinaryOperations binary_operations;
411    tBinarySerializationOperations binary_serialization_operations;
412  } static constexpr value =
413  {
414    tTypeInfo(typeid(T), TypeTraitsVector<T>::value, std::is_same<void, tUnderlying>::value ? nullptr : &tDataTypeInfo<tUnderlying>::value.data_type_info, &tTypeInfo::cNULL_TYPE_INFO, &shared_info, sizeof(T)), // Type info
415    { rtti::ConstructorFunction<T>::value, rtti::DestructorFunction<T>::value, rtti::DeepCopyFunction<T>::value, EqualsFunction<T>::value }, // Binary operations
416    { rtti::DeserializeFromBinaryFunction<T>::value, rtti::SerializeToBinaryFunction<T>::value } // Binary serialization
417  };
418};
419
420
421enum { cVOID_FLAGS = TableLayoutFlags<void>::value };
422
423template <>
424struct tDataTypeInfo<void, cVOID_FLAGS>
425{
426  struct tTable
427  {
428    tTypeInfo data_type_info;
429  } static constexpr value =
430  {
431    { typeid(void), 0, nullptr, nullptr, nullptr, 0 }, // Type info
432  };
433};
434
435template <unsigned int Tflags>
436struct ListTypeOffsetInTable
437{
438  enum { value = eTLF_ENUM ? 8 : (4 + (Tflags & eTLF_BINARY_OPS) ? 3 : 0 + (Tflags & eTLF_BINARY_SERIALIZATION) ? 2 : 0 + (Tflags & eTLF_OTHER_SERIALIZATION) ? 2 : 0) };
439};
440
441template <typename T, unsigned int Tflags> constexpr typename tDataTypeInfo<T, Tflags>::tTable tDataTypeInfo<T, Tflags>::value;
442template <typename T> constexpr typename tDataTypeInfo<T, 0>::tTable tDataTypeInfo<T, 0>::value;
443template <typename T> constexpr typename tDataTypeInfo<T, 1>::tTable tDataTypeInfo<T, 1>::value;
444template <typename T> constexpr typename tDataTypeInfo<T, 2>::tTable tDataTypeInfo<T, 2>::value;
445template <typename T> constexpr typename tDataTypeInfo<T, 3>::tTable tDataTypeInfo<T, 3>::value;
446template <typename T> constexpr typename tDataTypeInfo<T, 4>::tTable tDataTypeInfo<T, 4>::value;
447template <typename T> constexpr typename tDataTypeInfo<T, 5>::tTable tDataTypeInfo<T, 5>::value;
448template <typename T> constexpr typename tDataTypeInfo<T, 6>::tTable tDataTypeInfo<T, 6>::value;
449template <typename T> constexpr typename tDataTypeInfo<T, 7>::tTable tDataTypeInfo<T, 7>::value;
450template <typename T> constexpr typename tDataTypeInfo<T, 9>::tTable tDataTypeInfo<T, 9>::value;
451template <typename T> constexpr typename tDataTypeInfo<T, 11>::tTable tDataTypeInfo<T, 11>::value;
452template <typename T> constexpr typename tDataTypeInfo<T, 13>::tTable tDataTypeInfo<T, 13>::value;
453template <typename T> constexpr typename tDataTypeInfo<T, 15>::tTable tDataTypeInfo<T, 15>::value;
454template <typename T> constexpr typename tDataTypeInfo<T, 16>::tTable tDataTypeInfo<T, 16>::value;
455template <typename T> constexpr typename tDataTypeInfo<T, 32>::tTable tDataTypeInfo<T, 32>::value;
456template <typename T> constexpr typename tDataTypeInfo<T, 33>::tTable tDataTypeInfo<T, 33>::value;
457template <typename T> constexpr typename tDataTypeInfo<T, 34>::tTable tDataTypeInfo<T, 34>::value;
458template <typename T> constexpr typename tDataTypeInfo<T, 35>::tTable tDataTypeInfo<T, 35>::value;
459
460template <typename T, unsigned int Tflags> tTypeInfo::tSharedInfo tDataTypeInfo<T, Tflags>::shared_info(&tDataTypeInfo<T>::value.data_type_info, TypeName<T>::value);
461template <typename T> tTypeInfo::tSharedInfo tDataTypeInfo<T, 0>::shared_info(&tDataTypeInfo<T>::value.data_type_info, TypeName<T>::value, AutoRegisterVectorType<T>::value ? &tDataTypeInfo<typename std::conditional<AutoRegisterVectorType<T>::value, std::vector<T>, void>::type>::value.data_type_info : &tTypeInfo::cNULL_TYPE_INFO, AutoRegister<T>::Register());
462template <typename T> tTypeInfo::tSharedInfo tDataTypeInfo<T, 1>::shared_info(&tDataTypeInfo<T>::value.data_type_info, TypeName<T>::value, AutoRegisterVectorType<T>::value ? &tDataTypeInfo<typename std::conditional<AutoRegisterVectorType<T>::value, std::vector<T>, void>::type>::value.data_type_info : &tTypeInfo::cNULL_TYPE_INFO, AutoRegister<T>::Register());
463template <typename T> tTypeInfo::tSharedInfo tDataTypeInfo<T, 2>::shared_info(&tDataTypeInfo<T>::value.data_type_info, TypeName<T>::value, AutoRegisterVectorType<T>::value ? &tDataTypeInfo<typename std::conditional<AutoRegisterVectorType<T>::value, std::vector<T>, void>::type>::value.data_type_info : &tTypeInfo::cNULL_TYPE_INFO, AutoRegister<T>::Register());
464template <typename T> tTypeInfo::tSharedInfo tDataTypeInfo<T, 3>::shared_info(&tDataTypeInfo<T>::value.data_type_info, TypeName<T>::value, AutoRegisterVectorType<T>::value ? &tDataTypeInfo<typename std::conditional<AutoRegisterVectorType<T>::value, std::vector<T>, void>::type>::value.data_type_info : &tTypeInfo::cNULL_TYPE_INFO, AutoRegister<T>::Register());
465template <typename T> tTypeInfo::tSharedInfo tDataTypeInfo<T, 4>::shared_info(&tDataTypeInfo<T>::value.data_type_info, TypeName<T>::value, AutoRegisterVectorType<T>::value ? &tDataTypeInfo<typename std::conditional<AutoRegisterVectorType<T>::value, std::vector<T>, void>::type>::value.data_type_info : &tTypeInfo::cNULL_TYPE_INFO, AutoRegister<T>::Register());
466template <typename T> tTypeInfo::tSharedInfo tDataTypeInfo<T, 5>::shared_info(&tDataTypeInfo<T>::value.data_type_info, TypeName<T>::value, AutoRegisterVectorType<T>::value ? &tDataTypeInfo<typename std::conditional<AutoRegisterVectorType<T>::value, std::vector<T>, void>::type>::value.data_type_info : &tTypeInfo::cNULL_TYPE_INFO, AutoRegister<T>::Register());
467template <typename T> tTypeInfo::tSharedInfo tDataTypeInfo<T, 6>::shared_info(&tDataTypeInfo<T>::value.data_type_info, TypeName<T>::value, AutoRegisterVectorType<T>::value ? &tDataTypeInfo<typename std::conditional<AutoRegisterVectorType<T>::value, std::vector<T>, void>::type>::value.data_type_info : &tTypeInfo::cNULL_TYPE_INFO, AutoRegister<T>::Register());
468template <typename T> tTypeInfo::tSharedInfo tDataTypeInfo<T, 7>::shared_info(&tDataTypeInfo<T>::value.data_type_info, TypeName<T>::value, AutoRegisterVectorType<T>::value ? &tDataTypeInfo<typename std::conditional<AutoRegisterVectorType<T>::value, std::vector<T>, void>::type>::value.data_type_info : &tTypeInfo::cNULL_TYPE_INFO, AutoRegister<T>::Register());
469template <typename T> tTypeInfo::tSharedInfo tDataTypeInfo<T, 9>::shared_info(&tDataTypeInfo<T>::value.data_type_info, TypeName<T>::value, &tTypeInfo::cNULL_TYPE_INFO, AutoRegister<T>::Register());
470template <typename T> tTypeInfo::tSharedInfo tDataTypeInfo<T, 11>::shared_info(&tDataTypeInfo<T>::value.data_type_info, TypeName<T>::value, &tTypeInfo::cNULL_TYPE_INFO, AutoRegister<T>::Register());
471template <typename T> tTypeInfo::tSharedInfo tDataTypeInfo<T, 13>::shared_info(&tDataTypeInfo<T>::value.data_type_info, TypeName<T>::value, &tTypeInfo::cNULL_TYPE_INFO, AutoRegister<T>::Register());
472template <typename T> tTypeInfo::tSharedInfo tDataTypeInfo<T, 15>::shared_info(&tDataTypeInfo<T>::value.data_type_info, TypeName<T>::value, &tTypeInfo::cNULL_TYPE_INFO, AutoRegister<T>::Register());
473
474template <typename T>
475tTypeInfo::tSharedInfoEnum tDataTypeInfo<T, eTLF_ENUM>::shared_info(&tDataTypeInfo<T>::value.data_type_info,
476    TypeName<T>::value,
477    make_builder::internal::GetEnumStrings<T>(),
478    &tDataTypeInfo<typename std::conditional<AutoRegisterVectorType<T>::value, std::vector<T>, void>::type>::value.data_type_info,
479    AutoRegister<T>::Register());
480
481namespace
482{
483
484template <typename T>
485struct tTupleInfo
486{
487  static_assert(std::is_same<T, void>::value, "This should not be instantiated");
488};
489template <typename T1, typename T2>
490struct tTupleInfo<std::pair<T1, T2>>
491{
492  enum { cTUPLE_SIZE = 2 };
493  static const std::array<tTypeInfo::tTupleElementInfo, 2> cTUPLE_INFO;
494
495  static std::array<tTypeInfo::tTupleElementInfo, 2> Get(const std::pair<T1, T2>* pair)
496  {
497    return { tTypeInfo::tTupleElementInfo(&tDataTypeInfo<typename NormalizedType<T1>::type>::value.data_type_info, reinterpret_cast<const char*>(&pair->first) - reinterpret_cast<const char*>(pair)),
498             tTypeInfo::tTupleElementInfo(&tDataTypeInfo<typename NormalizedType<T2>::type>::value.data_type_info, reinterpret_cast<const char*>(&pair->second) - reinterpret_cast<const char*>(pair))
499           };
500  }
501};
502
503template <typename ... TArgs>
504struct tTupleInfo<std::tuple<TArgs...>>
505{
506  enum { cTUPLE_SIZE = std::tuple_size<std::tuple<TArgs...>>::value };
507  static const std::array<tTypeInfo::tTupleElementInfo, cTUPLE_SIZE> cTUPLE_INFO;
508  typedef std::tuple<TArgs...> tTuple;
509
510  template <int ... SEQUENCE>
511  static std::array<tTypeInfo::tTupleElementInfo, cTUPLE_SIZE> Get(const tTuple* tuple, rrlib::util::tIntegerSequence<SEQUENCE...> sequence)
512  {
513    std::array<tTypeInfo::tTupleElementInfo, cTUPLE_SIZE> result = { tTypeInfo::tTupleElementInfo(&tDataTypeInfo<typename NormalizedType<typename std::tuple_element<SEQUENCE, tTuple>::type>::type>::value.data_type_info, reinterpret_cast<const char*>(&std::get<SEQUENCE>(*tuple)) - reinterpret_cast<const char*>(tuple)) ... };
514    return result;
515  }
516};
517
518template <typename T1, typename T2> const std::array<tTypeInfo::tTupleElementInfo, 2> tTupleInfo<std::pair<T1, T2>>::cTUPLE_INFO = tTupleInfo<std::pair<T1, T2>>::Get(static_cast<std::pair<T1, T2>*>(nullptr));
519template <typename ... TArgs> const std::array<tTypeInfo::tTupleElementInfo, tTupleInfo<std::tuple<TArgs...>>::cTUPLE_SIZE> tTupleInfo<std::tuple<TArgs...>>::cTUPLE_INFO = tTupleInfo<std::tuple<TArgs...>>::Get(static_cast<std::tuple<TArgs...>*>(nullptr), typename rrlib::util::tIntegerSequenceGenerator<tTupleInfo<std::tuple<TArgs...>>::cTUPLE_SIZE>::type());
520
521}
522
523template <typename T> tTypeInfo::tSharedInfoTuple tDataTypeInfo<T, 32>::shared_info(&tDataTypeInfo<T, 32>::value.data_type_info, tTupleInfo<T>::cTUPLE_SIZE, tTupleInfo<T>::cTUPLE_INFO.data(), AutoRegisterVectorType<T>::value ? &tDataTypeInfo<typename std::conditional<AutoRegisterVectorType<T>::value, std::vector<T>, void>::type>::value.data_type_info : &tTypeInfo::cNULL_TYPE_INFO, AutoRegister<T>::Register());
524template <typename T> tTypeInfo::tSharedInfoTuple tDataTypeInfo<T, 33>::shared_info(&tDataTypeInfo<T, 33>::value.data_type_info, tTupleInfo<T>::cTUPLE_SIZE, tTupleInfo<T>::cTUPLE_INFO.data(), AutoRegisterVectorType<T>::value ? &tDataTypeInfo<typename std::conditional<AutoRegisterVectorType<T>::value, std::vector<T>, void>::type>::value.data_type_info : &tTypeInfo::cNULL_TYPE_INFO, AutoRegister<T>::Register());
525template <typename T> tTypeInfo::tSharedInfoTuple tDataTypeInfo<T, 34>::shared_info(&tDataTypeInfo<T, 34>::value.data_type_info, tTupleInfo<T>::cTUPLE_SIZE, tTupleInfo<T>::cTUPLE_INFO.data(), AutoRegisterVectorType<T>::value ? &tDataTypeInfo<typename std::conditional<AutoRegisterVectorType<T>::value, std::vector<T>, void>::type>::value.data_type_info : &tTypeInfo::cNULL_TYPE_INFO, AutoRegister<T>::Register());
526template <typename T> tTypeInfo::tSharedInfoTuple tDataTypeInfo<T, 35>::shared_info(&tDataTypeInfo<T, 35>::value.data_type_info, tTupleInfo<T>::cTUPLE_SIZE, tTupleInfo<T>::cTUPLE_INFO.data(), AutoRegisterVectorType<T>::value ? &tDataTypeInfo<typename std::conditional<AutoRegisterVectorType<T>::value, std::vector<T>, void>::type>::value.data_type_info : &tTypeInfo::cNULL_TYPE_INFO, AutoRegister<T>::Register());
527
528template <typename T>
529struct ConstructorFunction<T, false, false, true>
530{
531  static void Construct(void* placement)
532  {
533    const make_builder::internal::tEnumStrings& enum_strings = tDataTypeInfo<T>::shared_info.enum_strings;
534    if (enum_strings.non_standard_values)
535    {
536      memcpy(placement, enum_strings.non_standard_values, sizeof(T));
537    }
538    else
539    {
540      memset(placement, 0, sizeof(T));
541    }
542  }
543
544  static constexpr operations::tConstructor value = &Construct;
545};
546
547//----------------------------------------------------------------------
548// End of namespace declaration
549//----------------------------------------------------------------------
550}
551}
552}
553
554#endif
Note: See TracBrowser for help on using the repository browser.