November 5th, 2012, 05:30 AM
custom streambuf for use with std::fstream?
I have an application which uses several files to store its data.
The data is organized to store all current data like this, and additionally the data is moved to a single file after a specific time interval to be able to back it up. This single file then contains all data for the time interval like this:
Suppose the data are stored in file1, ..., file8.
The single file has all data for the time interval from file1, then from file2, ...
The data sections may be addressed via an offset into the file plus a length of each section to identify the end.
In the application, I must be able to access data from the single file as well as from the multiple files. I was thinking of hiding the single file in a kind of a wrapper of an std::ifstream with a buffer that is supplied with the offset of the data and the length and thus models a single file.
In other words, I have 8 std::fstreams in the application, and when I access the single file, I create 8 fstreams with buffers "pointing" to the separate data sections.
My first thought was to create my own streambuf-derived class to achieve this. I am currently looking at boost::Iostreams, but am not sure if that may provide a solution.
Does anyone here have a comment on my approach?
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!