As shown in the Archives article, both the input and output archive wrap a reference to a corresponding c++ standard stream. The output archives use an underlying std::ostream, the input archives a std::istream.
Since the input archives derived from tsl::itext_archive are implemented through boost::spirit, the underlying std::istream should have the ios::skipws bit unset, if not, a std::runtime_error is thrown at the very first TSL usage. TSL also uses std::exception in all its code, so it is a good practice to enable them inside the standard c++ IO streams as well. Below the code in order to properly use a stream for [de]serialization under TSL:
1 2 3 4 | ifstream stream; stream.exceptions(std::ifstream::failbit|std::ifstream::badbit); stream.open( "file_name" ); stream.unsetf(ios::skipws); |
The most recent version of TSL introduces a template wrapper for c++ standard stream so that the previous code becomes the following:
1 | tsl::ISWrapper stream( "file_name" ); |
Considering an output stream instead:
1 2 3 | ofstream stream; stream.exceptions(std::ifstream::failbit|std::ifstream::badbit); stream.open( "output_file" ); |
with the usage of the OSWrapper the code becomes:
1 | tsl::OSWrapper stream( "output_file_name" ); |