I am writing some kind of virtual file system library for video games in the likes of CRF Middleware ROFS (see Wikipedia ). My intention in the library is to provide natural ways of accessing the resources of developed games, which store some data embedded in the executable file, some on media, and some on the user's local hard drive (preferences, saving game files, etc.), .
Access to such resources should be as simple as calling as
std::auto_ptr<std::istream> defaultConfigIStream(
fslib.inputStream("self://defaultConfig.ini"));
std::auto_ptr<std::ostream> defaultConfigOStream(
fslib.outputStream("localappdata://config.ini"));
defaultConfigIStream >> defaultConfigOStream;
The actual way of doing things is actually different, with a different level of abstraction used to load the background, but that doesn't matter here.
I want to know how I can return this auto_ptr<>(or unique_ptr<>, you choose), given that the std::streambuf<>associated std::[i/o]stream<>one is not deleted by it when it is destroyed.
I consider it std::[i/o]stream<>does not imply ownership of the streambuf transferred to it during construction, since the constructor does not transfer ownership semantics, and the Apache STDCXX link does not mention ownership transfers (and not one of the stdlib links I found on the Internet).
What are my alternatives? I could also return the shared pointer and keep an eye on it until the FSlib manager stores a unique copy of the shared pointer, in which case it destroys its unique copy, as well as streambuf. This is practical given the organizational model of the library, but it is not very elegant and effective in this regard.
Boost.Iostreams, , , , ( ). , -, Boost.Iostreams , "/", , , , , .
, , (.. , !;).
?