Main MRPT website > C++ reference for MRPT 1.9.9
CSerializable_unittest.cpp
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 
12 #include <mrpt/io/CMemoryStream.h>
13 #include <gtest/gtest.h>
14 
15 using namespace mrpt::serialization;
16 
17 namespace MyNS
18 {
19 class Foo : public CSerializable
20 {
22  public:
24 };
25 }
26 
28 
30 void MyNS::Foo::serializeTo(CArchive& out) const { out << value; }
32 {
33  in >> value;
34 }
35 
36 TEST(Serialization, CustomClassSerialize)
37 {
39 
40  MyNS::Foo a;
41  a.value = 123;
42 
44  auto arch = mrpt::serialization::archiveFrom(buf);
45  arch << a;
46 
47  buf.Seek(0);
48  MyNS::Foo b;
49  arch >> b;
50 
51  EXPECT_EQ(a.value, b.value);
52 }
mrpt::io::CMemoryStream::Seek
uint64_t Seek(int64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning) override
Introduces a pure virtual method for moving to a specified position in the streamed resource.
Definition: CMemoryStream.cpp:120
mrpt::rtti::registerClass
void registerClass(const mrpt::rtti::TRuntimeClassId *pNewClass)
Register a class into the MRPT internal list of "CObject" descendents.
Definition: internal_class_registry.cpp:155
Foo
Definition: stl_serialize_unittest.cpp:64
MyNS
[example-define-class]
Definition: rtti_unittest.cpp:13
TEST
TEST(Observations, WriteReadToMem)
Definition: serialization/src/CSerializable_unittest.cpp:74
CMemoryStream.h
MyNS::Foo::serializeGetVersion
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: serialization/src/CSerializable_unittest.cpp:29
uint8_t
unsigned char uint8_t
Definition: rptypes.h:41
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
int16_t
__int16 int16_t
Definition: rptypes.h:43
MyNS::Foo
Definition: serialization/src/CSerializable_unittest.cpp:19
IMPLEMENTS_SERIALIZABLE
IMPLEMENTS_SERIALIZABLE(Foo, CSerializable, MyNS)
b
GLubyte GLubyte b
Definition: glext.h:6279
mrpt::serialization::CSerializable
The virtual base class which provides a unified interface for all persistent objects in MRPT.
Definition: CSerializable.h:32
mrpt::io::CMemoryStream
This CStream derived class allow using a memory buffer as a CStream.
Definition: io/CMemoryStream.h:26
mrpt::serialization
Definition: aligned_serialization.h:14
mrpt::serialization::archiveFrom
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT's CStream,...
Definition: CArchive.h:561
CLASS_ID
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
Definition: CObject.h:85
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:102
value
GLsizei const GLfloat * value
Definition: glext.h:4117
MyNS::Foo::value
int16_t value
Definition: serialization/src/CSerializable_unittest.cpp:23
MyNS::Foo::serializeTo
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: serialization/src/CSerializable_unittest.cpp:30
in
GLuint in
Definition: glext.h:7274
CArchive.h
CSerializable.h
MyNS::Foo::serializeFrom
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: serialization/src/CSerializable_unittest.cpp:31
a
GLubyte GLubyte GLubyte a
Definition: glext.h:6279



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST