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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ce444d842 Fri Dec 6 19:35:10 2019 +0100 at vie dic 6 19:45:12 CET 2019