GCC Code Coverage Report


Directory: ./
File: demos/serialization.cpp
Date: 2022-06-30 06:29:57
Exec Total Coverage
Lines: 0 25 0.0%
Branches: 0 30 0.0%

Line Branch Exec Source
1 #include "shared_memory/serializer.hpp"
2 #include "shared_memory/shared_memory.hpp"
3
4 class SerializableExample
5 {
6 public:
7 SerializableExample()
8 {
9 }
10
11 SerializableExample(int i1, int i2, double d1)
12 {
13 i1_ = i1;
14 i2_ = i2;
15 d1_ = d1;
16 }
17
18 void add(int value)
19 {
20 v_.push_back(value);
21 }
22
23 // This method lets cereal know which data members to serialize
24 template <class Archive>
25 void serialize(Archive& archive)
26 {
27 archive(i1_, i2_, d1_, v_);
28 }
29
30 void print()
31 {
32 std::cout << i1_ << " " << i2_ << " " << d1_ << "\n";
33 for (size_t i = 0; i < v_.size(); i++)
34 {
35 std::cout << v_[i] << " ";
36 }
37 std::cout << "\n";
38 }
39
40 private:
41 // this is required for the serialization
42 // to access the private members
43 friend shared_memory::private_serialization;
44
45 int i1_, i2_;
46 double d1_;
47 std::vector<int> v_;
48 };
49
50 int main()
51 {
52 shared_memory::clear_shared_memory("s1");
53
54 SerializableExample in(1, 1, 4);
55 in.add(5);
56 in.add(6);
57 in.print();
58 shared_memory::serialize("s1", "o1", in);
59
60 SerializableExample out;
61 shared_memory::deserialize("s1", "o1", out);
62 out.print();
63 }
64