Main MRPT website > C++ reference for MRPT 1.9.9
CMemoryChunk.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
13 
14 namespace mrpt
15 {
16 namespace io
17 {
18 class CMemoryStream;
19 }
20 namespace serialization
21 {
22 template <class Derived>
24 
26 
27 /** A memory buffer (implements CStream) which can be itself serialized.
28  *
29  * \sa CStream
30  * \ingroup mrpt_base_grp
31  */
32 template <class Derived>
33 class CMemoryChunkBase : public CSerializable, public Derived
34 {
36  protected:
37  Derived& derived() { return static_cast<Derived&>(*this); }
38  const Derived& derived() const
39  {
40  return static_cast<const Derived&>(*this);
41  }
42 }; // End of class def.
43 
44 template <class Derived>
46 {
47  return 0;
48 }
49 template <class Derived>
51 {
52  out << static_cast<uint64_t>(derived().getTotalBytesCount());
53  if (derived().getTotalBytesCount())
54  {
55  ASSERT_(derived().getRawBufferData());
56  out.WriteBuffer(
57  derived().getRawBufferData(), derived().getTotalBytesCount());
58  }
59 }
60 template <class Derived>
62 {
63  switch (version)
64  {
65  case 0:
66  {
67  uint64_t N;
68  in >> N;
69  derived().changeSize(N);
70  derived().Seek(0);
71  if (N) in.ReadBuffer(derived().getRawBufferData(), N);
72  }
73  break;
74  default:
76  };
77 }
78 
79 } // namespace serialization
80 } // namespace mrpt
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CMemoryChunk.h:50
void WriteBuffer(const void *Buffer, size_t Count)
Writes a block of bytes to the stream from Buffer.
Definition: CArchive.cpp:48
mrpt::io::CMemoryStream CMemoryStream
unsigned char uint8_t
Definition: rptypes.h:41
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:90
A memory buffer (implements CStream) which can be itself serialized.
Definition: CMemoryChunk.h:23
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: CMemoryChunk.h:45
unsigned __int64 uint64_t
Definition: rptypes.h:50
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
GLuint in
Definition: glext.h:7274
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:32
const Derived & derived() const
Definition: CMemoryChunk.h:38
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: CMemoryChunk.h:61



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019