source: rrlib_rtti/detail/type_traits.h @ 90:4e0cc8c4a4e2

17.03
Last change on this file since 90:4e0cc8c4a4e2 was 90:4e0cc8c4a4e2, checked in by Max Reichardt <mreichardt@…>, 4 years ago

rrlib_rtti version 3.0.

Rewrite and refactoring of major parts of the implementation:

  • No longer contains any virtual methods - relies on compile-time generated function tables instead.
  • Improvements to efficiency (memory efficiency in particular). Size of librrlib_rtti.so is reduced by more than 60% in release mode.
  • Added generic operations for std::vector types
  • Added more type traits - including one for every generic operation; moved some functionality to those
  • Removed obsolete, platform-specific binary detection feature
  • Removed base class for type annotations. They are now copied by-value.
  • Various additional new features
File size: 3.6 KB
Line 
1//
2// You received this file as part of RRLib
3// Robotics Research Library
4//
5// Copyright (C) AG Robotersysteme TU Kaiserslautern
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/type_traits.h
23 *
24 * \author  Max Reichardt
25 *
26 * \date    2015-05-22
27 *
28 * Contains type trait implementation helper classes and structs
29 *
30 */
31//----------------------------------------------------------------------
32#ifndef __rrlib__rtti__detail__type_traits_h__
33#define __rrlib__rtti__detail__type_traits_h__
34
35//----------------------------------------------------------------------
36// External includes (system with <>, local with "")
37//----------------------------------------------------------------------
38
39//----------------------------------------------------------------------
40// Internal includes with ""
41//----------------------------------------------------------------------
42#include "rrlib/util/tManagedConstCharPointer.h"
43
44//----------------------------------------------------------------------
45// Namespace declaration
46//----------------------------------------------------------------------
47namespace rrlib
48{
49namespace rtti
50{
51namespace detail
52{
53
54//----------------------------------------------------------------------
55// Forward declarations / typedefs / enums
56//----------------------------------------------------------------------
57
58//----------------------------------------------------------------------
59// Function declarations
60//----------------------------------------------------------------------
61
62/*!
63 * Provides normalized integer types for specified size and signedness
64 */
65template <size_t SIZE, bool UNSIGNED>
66struct NormalizedIntegerType
67{
68  typedef void type;
69};
70
71template<>
72struct NormalizedIntegerType<1, false>
73{
74  typedef int8_t type;
75};
76
77template<>
78struct NormalizedIntegerType<1, true>
79{
80  typedef uint8_t type;
81};
82
83template<>
84struct NormalizedIntegerType<2, false>
85{
86  typedef int16_t type;
87};
88
89template<>
90struct NormalizedIntegerType<2, true>
91{
92  typedef uint16_t type;
93};
94
95template<>
96struct NormalizedIntegerType<4, false>
97{
98  typedef int type;
99};
100
101template<>
102struct NormalizedIntegerType<4, true>
103{
104  typedef unsigned int type;
105};
106
107template<>
108struct NormalizedIntegerType<8, false>
109{
110  typedef long long type;
111};
112
113template<>
114struct NormalizedIntegerType<8, true>
115{
116  typedef unsigned long long type;
117};
118
119/*!
120 * Type trait to determine whether T has a CopyFrom member function
121 */
122template <typename T>
123struct HasCopyFromMethod
124{
125  template <typename U>
126  static U &Make();
127
128  template <typename U = T>
129  static int16_t Test(decltype(Make<U>().CopyFrom(Make<const U>()))*);
130
131  static int32_t Test(...);
132
133  enum { value = sizeof(Test(static_cast<void*>(nullptr))) == sizeof(int16_t) }; // g++ 4.8 requires this cast somehow
134};
135
136//----------------------------------------------------------------------
137// End of namespace declaration
138//----------------------------------------------------------------------
139}
140}
141}
142
143
144#endif
Note: See TracBrowser for help on using the repository browser.