MCPcopy Create free account
hub / github.com/alibaba/yalantinglibs / base_class_example

Function base_class_example

src/struct_pack/examples/derived_class.cpp:113–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111} // namespace base_class
112
113void base_class_example(void) {
114 using namespace base_class;
115 std::vector<std::unique_ptr<base>> data;
116 data.emplace_back(std::make_unique<obj2>());
117 data.emplace_back(std::make_unique<obj1>());
118 data.emplace_back(std::make_unique<obj3>());
119 data.emplace_back(std::make_unique<base>());
120 auto ret = struct_pack::serialize(data);
121 auto checker = std::vector{"obj2", "obj1", "obj3", "base"};
122 auto result =
123 struct_pack::deserialize<std::vector<std::unique_ptr<base>>>(ret);
124 assert(result.has_value());
125 assert(result->size() == 4); // check vector size
126 for (size_t i = 0; i < result->size(); ++i) {
127 assert(checker[i] == result.value()[i]->hello()); // check type
128 }
129}
130
131void deserialize_derived_class_example() {
132 using namespace base_class;

Callers 1

derived_class_exampleFunction · 0.85

Calls 5

serializeFunction · 0.85
has_valueMethod · 0.45
sizeMethod · 0.45
helloMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected