Skip to content

Instantly share code, notes, and snippets.

@tilarids tilarids/.gitignore
Last active Jul 7, 2016

Embed
What would you like to do?
Testbed for C++ serialization
main
main.dSYM/
#pragma once
// should be serializable.
class A {
public:
A(int x, int y): x_(x), y_(y) {}
virtual ~A() {}
private:
int x_;
int y_;
};
#pragma once
#include "a.h"
// should be serializable.
class B : public A {
public:
B(int x, int y, double z): A(x, y), z_(z) {}
virtual ~B() {}
private:
double z_;
};
#pragma once
#include <vector>
#include "b.h"
// should be serializable.
class C {
public:
explicit C(int n) {
v_b_.reserve(n);
v_.reserve(n);
for (int i = 0; i < n; ++i) {
v_b_.emplace_back(i, i + 1, i * 42);
v_.push_back(i);
}
}
private:
std::vector<B> v_b_;
std::vector<int> v_;
};
#include <string>
#include "c.h"
void serialize(const std::string& filename, C) {
// todo
}
C deserialize(const std::string& filename) {
// todo
return C(0);
}
int main() {
C test1(3);
C test2(5);
serialize("test1.bin", test1);
serialize("test2.bin", test2);
C test1_new = deserialize("test1.bin");
C test2_new = deserialize("test2.bin");
return 0;
}
main: main.cpp a.h b.h c.h
g++ -g -O0 -o main -std=c++11 main.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.