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