MRPT  1.9.9
CSerializable_unittest.cpp
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 
10 #include <gtest/gtest.h>
11 #include <mrpt/io/CMemoryStream.h>
14 
15 using namespace mrpt::serialization;
16 
17 namespace MyNS
18 {
19 class Foo : public CSerializable
20 {
22  public:
24 };
25 } // namespace MyNS
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: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:586
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
Definition: CObject.h:89
__int16 int16_t
Definition: rptypes.h:46
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:6372
#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:53
GLuint in
Definition: glext.h:7391
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:30
void registerClass(const mrpt::rtti::TRuntimeClassId *pNewClass)
Register a class into the MRPT internal list of "CObject" descendents.
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
GLsizei const GLfloat * value
Definition: glext.h:4134
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
GLubyte GLubyte GLubyte a
Definition: glext.h:6372
[example-define-class]
TEST(Observations, WriteReadToMem)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019