| 1 | #include <boost/serialization/split_member.hpp>
|
|---|
| 2 | #include <boost/serialization/vector.hpp>
|
|---|
| 3 | #include <boost/serialization/utility.hpp>
|
|---|
| 4 | #include <boost/archive/text_iarchive.hpp>
|
|---|
| 5 | #include <boost/archive/text_oarchive.hpp>
|
|---|
| 6 | #include <boost/serialization/string.hpp>
|
|---|
| 7 |
|
|---|
| 8 | #include <fstream>
|
|---|
| 9 | #include <iostream>
|
|---|
| 10 | #include <unordered_map>
|
|---|
| 11 |
|
|---|
| 12 | using namespace std;
|
|---|
| 13 |
|
|---|
| 14 | class Foo
|
|---|
| 15 | {
|
|---|
| 16 | public:
|
|---|
| 17 | string s;
|
|---|
| 18 |
|
|---|
| 19 | Foo()
|
|---|
| 20 | {}
|
|---|
| 21 |
|
|---|
| 22 | Foo(string s):
|
|---|
| 23 | s(s)
|
|---|
| 24 | {}
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 | Foo(const Foo& other) = delete;
|
|---|
| 28 | Foo &operator=(const Foo &other) = delete;
|
|---|
| 29 |
|
|---|
| 30 | Foo(Foo &&other) noexcept = default;
|
|---|
| 31 | Foo &operator=(Foo &&other) noexcept = default;
|
|---|
| 32 |
|
|---|
| 33 | template <typename Archive>
|
|---|
| 34 | void save(Archive &ar, const unsigned int version) const
|
|---|
| 35 | {
|
|---|
| 36 | ar & this->s;
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | template <typename Archive>
|
|---|
| 40 | void load(Archive &ar, const unsigned int version)
|
|---|
| 41 | {
|
|---|
| 42 | ar & this->s;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | BOOST_SERIALIZATION_SPLIT_MEMBER()
|
|---|
| 46 |
|
|---|
| 47 | friend class boost::serialization::access;
|
|---|
| 48 | };
|
|---|
| 49 |
|
|---|
| 50 | int main(int argc, char *argv[])
|
|---|
| 51 | {
|
|---|
| 52 | vector<pair<const uint8_t, Foo>> bar;
|
|---|
| 53 |
|
|---|
| 54 | const char* text_file_name = "/tmp/test-fixed-multibit.txt";
|
|---|
| 55 | {
|
|---|
| 56 | std::ofstream ofs(text_file_name);
|
|---|
| 57 | boost::archive::text_oarchive ar(ofs);
|
|---|
| 58 | ar & bar;
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | {
|
|---|
| 62 | vector<pair<const uint8_t, Foo>> bar1;
|
|---|
| 63 |
|
|---|
| 64 | std::ifstream ifs(text_file_name);
|
|---|
| 65 | boost::archive::text_iarchive ar(ifs);
|
|---|
| 66 |
|
|---|
| 67 | ar & bar1;
|
|---|
| 68 | }
|
|---|
| 69 | return 0;
|
|---|
| 70 | }
|
|---|