source: rrlib_rtti/detail/tGenericObjectBaseImpl.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: 5.1 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/tGenericObjectBaseImpl.h
23 *
24 * \author  Max Reichardt
25 *
26 * \date    2012-02-05
27 *
28 * \brief   Contains tGenericObjectBaseImpl
29 *
30 * \b tGenericObjectBaseImpl
31 *
32 * This class implements all type-specific generic operations of
33 * tGenericObject.
34 */
35//----------------------------------------------------------------------
36#ifndef __rrlib__rtti__detail__tGenericObjectBaseImpl_h__
37#define __rrlib__rtti__detail__tGenericObjectBaseImpl_h__
38
39//----------------------------------------------------------------------
40// External includes (system with <>, local with "")
41//----------------------------------------------------------------------
42#include "rrlib/serialization/tStringInputStream.h"
43#include "rrlib/serialization/tStringOutputStream.h"
44#include "rrlib/serialization/type_traits.h"
45
46//----------------------------------------------------------------------
47// Internal includes with ""
48//----------------------------------------------------------------------
49#include "rrlib/rtti/tGenericObject.h"
50
51//----------------------------------------------------------------------
52// Namespace declaration
53//----------------------------------------------------------------------
54namespace rrlib
55{
56namespace rtti
57{
58namespace detail
59{
60
61//----------------------------------------------------------------------
62// Forward declarations / typedefs / enums
63//----------------------------------------------------------------------
64
65//----------------------------------------------------------------------
66// Class declaration
67//----------------------------------------------------------------------
68//! Generic object implementation
69/*!
70 * This class implements all type-specific generic operations of
71 * tGenericObject.
72 */
73template<typename T>
74class tGenericObjectBaseImpl : public tGenericObject
75{
76  static_assert(IsNormalizedType<T>::value, "Only normalized types should be used in generic objects");
77
78//----------------------------------------------------------------------
79// Public methods and typedefs
80//----------------------------------------------------------------------
81public:
82
83  virtual void Clear() override
84  {
85    //TODO
86  }
87
88  /*!
89   * Deep copy source object to this object
90   *
91   * \param source Source object
92   */
93  inline void DeepCopyFromImpl(const T& source, tFactory* f = NULL)
94  {
95    GenericOperations<T>::DeepCopy(source, this->GetData<T>());
96  }
97
98  virtual void Deserialize(serialization::tInputStream& is) override
99  {
100    serialization::Deserialize(is, tGenericObject::GetData<T>());
101  }
102
103  virtual void Deserialize(serialization::tStringInputStream& is) override
104  {
105    serialization::Deserialize(is, tGenericObject::GetData<T>());
106  }
107
108#ifdef _LIB_RRLIB_XML_PRESENT_
109  virtual void Deserialize(const xml::tNode& node) override
110  {
111    serialization::Deserialize(node, tGenericObject::GetData<T>());
112  }
113#endif
114
115  virtual bool Equals(const tGenericObject& other) override
116  {
117    return wrapped == other.GetRawDataPointer() || (GetType() == other.GetType() && GenericOperations<T>::Equals(this->GetData<T>(), other.GetData<T>()));
118  }
119
120  virtual void Serialize(serialization::tOutputStream& os) const override
121  {
122    serialization::Serialize(os, tGenericObject::GetData<T>());
123  }
124
125  virtual void Serialize(serialization::tStringOutputStream& os) const override
126  {
127    serialization::Serialize(os, tGenericObject::GetData<T>());
128  }
129
130#ifdef _LIB_RRLIB_XML_PRESENT_
131  virtual void Serialize(xml::tNode& node) const override
132  {
133    serialization::Serialize(node, tGenericObject::GetData<T>());
134  }
135#endif
136
137//----------------------------------------------------------------------
138// Protected constructor and methods
139//----------------------------------------------------------------------
140protected:
141
142  tGenericObjectBaseImpl() :
143    tGenericObject(tDataType<T>())
144  {}
145
146//----------------------------------------------------------------------
147// Private fields and methods
148//----------------------------------------------------------------------
149private:
150
151  virtual void DeepCopyFrom(const void* source, tFactory* f) override
152  {
153    DeepCopyFromImpl(*static_cast<const T*>(source), f);
154  }
155
156};
157
158//----------------------------------------------------------------------
159// End of namespace declaration
160//----------------------------------------------------------------------
161}
162}
163}
164
165#endif
Note: See TracBrowser for help on using the repository browser.