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 // See: https://stackoverflow.com/a/46507150/1631514
26 #if defined(__clang__) && (__clang_major__ <= 7)
27 #define HAS_BROKEN_CLANG_STD_VISIT
28 #endif
29 
30 namespace mrpt::serialization
31 {
32 class CMessage;
33 
34 /** Used in mrpt::serialization::CArchive */
35 class CExceptionEOF : public std::runtime_error
36 {
37  public:
38  CExceptionEOF(const std::string& s) : std::runtime_error(s) {}
39 };
40 
41 /** Virtual base class for "archives": classes abstracting I/O streams.
42  * This class separates the implementation details of serialization (in
43  * CSerializable) and data storage (CArchive children: files, sockets,...).
44  *
45  * Two main sets of implementations are provided:
46  * - archiveFrom: for MRPT mrpt::io::CArchive objects, and
47  * - CArchiveStdIStream and CArchiveStdOStream: for std::istream and
48  * std::ostream, respectively.
49  *
50  * \sa mrpt::io::CArchive, mrpt::serialization::CSerializable
51  * \ingroup mrpt_serialization_grp
52  */
53 class CArchive
54 {
55  public:
56  CArchive() = default;
57  virtual ~CArchive() = default;
58  /** @name Serialization API for generic "archives" I/O streams
59  * @{ */
60  /** Reads a block of bytes from the stream into Buffer
61  * \exception std::exception On any error, or if ZERO bytes are read.
62  * \return The amound of bytes actually read.
63  * \note This method is endianness-dependent.
64  * \sa ReadBufferImmediate ; Important, see: ReadBufferFixEndianness,
65  */
66  size_t ReadBuffer(void* Buffer, size_t Count);
67 
68  /** Reads a sequence of elemental datatypes, taking care of reordering their
69  *bytes from the MRPT stream standard (little endianness) to the format of
70  *the running architecture.
71  * \param ElementCount The number of elements (not bytes) to read.
72  * \param ptr A pointer to the first output element in an array (or
73  *std::vector<>, etc...).
74  * \return The amound of *bytes* (not elements) actually read (under error
75  *situations, the last element may be invalid if the data stream abruptly
76  *ends).
77  * Example of usage:
78  * \code
79  * uint32_t N;
80  * s >> N;
81  * vector<float> vec(N);
82  * if (N)
83  * s.ReadBufferFixEndianness<float>(&vec[0],N);
84  * \endcode
85  * \exception std::exception On any error, or if ZERO bytes are read.
86  * \sa ReadBufferFixEndianness, ReadBuffer
87  */
88  template <typename T>
89  size_t ReadBufferFixEndianness(T* ptr, size_t ElementCount)
90  {
91 #if !MRPT_IS_BIG_ENDIAN
92  // little endian: no conversion needed.
93  return ReadBuffer(ptr, ElementCount * sizeof(T));
94 #else
95  // big endian: convert.
96  const size_t nread = ReadBuffer(ptr, ElementCount * sizeof(T));
97  for (size_t i = 0; i < ElementCount; i++)
99  return nread;
100 #endif
101  }
102 
103  /** Writes a block of bytes to the stream from Buffer.
104  * \exception std::exception On any error
105  * \sa Important, see: WriteBufferFixEndianness
106  * \note This method is endianness-dependent.
107  */
108  void WriteBuffer(const void* Buffer, size_t Count);
109 
110  /** Writes a sequence of elemental datatypes, taking care of reordering
111  * their bytes from the running architecture to MRPT stream standard (little
112  * endianness).
113  * \param ElementCount The number of elements (not bytes) to write.
114  * \param ptr A pointer to the first input element in an array (or
115  * std::vector<>, etc...).
116  * Example of usage:
117  * \code
118  * vector<float> vec = ...
119  * uint32_t N = vec.size();
120  * s << N
121  * if (N)
122  * s.WriteBufferFixEndianness<float>(&vec[0],N);
123  * \endcode
124  * \exception std::exception On any error
125  * \sa WriteBuffer
126  */
127  template <typename T>
128  void WriteBufferFixEndianness(const T* ptr, size_t ElementCount)
129  {
130 #if !MRPT_IS_BIG_ENDIAN
131  // little endian: no conversion needed.
132  return WriteBuffer(ptr, ElementCount * sizeof(T));
133 #else
134  // big endian: the individual "<<" functions already convert endiannes
135  for (size_t i = 0; i < ElementCount; i++) (*this) << ptr[i];
136 #endif
137  }
138  /** Read a value from a stream stored in a type different of the target
139  * variable, making the conversion via static_cast. Useful for coding
140  * backwards compatible de-serialization blocks */
141  template <typename STORED_TYPE, typename CAST_TO_TYPE>
142  void ReadAsAndCastTo(CAST_TO_TYPE& read_here)
143  {
144  STORED_TYPE var;
145  (*this) >> var;
146  read_here = static_cast<CAST_TO_TYPE>(var);
147  }
148  /** De-serialize a variable and returns it by value. */
149  template <typename STORED_TYPE>
150  STORED_TYPE ReadAs()
151  {
152  STORED_TYPE var;
153  (*this) >> var;
154  return var;
155  }
156  template <typename TYPE_TO_STORE, typename TYPE_FROM_ACTUAL>
157  void WriteAs(const TYPE_FROM_ACTUAL& value)
158  {
159  (*this) << static_cast<TYPE_TO_STORE>(value);
160  }
161  /** Writes an object to the stream.
162  */
163  void WriteObject(const CSerializable* o);
164  void WriteObject(const CSerializable& o) { WriteObject(&o); }
165  /** Reads an object from stream, its class determined at runtime, and
166  * returns a smart pointer to the object.
167  * \exception std::exception On I/O error or undefined class.
168  * \exception CExceptionEOF On an End-Of-File condition found
169  * at a correct place: an EOF that abruptly finishes in the middle of one
170  * object raises a plain std::exception instead.
171  */
172  CSerializable::Ptr ReadObject() { return ReadObject<CSerializable>(); }
173  /** Reads an object from stream, its class determined at runtime, and
174  * returns a smart pointer to the object. This version is similar to
175  * std::make_shared<T>.
176  * \exception std::exception On I/O error or undefined class.
177  * \exception CExceptionEOF On an End-Of-File condition found
178  * at a correct place: an EOF that abruptly finishes in the middle of one
179  * object raises a plain std::exception instead.
180  */
181  template <typename T>
182  typename T::Ptr ReadObject()
183  {
185  std::string strClassName;
186  bool isOldFormat{false};
187  int8_t version{-1};
188  internal_ReadObjectHeader(strClassName, isOldFormat, version);
189  if (strClassName != "nullptr")
190  {
191  const mrpt::rtti::TRuntimeClassId* classId =
192  mrpt::rtti::findRegisteredClass(strClassName);
193  if (!classId)
195  "Stored object has class '%s' which is not registered!",
196  strClassName.c_str());
198  }
200  obj.get() /* may be nullptr */, strClassName, isOldFormat,
201  version); // must be called to read the END FLAG byte
202  if (!obj)
203  {
204  return typename T::Ptr();
205  }
206  else
207  {
208  return std::dynamic_pointer_cast<T>(obj);
209  }
210  }
211 
212  private:
213  template <typename RET>
215  {
216  throw std::runtime_error("Can't match variant type");
217  return RET();
218  }
219 
220  template <typename RET, typename T, typename... R>
222  CSerializable::Ptr& ptr,
223  std::enable_if_t<mrpt::is_shared_ptr<T>::value>* = nullptr)
224  {
225  if (IS_CLASS(ptr, typename T::element_type))
226  return std::dynamic_pointer_cast<typename T::element_type>(ptr);
227  return ReadVariant_helper<RET, R...>(ptr);
228  }
229 
230  template <typename RET, typename T, typename... R>
232  CSerializable::Ptr& ptr,
233  std::enable_if_t<!mrpt::is_shared_ptr<T>::value>* = nullptr)
234  {
235  if (IS_CLASS(*ptr, T)) return dynamic_cast<T&>(*ptr);
236  return ReadVariant_helper<RET, R...>(ptr);
237  }
238 
239  public:
240  /** Reads a variant from stream, its class determined at runtime, and
241  * returns a variant to the object.
242  * To be compatible with the current polymorphic system this support smart
243  * pointer types.
244  * For pointer types, This will bind to the first possible pointer type.
245  * variant<CSerializable::Ptr, CRenderizable::Ptr>
246  * \exception std::exception On I/O error or undefined class.
247  * \exception CExceptionEOF On an End-Of-File condition found
248  * at a correct place: an EOF that abruptly finishes in the middle of one
249  * object raises a plain std::exception instead.
250  */
251  template <typename... T>
252  typename std::variant<T...> ReadVariant()
253  {
255  std::string strClassName;
256  bool isOldFormat;
257  int8_t version;
258  internal_ReadObjectHeader(strClassName, isOldFormat, version);
259  const mrpt::rtti::TRuntimeClassId* classId =
260  mrpt::rtti::findRegisteredClass(strClassName);
261  if (!classId)
263  "Stored object has class '%s' which is not registered!",
264  strClassName.c_str());
265  if (strClassName != "nullptr")
266  {
268  }
269  internal_ReadObject(obj.get(), strClassName, isOldFormat, version);
270  if (!obj)
271  {
272  return std::variant<T...>();
273  }
274  else
275  {
276  return ReadVariant_helper<std::variant<T...>, T...>(obj);
277  }
278  }
279 
280 #if !defined(HAS_BROKEN_CLANG_STD_VISIT)
281  /** Writes a Variant to the stream */
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
591 
592 namespace mrpt::rtti
593 {
594 // for std::variant
595 template <>
596 struct CLASS_ID_impl<std::monostate>
597 {
598  static constexpr const mrpt::rtti::TRuntimeClassId* get()
599  {
600  return nullptr;
601  }
602 };
603 
604 } // namespace mrpt::rtti
std::shared_ptr< CObject > createObject() const
Definition: CObject.cpp:79
T ReadPOD()
Reads a simple POD type and returns by value.
Definition: CArchive.h:297
CExceptionEOF(const std::string &s)
Definition: CArchive.h:38
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:128
A structure that holds runtime class type information.
Definition: CObject.h:31
void WriteObject(const CSerializable &o)
Definition: CArchive.h:164
signed char int8_t
Definition: rptypes.h:43
STL namespace.
void WriteAs(const TYPE_FROM_ACTUAL &value)
Definition: CArchive.h:157
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:231
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:142
#define ASSERT_EQUAL_(__A, __B)
Assert comparing two values, reporting their actual values upon failure.
Definition: exceptions.h:137
__int64 int64_t
Definition: rptypes.h:52
STORED_TYPE ReadAs()
De-serialize a variable and returns it by value.
Definition: CArchive.h:150
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:182
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
#define IS_CLASS(obj, class_name)
True if the given reference to object (derived from mrpt::rtti::CObject) is of the given class...
Definition: CObject.h:133
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:53
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
RET ReadVariant_helper(CSerializable::Ptr &ptr)
Definition: CArchive.h:214
RET ReadVariant_helper(CSerializable::Ptr &ptr, std::enable_if_t< mrpt::is_shared_ptr< T >::value > *=nullptr)
Definition: CArchive.h:221
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:172
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
static CAST_TO::Ptr from(const CAST_FROM_PTR &ptr)
Definition: CObject.h:366
void WriteObject(const CSerializable *o)
Writes an object to the stream.
Definition: CArchive.cpp:101
GLsizei const GLfloat * value
Definition: glext.h:4134
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
Definition: exceptions.h:69
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:89
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:252
static constexpr auto get()
Definition: TTypeName.h:71
Used in mrpt::serialization::CArchive.
Definition: CArchive.h:35
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: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019