source: rrlib_rtti/tGenericObjectInstance.h @ 72:90eb68fa9531

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

Implements transparent unified handling of equivalent integral types (e.g. tDataType<size_t> == tDataType<unsigned int> on 32 bit platforms). Furthermore, integral types have unambiguous rrlib_rtti type names such as "int16" or "uint64". This avoids issues with serialization on different platforms. Note that tType::GetRttiName() now returns typeid of 'normalized' type.

File size: 4.3 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/tGenericObjectInstance.h
23 *
24 * \author  Max Reichardt
25 *
26 * \date    2012-02-05
27 *
28 * \brief   Contains tGenericObjectInstance
29 *
30 * \b tGenericObjectInstance
31 *
32 * A generic object that allocates and owns its wrapped data
33 *
34 */
35//----------------------------------------------------------------------
36#ifndef __rrlib__rtti__tGenericObjectInstance_h__
37#define __rrlib__rtti__tGenericObjectInstance_h__
38
39//----------------------------------------------------------------------
40// External includes (system with <>, local with "")
41//----------------------------------------------------------------------
42
43//----------------------------------------------------------------------
44// Internal includes with ""
45//----------------------------------------------------------------------
46#include "rrlib/rtti/detail/tGenericObjectBaseImpl.h"
47
48//----------------------------------------------------------------------
49// Namespace declaration
50//----------------------------------------------------------------------
51namespace rrlib
52{
53namespace rtti
54{
55
56//----------------------------------------------------------------------
57// Forward declarations / typedefs / enums
58//----------------------------------------------------------------------
59
60//----------------------------------------------------------------------
61// Class declaration
62//----------------------------------------------------------------------
63//! Generic object owning buffer
64/*!
65 * A generic object that allocates and owns its wrapped data
66 */
67template<typename T, bool NO_ARG_CONSTRUCTOR = std::is_base_of<serialization::DefaultImplementation, serialization::DefaultInstantiation<T>>::value>
68class tGenericObjectInstance : public detail::tGenericObjectBaseImpl<typename NormalizedType<T>::type>
69{
70  typedef typename NormalizedType<T>::type tBuffer;
71
72//----------------------------------------------------------------------
73// Public methods and typedefs
74//----------------------------------------------------------------------
75public:
76
77  tGenericObjectInstance() :
78    detail::tGenericObjectBaseImpl<tBuffer>(),
79    wrapped_object(serialization::DefaultInstantiation<tBuffer>::Create())
80  {
81    tGenericObject::wrapped = &wrapped_object;
82  }
83
84//----------------------------------------------------------------------
85// Private fields and methods
86//----------------------------------------------------------------------
87private:
88
89  /*! Wrapped object */
90  tBuffer wrapped_object;
91};
92
93
94// Specialization for when default constructor is available
95template<typename T>
96class tGenericObjectInstance<T, true> : public detail::tGenericObjectBaseImpl<typename NormalizedType<T>::type>
97{
98  typedef typename NormalizedType<T>::type tBuffer;
99
100//----------------------------------------------------------------------
101// Public methods and typedefs
102//----------------------------------------------------------------------
103public:
104
105  tGenericObjectInstance() :
106    detail::tGenericObjectBaseImpl<tBuffer>(),
107    wrapped_object()
108  {
109    tGenericObject::wrapped = &wrapped_object;
110  }
111
112//----------------------------------------------------------------------
113// Private fields and methods
114//----------------------------------------------------------------------
115private:
116
117  /*! Wrapped object */
118  tBuffer wrapped_object;
119};
120
121//----------------------------------------------------------------------
122// End of namespace declaration
123//----------------------------------------------------------------------
124}
125}
126
127
128#endif
Note: See TracBrowser for help on using the repository browser.