MRPT  1.9.9
CArchive.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/config.h> // MRPT_IS_BIG_ENDIAN
12 #include <mrpt/core/Clock.h>
17 #include <cstdint>
18 #include <stdexcept>
19 #include <string>
20 #include <type_traits> // remove_reference_t, is_polymorphic
21 #include <variant>
22 #include <vector>
23 
24 // See: https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=258854
25 #if defined(__clang__) && (__GLIBCXX__ <= 20180419)
26 #define HAS_BROKEN_CLANG_STD_VISIT
27 #endif
28 
29 namespace mrpt::serialization
30 {
31 class CMessage;
32 
33 /** Used in mrpt::serialization::CArchive */
34 class CExceptionEOF : public std::runtime_error
35 {
36  public:
37  CExceptionEOF(const std::string& s) : std::runtime_error(s) {}
38 };
39 
40 /** Virtual base class for "archives": classes abstracting I/O streams.
41  * This class separates the implementation details of serialization (in
42  * CSerializable) and data storage (CArchive children: files, sockets,...).
43  *
44  * Two main sets of implementations are provided:
45  * - archiveFrom: for MRPT mrpt::io::CArchive objects, and
46  * - CArchiveStdIStream and CArchiveStdOStream: for std::istream and
47  * std::ostream, respectively.
48  *
49  * \sa mrpt::io::CArchive, mrpt::serialization::CSerializable
50  * \ingroup mrpt_serialization_grp
51  */
52 class CArchive
53 {
54  public:
55  CArchive() = default;
56  virtual ~CArchive() = default;
57  /** @name Serialization API for generic "archives" I/O streams
58  * @{ */
59  /** Reads a block of bytes from the stream into Buffer
60  * \exception std::exception On any error, or if ZERO bytes are read.
61  * \return The amound of bytes actually read.
62  * \note This method is endianness-dependent.
63  * \sa ReadBufferImmediate ; Important, see: ReadBufferFixEndianness,
64  */
65  size_t ReadBuffer(void* Buffer, size_t Count);
66 
67  /** Reads a sequence of elemental datatypes, taking care of reordering their
68  *bytes from the MRPT stream standard (little endianness) to the format of
69  *the running architecture.
70  * \param ElementCount The number of elements (not bytes) to read.
71  * \param ptr A pointer to the first output element in an array (or
72  *std::vector<>, etc...).
73  * \return The amound of *bytes* (not elements) actually read (under error
74  *situations, the last element may be invalid if the data stream abruptly
75  *ends).
76  * Example of usage:
77  * \code
78  * uint32_t N;
79  * s >> N;
80  * vector<float> vec(N);
81  * if (N)
82  * s.ReadBufferFixEndianness<float>(&vec[0],N);
83  * \endcode
84  * \exception std::exception On any error, or if ZERO bytes are read.
85  * \sa ReadBufferFixEndianness, ReadBuffer
86  */
87  template <typename T>
88  size_t ReadBufferFixEndianness(T* ptr, size_t ElementCount)
89  {
90 #if !MRPT_IS_BIG_ENDIAN
91  // little endian: no conversion needed.
92  return ReadBuffer(ptr, ElementCount * sizeof(T));
93 #else
94  // big endian: convert.
95  const size_t nread = ReadBuffer(ptr, ElementCount * sizeof(T));
96  for (size_t i = 0; i < ElementCount; i++)
98  return nread;
99 #endif
100  }
101 
102  /** Writes a block of bytes to the stream from Buffer.
103  * \exception std::exception On any error
104  * \sa Important, see: WriteBufferFixEndianness
105  * \note This method is endianness-dependent.
106  */
107  void WriteBuffer(const void* Buffer, size_t Count);
108 
109  /** Writes a sequence of elemental datatypes, taking care of reordering
110  * their bytes from the running architecture to MRPT stream standard (little
111  * endianness).
112  * \param ElementCount The number of elements (not bytes) to write.
113  * \param ptr A pointer to the first input element in an array (or
114  * std::vector<>, etc...).
115  * Example of usage:
116  * \code
117  * vector<float> vec = ...
118  * uint32_t N = vec.size();
119  * s << N
120  * if (N)
121  * s.WriteBufferFixEndianness<float>(&vec[0],N);
122  * \endcode
123  * \exception std::exception On any error
124  * \sa WriteBuffer
125  */
126  template <typename T>
127  void WriteBufferFixEndianness(const T* ptr, size_t ElementCount)
128  {
129 #if !MRPT_IS_BIG_ENDIAN
130  // little endian: no conversion needed.
131  return WriteBuffer(ptr, ElementCount * sizeof(T));
132 #else
133  // big endian: the individual "<<" functions already convert endiannes
134  for (size_t i = 0; i < ElementCount; i++) (*this) << ptr[i];
135 #endif
136  }
137  /** Read a value from a stream stored in a type different of the target
138  * variable, making the conversion via static_cast. Useful for coding
139  * backwards compatible de-serialization blocks */
140  template <typename STORED_TYPE, typename CAST_TO_TYPE>
141  void ReadAsAndCastTo(CAST_TO_TYPE& read_here)
142  {
143  STORED_TYPE var;
144  (*this) >> var;
145  read_here = static_cast<CAST_TO_TYPE>(var);
146  }
147  /** De-serialize a variable and returns it by value. */
148  template <typename STORED_TYPE>
149  STORED_TYPE ReadAs()
150  {
151  STORED_TYPE var;
152  (*this) >> var;
153  return var;
154  }
155  template <typename TYPE_TO_STORE, typename TYPE_FROM_ACTUAL>
156  void WriteAs(const TYPE_FROM_ACTUAL& value)
157  {
158  (*this) << static_cast<TYPE_TO_STORE>(value);
159  }
160  /** Writes an object to the stream.
161  */
162  void WriteObject(const CSerializable* o);
163  void WriteObject(const CSerializable& o) { WriteObject(&o); }
164  /** Reads an object from stream, its class determined at runtime, and
165  * returns a smart pointer to the object.
166  * \exception std::exception On I/O error or undefined class.
167  * \exception CExceptionEOF On an End-Of-File condition found
168  * at a correct place: an EOF that abruptly finishes in the middle of one
169  * object raises a plain std::exception instead.
170  */
171  CSerializable::Ptr ReadObject() { return ReadObject<CSerializable>(); }
172  /** Reads an object from stream, its class determined at runtime, and
173  * returns a smart pointer to the object. This version is similar to
174  * mrpt::make_aligned_shared<T>.
175  * \exception std::exception On I/O error or undefined class.
176  * \exception CExceptionEOF On an End-Of-File condition found
177  * at a correct place: an EOF that abruptly finishes in the middle of one
178  * object raises a plain std::exception instead.
179  */
180  template <typename T>
181  typename T::Ptr ReadObject()
182  {
184  std::string strClassName;
185  bool isOldFormat{false};
186  int8_t version{-1};
187  internal_ReadObjectHeader(strClassName, isOldFormat, version);
188  if (strClassName != "nullptr")
189  {
190  const mrpt::rtti::TRuntimeClassId* classId =
191  mrpt::rtti::findRegisteredClass(strClassName);
192  if (!classId)
194  "Stored object has class '%s' which is not registered!",
195  strClassName.c_str());
196  obj.reset(dynamic_cast<CSerializable*>(classId->createObject()));
197  }
199  obj.get() /* may be nullptr */, strClassName, isOldFormat,
200  version); // must be called to read the END FLAG byte
201  if (!obj)
202  {
203  return typename T::Ptr();
204  }
205  else
206  {
207  return std::dynamic_pointer_cast<T>(obj);
208  }
209  }
210 
211  private:
212  template <typename RET>
214  {
215  throw std::runtime_error("Can't match variant type");
216  return RET();
217  }
218 
219  template <typename RET, typename T, typename... R>
221  CSerializable::Ptr& ptr,
222  std::enable_if_t<mrpt::is_shared_ptr<T>::value>* = nullptr)
223  {
224  if (IS_CLASS(ptr, typename T::element_type))
225  return std::dynamic_pointer_cast<typename T::element_type>(ptr);
226  return ReadVariant_helper<RET, R...>(ptr);
227  }
228 
229  template <typename RET, typename T, typename... R>
231  CSerializable::Ptr& ptr,
232  std::enable_if_t<!mrpt::is_shared_ptr<T>::value>* = nullptr)
233  {
234  if (IS_CLASS(ptr, T)) return dynamic_cast<T&>(*ptr);
235  return ReadVariant_helper<RET, R...>(ptr);
236  }
237 
238  public:
239  /** Reads a variant from stream, its class determined at runtime, and
240  * returns a variant to the object.
241  * To be compatible with the current polymorphic system this support smart
242  * pointer types.
243  * For pointer types, This will bind to the first possible pointer type.
244  * variant<CSerializable::Ptr, CRenderizable::Ptr>
245  * \exception std::exception On I/O error or undefined class.
246  * \exception CExceptionEOF On an End-Of-File condition found
247  * at a correct place: an EOF that abruptly finishes in the middle of one
248  * object raises a plain std::exception instead.
249  */
250  template <typename... T>
251  typename std::variant<T...> ReadVariant()
252  {
254  std::string strClassName;
255  bool isOldFormat;
256  int8_t version;
257  internal_ReadObjectHeader(strClassName, isOldFormat, version);
258  const mrpt::rtti::TRuntimeClassId* classId =
259  mrpt::rtti::findRegisteredClass(strClassName);
260  if (!classId)
262  "Stored object has class '%s' which is not registered!",
263  strClassName.c_str());
264  if (strClassName != "nullptr")
265  {
266  obj.reset(dynamic_cast<CSerializable*>(classId->createObject()));
267  }
268  internal_ReadObject(obj.get(), strClassName, isOldFormat, version);
269  if (!obj)
270  {
271  return std::variant<T...>();
272  }
273  else
274  {
275  return ReadVariant_helper<std::variant<T...>, T...>(obj);
276  }
277  }
278 
279 #ifndef HAS_BROKEN_CLANG_STD_VISIT
280  /** Writes a Variant to the stream.
281  */
282  template <typename T>
283  void WriteVariant(T t)
284  {
285  std::visit([&](auto& o) { this->WriteObject(o); }, t);
286  }
287 #endif
288 
289  /** Reads a simple POD type and returns by value. Useful when `stream >>
290  * var;`
291  * cannot be used becuase of errors of misaligned reference binding.
292  * Use with macro `MRPT_READ_POD` to avoid typing the type T yourself.
293  * \note [New in MRPT 2.0.0]
294  * \note Write operator `s << var;` is safe for misaligned variables.
295  */
296  template <typename T>
298  {
299  T ret;
300  ReadBufferFixEndianness(&ret, 1);
301  return ret;
302  }
303 
304  /** Reads an object from stream, where its class must be the same
305  * as the supplied object, where the loaded object will be stored in.
306  * \exception std::exception On I/O error or different class found.
307  * \exception CExceptionEOF On an End-Of-File condition found
308  * at a correct place: an EOF that abruptly finishes in the middle of one
309  * object raises a plain std::exception instead.
310  */
311  void ReadObject(CSerializable* existingObj);
312 
313  /** Send a message to the device.
314  * Note that only the low byte from the "type" field will be used.
315  *
316  * For frames of size < 255 the frame format is an array of bytes in this
317  * order:
318  * \code
319  * <START_FLAG> <HEADER> <LENGTH> <BODY> <END_FLAG>
320  * <START_FLAG> = 0x69
321  * <HEADER> = A header byte
322  * <LENGHT> = Number of bytes of BODY
323  * <BODY> = N x bytes
324  * <END_FLAG> = 0X96
325  * Total length = <LENGTH> + 4
326  * \endcode
327  *
328  * For frames of size > 255 the frame format is an array of bytes in this
329  * order:
330  * \code
331  * <START_FLAG> <HEADER> <HIBYTE(LENGTH)> <LOBYTE(LENGTH)> <BODY>
332  * <END_FLAG>
333  * <START_FLAG> = 0x79
334  * <HEADER> = A header byte
335  * <LENGHT> = Number of bytes of BODY
336  * <BODY> = N x bytes
337  * <END_FLAG> = 0X96
338  * Total length = <LENGTH> + 5
339  * \endcode
340  *
341  * \exception std::exception On communication errors
342  */
343  void sendMessage(const CMessage& msg);
344 
345  /** Tries to receive a message from the device.
346  * \exception std::exception On communication errors
347  * \returns True if successful, false if there is no new data from the
348  * device (but communications seem to work fine)
349  * \sa The frame format is described in sendMessage()
350  */
351  bool receiveMessage(CMessage& msg);
352 
353  /** Write a CSerializable object to a stream in the binary MRPT format */
355  /** \overload */
356  CArchive& operator<<(const CSerializable::Ptr& pObj);
357  /** Reads a CSerializable object from the stream */
359  /** \overload */
361 
362  /** @} */
363 
364  protected:
365  /** @name Virtual methods of the CArchive interface
366  * @{ */
367  /** Writes a block of bytes.
368  * \exception std::exception On any error
369  * \return Number of bytes actually written.
370  */
371  virtual size_t write(const void* buf, size_t len) = 0;
372  /** Reads a block of bytes.
373  * \exception std::exception On any error, or if ZERO bytes are read.
374  * \return Number of bytes actually read if >0.
375  */
376  virtual size_t read(void* buf, size_t len) = 0;
377  /** @} */
378 
379  /** Read the object */
380  void internal_ReadObject(
381  CSerializable* newObj, const std::string& className, bool isOldFormat,
382  int8_t version);
383 
384  /** Read the object Header*/
386  std::string& className, bool& isOldFormat, int8_t& version);
387 };
388 
389 // Note: write op accepts parameters by value on purpose, to avoid misaligned
390 // reference binding errors.
391 template <class T, class... Ts>
392 using is_any = std::disjunction<std::is_same<T, Ts>...>;
393 
394 template <typename T>
395 using is_simple_type = is_any<
397  int64_t, float, double, long double>;
398 
399 #if MRPT_IS_BIG_ENDIAN
400 // Big endian system: Convert into little-endian for streaming
403 {
405  out.WriteBuffer((void*)&a, sizeof(a));
406  return out;
407 }
408 
410 CArchive& mrpt::serialization::operator>>(CArchive& in, T& a)
411 {
412  T b;
413  in.ReadBuffer((void*)&b, sizeof(a));
415  ::memcpy(&a, &b, sizeof(b));
416  return in;
417 }
418 
419 #else
420 // Little endian system:
422 CArchive& operator<<(CArchive& out, const T& a)
423 {
424  out.WriteBuffer((void*)&a, sizeof(a));
425  return out;
426 }
427 
430 {
431  in.ReadBuffer((void*)&a, sizeof(a));
432  return in;
433 }
434 #endif
435 
436 CArchive& operator<<(CArchive& out, const mrpt::Clock::time_point& a);
437 CArchive& operator>>(CArchive& in, mrpt::Clock::time_point& a);
438 
439 #define MRPT_READ_POD(_STREAM, _VARIABLE) \
440  do \
441  { \
442  const std::remove_cv_t<std::remove_reference_t<decltype(_VARIABLE)>> \
443  val = _STREAM.ReadPOD<std::remove_cv_t< \
444  std::remove_reference_t<decltype(_VARIABLE)>>>(); \
445  ::memcpy(&_VARIABLE, &val, sizeof(val)); \
446  } while (0)
447 
448 // Why this shouldn't be templatized?: There's a more modern system
449 // in MRPT that serializes any kind of vector<T>, deque<T>, etc... but
450 // to keep COMPATIBILITY with old serialized objects we must preserve
451 // the ones listed here:
452 
453 // Write --------------------
454 CArchive& operator<<(CArchive& s, const std::string& str);
455 
456 CArchive& operator<<(CArchive&, const std::vector<int32_t>& a);
457 CArchive& operator<<(CArchive&, const std::vector<uint32_t>& a);
458 CArchive& operator<<(CArchive&, const std::vector<uint16_t>& a);
459 CArchive& operator<<(CArchive&, const std::vector<int16_t>& a);
460 CArchive& operator<<(CArchive&, const std::vector<uint32_t>& a);
461 CArchive& operator<<(CArchive&, const std::vector<int64_t>& a);
462 CArchive& operator<<(CArchive&, const std::vector<uint8_t>& a);
463 CArchive& operator<<(CArchive&, const std::vector<int8_t>& a);
464 
465 CArchive& operator<<(CArchive&, const std::vector<bool>& a);
466 CArchive& operator<<(CArchive&, const std::vector<std::string>&);
467 
468 #if MRPT_WORD_SIZE != 32 // If it's 32 bit, size_t <=> uint32_t
469 CArchive& operator<<(CArchive&, const std::vector<size_t>& a);
470 #endif
471 
472 // Read --------------------
473 CArchive& operator>>(CArchive& in, std::string& str);
474 
475 CArchive& operator>>(CArchive& in, std::vector<int32_t>& a);
476 CArchive& operator>>(CArchive& in, std::vector<uint32_t>& a);
477 CArchive& operator>>(CArchive& in, std::vector<uint16_t>& a);
478 CArchive& operator>>(CArchive& in, std::vector<int16_t>& a);
479 CArchive& operator>>(CArchive& in, std::vector<int64_t>& a);
480 CArchive& operator>>(CArchive& in, std::vector<uint8_t>& a);
481 CArchive& operator>>(CArchive& in, std::vector<int8_t>& a);
482 CArchive& operator>>(CArchive& in, std::vector<bool>& a);
483 
484 CArchive& operator>>(CArchive& in, std::vector<std::string>& a);
485 
486 // For backward compatibility, since in MRPT<0.8.1 vector_XXX and
487 // std::vector<XXX> were exactly equivalent, now there're not.
488 CArchive& operator>>(CArchive& s, std::vector<float>& a);
489 CArchive& operator>>(CArchive& s, std::vector<double>& a);
490 CArchive& operator<<(CArchive& s, const std::vector<float>& a);
491 CArchive& operator<<(CArchive& s, const std::vector<double>& a);
492 
493 #if MRPT_WORD_SIZE != 32 // If it's 32 bit, size_t <=> uint32_t
494 CArchive& operator>>(CArchive& s, std::vector<size_t>& a);
495 #endif
496 //
497 
498 template <
499  typename T, std::enable_if_t<std::is_base_of_v<
500  mrpt::serialization::CSerializable, T>>* = nullptr>
502 {
503  pObj = in.ReadObject<T>();
504  return in;
505 }
506 
507 template <typename... T>
508 CArchive& operator>>(CArchive& in, typename std::variant<T...>& pObj)
509 {
510  pObj = in.ReadVariant<T...>();
511  return in;
512 }
513 
514 template <typename... T>
515 CArchive& operator<<(CArchive& out, const typename std::variant<T...>& pObj)
516 {
517  pObj.match([&](auto& t) { out << t; });
518  return out;
519 }
520 
521 /** Write a shared_ptr to a non-CSerializable object */
522 template <
523  class T, std::enable_if_t<!std::is_base_of_v<
524  mrpt::serialization::CSerializable, T>>* = nullptr>
525 CArchive& operator<<(CArchive& out, const std::shared_ptr<T>& pObj)
526 {
527  if (pObj)
528  {
529  out << mrpt::typemeta::TTypeName<T>::get();
530  out << *pObj;
531  }
532  else
533  {
534  out << std::string("nullptr");
535  }
536  return out;
537 }
538 
539 /** Read a smart pointer to a non-CSerializable (POD,...) data type*/
540 template <
541  class T, std::enable_if_t<!std::is_base_of_v<
542  mrpt::serialization::CSerializable, T>>* = nullptr>
543 CArchive& operator>>(CArchive& in, std::shared_ptr<T>& pObj)
544 {
545  std::string stored_name;
546  in >> stored_name;
547  const std::string expected_name =
549  if (stored_name == std::string("nullptr"))
550  {
551  pObj.reset();
552  }
553  else
554  {
555  ASSERT_EQUAL_(expected_name, stored_name);
556  pObj.reset(new T);
557  in >> *pObj;
558  }
559  return in;
560 }
561 
562 /** CArchive for mrpt::io::CStream classes (use as template argument).
563  * \sa Easier to use via function archiveFrom() */
564 template <class STREAM>
566 {
567  STREAM& m_s;
568 
569  public:
570  CArchiveStreamBase(STREAM& s) : m_s(s) {}
571 
572  protected:
573  size_t write(const void* d, size_t n) override { return m_s.Write(d, n); }
574  size_t read(void* d, size_t n) override { return m_s.Read(d, n); }
575 };
576 
577 /** Helper function to create a templatized wrapper CArchive object for a:
578  * MRPT's `CStream`, `std::istream`, `std::ostream`, `std::stringstream`.
579  * \note Use with `std::{.*}stream` requires including
580  * `<mrpt/serialization/archiveFrom_std_streams.h>` and explicitly specifying
581  * the template parameter like: `archiveFrom<std::istream>` or
582  * `archiveFrom<std::ostream>`.
583  * \sa \ref mrpt_serialization_grp, and example serialization_stl/test.cpp
584  */
585 template <class STREAM>
587 {
589 }
590 } // namespace mrpt::serialization
T ReadPOD()
Reads a simple POD type and returns by value.
Definition: CArchive.h:297
CExceptionEOF(const std::string &s)
Definition: CArchive.h:37
GLdouble GLdouble t
Definition: glext.h:3695
unsigned __int16 uint16_t
Definition: rptypes.h:47
size_t read(void *d, size_t n) override
Reads a block of bytes.
Definition: CArchive.h:574
std::chrono::time_point< Clock > time_point
Definition: Clock.h:26
GLenum GLsizei n
Definition: glext.h:5136
std::disjunction< std::is_same< T, Ts >... > is_any
Definition: CArchive.h:392
void WriteBufferFixEndianness(const T *ptr, size_t ElementCount)
Writes a sequence of elemental datatypes, taking care of reordering their bytes from the running arch...
Definition: CArchive.h:127
A structure that holds runtime class type information.
Definition: CObject.h:30
void WriteObject(const CSerializable &o)
Definition: CArchive.h:163
signed char int8_t
Definition: rptypes.h:43
STL namespace.
void WriteAs(const TYPE_FROM_ACTUAL &value)
Definition: CArchive.h:156
void WriteBuffer(const void *Buffer, size_t Count)
Writes a block of bytes to the stream from Buffer.
Definition: CArchive.cpp:49
RET ReadVariant_helper(CSerializable::Ptr &ptr, std::enable_if_t<!mrpt::is_shared_ptr< T >::value > *=nullptr)
Definition: CArchive.h:230
void sendMessage(const CMessage &msg)
Send a message to the device.
Definition: CArchive.cpp:521
GLdouble s
Definition: glext.h:3682
void reverseBytesInPlace(bool &v_in_out)
Reverse the order of the bytes of a given type (useful for transforming btw little/big endian) ...
GLenum GLsizei len
Definition: glext.h:4756
GLsizei GLsizei GLuint * obj
Definition: glext.h:4085
virtual size_t read(void *buf, size_t len)=0
Reads a block of bytes.
CArchive & operator>>(CSerializable &obj)
Reads a CSerializable object from the stream.
Definition: CArchive.cpp:158
This is useful for checking ::Ptr types.
Definition: is_shared_ptr.h:20
unsigned char uint8_t
Definition: rptypes.h:44
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT&#39;s CStream, std::istream, std::ostream, std::stringstream.
Definition: CArchive.h:586
void internal_ReadObjectHeader(std::string &className, bool &isOldFormat, int8_t &version)
Read the object Header.
Definition: CArchive.cpp:329
virtual ~CArchive()=default
void WriteVariant(T t)
Writes a Variant to the stream.
Definition: CArchive.h:283
__int16 int16_t
Definition: rptypes.h:46
void ReadAsAndCastTo(CAST_TO_TYPE &read_here)
Read a value from a stream stored in a type different of the target variable, making the conversion v...
Definition: CArchive.h:141
#define ASSERT_EQUAL_(__A, __B)
Assert comparing two values, reporting their actual values upon failure.
Definition: exceptions.h:178
__int64 int64_t
Definition: rptypes.h:52
STORED_TYPE ReadAs()
De-serialize a variable and returns it by value.
Definition: CArchive.h:149
size_t write(const void *d, size_t n) override
Writes a block of bytes.
Definition: CArchive.h:573
CArchive & operator<<(const CSerializable &obj)
Write a CSerializable object to a stream in the binary MRPT format.
Definition: CArchive.cpp:146
T::Ptr ReadObject()
Reads an object from stream, its class determined at runtime, and returns a smart pointer to the obje...
Definition: CArchive.h:181
GLubyte GLubyte b
Definition: glext.h:6372
is_any< T, bool, uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t, float, double, long double > is_simple_type
Definition: CArchive.h:397
GLsizei const GLchar ** string
Definition: glext.h:4116
bool receiveMessage(CMessage &msg)
Tries to receive a message from the device.
Definition: CArchive.cpp:555
virtual size_t write(const void *buf, size_t len)=0
Writes a block of bytes.
const TRuntimeClassId * findRegisteredClass(const std::string &className)
Return info about a given class by its name, or nullptr if the class is not registered.
CArchive for mrpt::io::CStream classes (use as template argument).
Definition: CArchive.h:565
CArchive & operator>>(CArchive &s, mrpt::aligned_std_vector< float > &a)
Definition: CArchive.cpp:250
__int32 int32_t
Definition: rptypes.h:49
unsigned __int64 uint64_t
Definition: rptypes.h:53
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:52
A class that contain generic messages, that can be sent and received from a "CClientTCPSocket" object...
Definition: CMessage.h:27
void internal_ReadObject(CSerializable *newObj, const std::string &className, bool isOldFormat, int8_t version)
Read the object.
Definition: CArchive.cpp:428
const float R
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::rtti::CObject) is of the give...
Definition: CObject.h:102
RET ReadVariant_helper(CSerializable::Ptr &ptr)
Definition: CArchive.h:213
RET ReadVariant_helper(CSerializable::Ptr &ptr, std::enable_if_t< mrpt::is_shared_ptr< T >::value > *=nullptr)
Definition: CArchive.h:220
GLuint in
Definition: glext.h:7391
CSerializable::Ptr ReadObject()
Reads an object from stream, its class determined at runtime, and returns a smart pointer to the obje...
Definition: CArchive.h:171
CArchive & operator<<(CArchive &s, const mrpt::aligned_std_vector< float > &a)
Definition: CArchive.cpp:199
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:30
size_t ReadBuffer(void *Buffer, size_t Count)
Reads a block of bytes from the stream into Buffer.
Definition: CArchive.cpp:25
void WriteObject(const CSerializable *o)
Writes an object to the stream.
Definition: CArchive.cpp:101
GLsizei const GLfloat * value
Definition: glext.h:4134
mrpt::rtti::CObject * createObject() const
Definition: CObject.cpp:79
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
Definition: exceptions.h:110
unsigned __int32 uint32_t
Definition: rptypes.h:50
size_t ReadBufferFixEndianness(T *ptr, size_t ElementCount)
Reads a sequence of elemental datatypes, taking care of reordering their bytes from the MRPT stream s...
Definition: CArchive.h:88
GLubyte GLubyte GLubyte a
Definition: glext.h:6372
std::variant< T... > ReadVariant()
Reads a variant from stream, its class determined at runtime, and returns a variant to the object...
Definition: CArchive.h:251
static constexpr auto get()
Definition: TTypeName.h:71
Used in mrpt::serialization::CArchive.
Definition: CArchive.h:34
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".
Definition: os.cpp:358



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: bef67d9c5 Mon Apr 15 00:03:11 2019 +0200 at lun abr 15 00:10:13 CEST 2019