Chapter 16. Advanced topics

Table of Contents

16.1. Serializing multiple data sets into the same database file
16.2. Partially loading serialized data

This chapter discusses a few advanced topics which may assist your serialization efforts.

16.1. Serializing multiple data sets into the same database file

Suppose you had 2 sets of objects that you wanted to serialize into the same database file, and you wanted to name them "set_1" and "set_2".

Here's how you would save the data:

// must be in a block so that the database will be closed/flushed:
{
  // notice the same path is used here and below:
  ccs::serialization::storage<>    db1("/path/to/stored/data.db", "set_1");
  db1 << obj1_1 << obj1_2 << ... ;
}

// must be in a block so that the database will be closed/flushed:
{
  // notice the same path is used here and above:
  ccs::serialization::storage<>    db2("/path/to/stored/data.db", "set_2");
  db2 << obj2_1 << obj2_2 << ... ;
}

You can then load the data using the same technique. Note that sets can be loaded in a different order but the elements in a set must be loaded in the same order they were saved in.

// must be in a block so that the database will be closed/flushed:
{
  // notice the same path is used here and above:
  ccs::serialization::storage<>    db2("/path/to/stored/data.db", "set_2");
  db2 >> obj2_1 >> obj2_2 >> ... ;
}

// must be in a block so that the database will be closed/flushed:
{
  // notice the same path is used here and below:
  ccs::serialization::storage<>    db1("/path/to/stored/data.db", "set_1");
  db1 >> obj1_1 >> obj1_2 >> ... ;
}

As long as there are no name clashes, you can store as many sets of data as you wish, subject to storage limits of course.