From Martin Naylor, replace osgDB::fstream with an osgDB::open() call.

This commit is contained in:
Robert Osfield 2013-06-12 12:49:18 +00:00
parent 1a7f2fcb3e
commit b4bfc3a451
4 changed files with 12 additions and 23 deletions

View File

@ -19,26 +19,17 @@
#include <fstream>
namespace osgDB
{
/**
* Replacements for std::fstream, std::ifstream, and std::ofstream to
* Convenience function for fstream open , std::ifstream, and std::ofstream to
* automatically handle UTF-8 to UTF-16 filename conversion. Always use one
* of these classes in any OpenSceneGraph code instead of the STL equivalent.
*/
class OSGDB_EXPORT fstream : public std::fstream
{
public:
fstream();
explicit fstream(const char* filename,
std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out);
~fstream();
void open(const char* filename,
std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out);
};
void OSGDB_EXPORT open(std::fstream& fs, const char* filename,std::ios_base::openmode mode);
class OSGDB_EXPORT ifstream : public std::ifstream
{

View File

@ -12,6 +12,8 @@
*/
#include <osgDB/fstream>
#include <osgDB/ConvertUTF>
#include <osg/Config>
@ -25,17 +27,13 @@ namespace osgDB
#define OSGDB_CONVERT_UTF8_FILENAME(s) s
#endif
fstream::fstream(){}
fstream::fstream(const char* filename,
std::ios_base::openmode mode) : std::fstream(OSGDB_CONVERT_UTF8_FILENAME(filename), mode)
{}
fstream::~fstream(){}
void fstream::open(const char* filename,
std::ios_base::openmode mode)
void open(std::fstream &fs, const char* filename,std::ios_base::openmode mode)
{
std::fstream::open(OSGDB_CONVERT_UTF8_FILENAME(filename), mode);
fs.open(OSGDB_CONVERT_UTF8_FILENAME(filename), mode);
}
ifstream::ifstream(){}
ifstream::ifstream(const char* filename,
std::ios_base::openmode mode) : std::ifstream(OSGDB_CONVERT_UTF8_FILENAME(filename), mode)

View File

@ -373,7 +373,7 @@ bool OSGA_Archive::open(const std::string& filename, ArchiveStatus status, unsig
_input.close();
_status = WRITE;
_output.open(filename.c_str(), std::ios_base::binary | std::ios_base::in | std::ios_base::out);
osgDB::open(_output, filename.c_str(), std::ios_base::binary | std::ios_base::in | std::ios_base::out);
OSG_INFO<<"File position after open = "<<ARCHIVE_POS( _output.tellp() )<<" is_open "<<_output.is_open()<<std::endl;
@ -391,7 +391,7 @@ bool OSGA_Archive::open(const std::string& filename, ArchiveStatus status, unsig
OSG_INFO<<"OSGA_Archive::open("<<filename<<"), archive being created."<<std::endl;
_status = WRITE;
_output.open(filename.c_str(), std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
osgDB::open(_output, filename.c_str(), std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
_output<<"osga";
_output.write(reinterpret_cast<const char*>(&ENDIAN_TEST_NUMBER),4);
_output.write(reinterpret_cast<char*>(&s_currentSupportedVersion),sizeof(float));

View File

@ -217,7 +217,7 @@ class OSGA_Archive : public osgDB::Archive
float _version;
ArchiveStatus _status;
osgDB::ifstream _input;
osgDB::fstream _output;
std::fstream _output;
std::string _archiveFileName;
std::string _masterFileName;