Last active
July 7, 2016 18:00
-
-
Save tilarids/cc64ab35a09eda717ee48b99b8c79266 to your computer and use it in GitHub Desktop.
Testbed for C++ serialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main | |
main.dSYM/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
// should be serializable. | |
class A { | |
public: | |
A(int x, int y): x_(x), y_(y) {} | |
virtual ~A() {} | |
private: | |
int x_; | |
int y_; | |
}; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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_; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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_; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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