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 }
IMPLEMENTS_SERIALIZABLE(Foo, CSerializable, MyNS)
unsigned char uint8_t
Definition: rptypes.h:41
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:561
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
Definition: CObject.h:85
__int16 int16_t
Definition: rptypes.h:43
This CStream derived class allow using a memory buffer as a CStream.
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...
GLubyte GLubyte b
Definition: glext.h:6279
#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
void registerClass(const mrpt::rtti::TRuntimeClassId *pNewClass)
Register a class into the MRPT internal list of "CObject" descendents.
GLsizei const GLfloat * value
Definition: glext.h:4117
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
[example-define-class]
TEST(Observations, WriteReadToMem)
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.



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