diff --git a/CMakeLists.txt b/CMakeLists.txt index d03ca192f..022fb9360 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -263,6 +263,9 @@ MARK_AS_ADVANCED(OSG_USE_FLOAT_BOUNDINGSPHERE) OPTION(OSG_USE_FLOAT_BOUNDINGBOX "Set to ON to build OpenSceneGraph with float BoundingBox instead of double." ON) MARK_AS_ADVANCED(OSG_USE_FLOAT_BOUNDINGBOX) +OPTION(OSG_USE_UTF8_FILENAME "Set to ON to use a UTF8 locale for filenames instead of the default locale." OFF) +MARK_AS_ADVANCED(OSG_USE_UTF8_FILENAME) + OPTION(OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION "Set to ON to use the ref_ptr<> T* operator() output conversion. " ON) ################################################################################ diff --git a/applications/osgversion/CMakeLists.txt b/applications/osgversion/CMakeLists.txt index 369b859a1..45aedad94 100644 --- a/applications/osgversion/CMakeLists.txt +++ b/applications/osgversion/CMakeLists.txt @@ -3,6 +3,7 @@ SET(TARGET_SRC osgversion.cpp ) SET(TARGET_COMMON_LIBRARIES OpenThreads osg + osgDB ) SETUP_COMMANDLINE_APPLICATION(osgversion) diff --git a/applications/osgversion/osgversion.cpp b/applications/osgversion/osgversion.cpp index 98a362e07..6c2e3f800 100644 --- a/applications/osgversion/osgversion.cpp +++ b/applications/osgversion/osgversion.cpp @@ -8,13 +8,13 @@ #include #include +#include #include #include #include #include -#include // the majority of the application is dedicated to building the // current contribitors list by parsing the ChangeLog, it just takes @@ -676,7 +676,7 @@ bool submissionsSequence(const Words& words, unsigned int& i) void readContributors(NameMap& names, const std::string& file) { - std::ifstream fin(file.c_str()); + osgDB::ifstream fin(file.c_str()); Words words; while(fin) diff --git a/examples/osg2cpp/osg2cpp.cpp b/examples/osg2cpp/osg2cpp.cpp index b4e9f2750..c0c4e2419 100644 --- a/examples/osg2cpp/osg2cpp.cpp +++ b/examples/osg2cpp/osg2cpp.cpp @@ -3,13 +3,13 @@ #include #include +#include #include -#include void writeShader(osg::Shader* shader, const std::string& cppFileName, const std::string& variableName) { - std::ofstream fout(cppFileName.c_str()); + osgDB::ofstream fout(cppFileName.c_str()); if (!fout) { std::cout<<"Error: could not open file `"< #include -#include #include #include #include #include +#include bool Utility::readFile(const char* fName, std::string& s) { std::string foundFile = osgDB::findDataFile(fName); if (foundFile.empty()) return false; - std::ifstream is;//(fName); + osgDB::ifstream is;//(fName); is.open(foundFile.c_str()); if (is.fail()) { @@ -73,7 +73,7 @@ double Utility::getNoise(unsigned x, unsigned y, unsigned random) int n = x + y * 57 + random * 131; n = (n<<13) ^ n; double noise = (1.0f - ( (n * (n * n * 15731 + 789221) + - 1376312589)&0x7fffffff)* 0.000000000931322574615478515625f); + 1376312589)&0x7fffffff)* 0.000000000931322574615478515625f); return noise; } @@ -86,13 +86,13 @@ double Utility::smoothNoise(unsigned width, unsigned height, unsigned x, unsigne return noise[x + y*width]; double corners = (noise[x-1 + (y-1) *width] - +noise[x+1 + (y-1)*width] - +noise[x-1 + (y+1) * width] - +noise[x+1 + (y+1) * width]) / 16.0; + +noise[x+1 + (y-1)*width] + +noise[x-1 + (y+1) * width] + +noise[x+1 + (y+1) * width]) / 16.0; double sides = (noise[x-1 + y*width] - +noise[x+1 + y*width] - +noise[x + (y-1)*width] - +noise[x + (y+1)*width]) / 8.0; + +noise[x+1 + y*width] + +noise[x + (y-1)*width] + +noise[x + (y+1)*width]) / 8.0; double center = noise[x + y*width] / 4.0; return corners + sides + center; diff --git a/examples/osglauncher/osglauncher.cpp b/examples/osglauncher/osglauncher.cpp index d3c23902b..4b3416383 100644 --- a/examples/osglauncher/osglauncher.cpp +++ b/examples/osglauncher/osglauncher.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -48,6 +47,7 @@ #include #include +#include int runApp(std::string xapp); @@ -249,7 +249,7 @@ void readConfFile(const char* confFile) } - std::ifstream in(fileName.c_str()); + osgDB::ifstream in(fileName.c_str()); if (!in) { osg::notify(osg::INFO) << "File " << fileName << " can not be opened!" << std::endl; diff --git a/examples/osgphotoalbum/PhotoArchive.cpp b/examples/osgphotoalbum/PhotoArchive.cpp index ee2b1b906..4c06137cf 100644 --- a/examples/osgphotoalbum/PhotoArchive.cpp +++ b/examples/osgphotoalbum/PhotoArchive.cpp @@ -21,10 +21,10 @@ #include #include #include +#include #include -#include #include @@ -78,7 +78,7 @@ PhotoArchive::PhotoArchive(const std::string& filename) bool PhotoArchive::readPhotoIndex(const std::string& filename) { - std::ifstream in(filename.c_str()); + osgDB::ifstream in(filename.c_str()); char* fileIndentifier = new char [FILE_IDENTIFER.size()]; in.read(fileIndentifier,FILE_IDENTIFER.size()); @@ -124,7 +124,7 @@ osg::Image* PhotoArchive::readImage(const std::string& filename, target_t <= photoHeader.thumbnail_t && photoHeader.thumbnail_position != 0) { - std::ifstream in(_archiveFileName.c_str(),std::ios::in | std::ios::binary); + osgDB::ifstream in(_archiveFileName.c_str(),std::ios::in | std::ios::binary); // find image in.seekg(photoHeader.thumbnail_position); @@ -150,7 +150,7 @@ osg::Image* PhotoArchive::readImage(const std::string& filename, photoHeader.fullsize_t && photoHeader.fullsize_position != 0) { - std::ifstream in(_archiveFileName.c_str(),std::ios::in | std::ios::binary); + osgDB::ifstream in(_archiveFileName.c_str(),std::ios::in | std::ios::binary); // find image in.seekg(photoHeader.fullsize_position); @@ -211,7 +211,7 @@ void PhotoArchive::buildArchive(const std::string& filename, const FileNameList& MyGraphicsContext context; // open up the archive for writing to - std::ofstream out(filename.c_str(), std::ios::out | std::ios::binary); + osgDB::ofstream out(filename.c_str(), std::ios::out | std::ios::binary); // write out file indentifier. out.write(FILE_IDENTIFER.c_str(),FILE_IDENTIFER.size()); diff --git a/examples/osgsimulation/osgsimulation.cpp b/examples/osgsimulation/osgsimulation.cpp index 692c0a2cc..280910391 100644 --- a/examples/osgsimulation/osgsimulation.cpp +++ b/examples/osgsimulation/osgsimulation.cpp @@ -46,6 +46,7 @@ #include #include +#include #include #include @@ -243,7 +244,7 @@ int main(int argc, char **argv) std::string flightpath_filename; while (arguments.read("--flight-path",flightpath_filename)) { - std::ifstream fin(flightpath_filename.c_str()); + osgDB::ifstream fin(flightpath_filename.c_str()); if (fin) { osg::AnimationPath* path = new osg::AnimationPath; diff --git a/examples/osgstereoimage/osgstereoimage.cpp b/examples/osgstereoimage/osgstereoimage.cpp index 8309b02a5..7785bcd64 100644 --- a/examples/osgstereoimage/osgstereoimage.cpp +++ b/examples/osgstereoimage/osgstereoimage.cpp @@ -17,6 +17,7 @@ */ #include +#include #include #include #include @@ -499,7 +500,7 @@ int main( int argc, char **argv ) FileList fileList; // extract the filenames from the a file, one filename per line. while (arguments.read("-files",filename)) { - std::ifstream is(filename.c_str()); + osgDB::ifstream is(filename.c_str()); if (is) { std::string line; while (std::getline(is,line,'\n')) fileList.push_back(line); diff --git a/examples/osgterrain/osgterrain.cpp b/examples/osgterrain/osgterrain.cpp index a46438786..39e3a2973 100644 --- a/examples/osgterrain/osgterrain.cpp +++ b/examples/osgterrain/osgterrain.cpp @@ -30,6 +30,7 @@ #include +#include #include #include @@ -120,7 +121,7 @@ public: bool readMasterFile(Files& files) const { - std::ifstream fin(_filename.c_str()); + osgDB::ifstream fin(_filename.c_str()); if (fin) { osgDB::Input fr; diff --git a/examples/osgunittests/UnitTestFramework.h b/examples/osgunittests/UnitTestFramework.h index fea19372a..71cce5eaf 100644 --- a/examples/osgunittests/UnitTestFramework.h +++ b/examples/osgunittests/UnitTestFramework.h @@ -27,10 +27,11 @@ #include #include +#include + #include #include #include -#include /** @@ -119,7 +120,7 @@ private: TraceLevel _traceLevel; std::ostream* _outputStreamPtr; - std::ofstream _nullStream; + osgDB::ofstream _nullStream; }; #endif /* DOXYGEN_SHOULD_SKIP_THIS */ diff --git a/examples/osgvolume/osgvolume.cpp b/examples/osgvolume/osgvolume.cpp index ab3f4aa56..e2cce1f53 100644 --- a/examples/osgvolume/osgvolume.cpp +++ b/examples/osgvolume/osgvolume.cpp @@ -1447,7 +1447,7 @@ struct WriteRowOperator osg::Image* readRaw(int sizeX, int sizeY, int sizeZ, int numberBytesPerComponent, int numberOfComponents, const std::string& endian, const std::string& raw_filename) { - std::ifstream fin(raw_filename.c_str(), std::ifstream::binary); + osgDB::ifstream fin(raw_filename.c_str(), std::ifstream::binary); if (!fin) return 0; GLenum pixelFormat; @@ -1711,7 +1711,7 @@ osg::TransferFunction1D* readTransferFunctionFile(const std::string& filename) std::cout<<"Reading transfer function "<> raw_filename >> transfer_filename >> xdim >> ydim >> zdim >> xSize >> ySize >> zSize; @@ -1977,7 +1977,7 @@ int main( int argc, char **argv ) if (!transfer_filename.empty()) { - std::ifstream fin(transfer_filename.c_str()); + osgDB::ifstream fin(transfer_filename.c_str()); if (fin) { osg::TransferFunction1D::ValueMap valueMap; diff --git a/include/osgDB/ConvertUTF b/include/osgDB/ConvertUTF new file mode 100644 index 000000000..bb6e5b6b4 --- /dev/null +++ b/include/osgDB/ConvertUTF @@ -0,0 +1,36 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 2008 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSGDB_CONVERTUTF +#define OSGDB_CONVERTUTF 1 + +#include +#include + +#include + +namespace osgDB +{ + +std::string OSGDB_EXPORT convertUTF16toUTF8(const wchar_t* source, unsigned sourceLength); +std::wstring OSGDB_EXPORT convertUTF8toUTF16(const char* source, unsigned sourceLength); + +inline std::string convertUTF16toUTF8(const std::wstring& s){return convertUTF16toUTF8(s.c_str(), s.length());} +inline std::string convertUTF16toUTF8(const wchar_t* s){return convertUTF16toUTF8(s, wcslen(s));} + +inline std::wstring convertUTF8toUTF16(const std::string& s){return convertUTF8toUTF16(s.c_str(), s.length());} +inline std::wstring convertUTF8toUTF16(const char* s){return convertUTF8toUTF16(s, strlen(s));} + +} + +#endif diff --git a/include/osgDB/FileUtils b/include/osgDB/FileUtils index cdbab8794..45a4c7e4c 100644 --- a/include/osgDB/FileUtils +++ b/include/osgDB/FileUtils @@ -20,6 +20,7 @@ #include #include +#include namespace osgDB { @@ -36,6 +37,10 @@ enum FileType DIRECTORY }; +// Overload of the standard fopen function. If OSG_USE_UTF8_FILENAME is defined, +// filename will be expanded from UTF8 to UTF16 and _wfopen will be called. +extern OSGDB_EXPORT FILE* fopen(const char* filename, const char* mode); + // Make a new directory. Returns true if directory exists or was created. extern OSGDB_EXPORT bool makeDirectory( const std::string &directoryPath ); diff --git a/include/osgDB/Output b/include/osgDB/Output index 55b4ecccf..9acc24637 100644 --- a/include/osgDB/Output +++ b/include/osgDB/Output @@ -17,16 +17,16 @@ #include #include +#include #include #include -#include namespace osgDB { /** ofstream wrapper class for adding support for indenting. Used in output of .osg ASCII files to improve their readability.*/ -class OSGDB_EXPORT Output : public std::ofstream +class OSGDB_EXPORT Output : public osgDB::ofstream { public: diff --git a/include/osgDB/fstream b/include/osgDB/fstream new file mode 100644 index 000000000..f25adb4dc --- /dev/null +++ b/include/osgDB/fstream @@ -0,0 +1,68 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSGDB_FSTREAM +#define OSGDB_FSTREAM 1 + +#include + +#include + +namespace osgDB +{ + +/** +* Replacements for std::fstream, 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); +}; + +class OSGDB_EXPORT ifstream : public std::ifstream +{ +public: + ifstream(); + explicit ifstream(const char* filename, + std::ios_base::openmode mode = std::ios_base::in); + ~ifstream(); + + void open(const char* filename, + std::ios_base::openmode mode = std::ios_base::in); +}; + +class OSGDB_EXPORT ofstream : public std::ofstream +{ +public: + ofstream(); + explicit ofstream(const char* filename, + std::ios_base::openmode mode = std::ios_base::out); + ~ofstream(); + + void open(const char* filename, + std::ios_base::openmode mode = std::ios_base::out); +}; + +} + +#endif diff --git a/include/osgViewer/ViewerEventHandlers b/include/osgViewer/ViewerEventHandlers index 606d65cec..06995cded 100644 --- a/include/osgViewer/ViewerEventHandlers +++ b/include/osgViewer/ViewerEventHandlers @@ -22,7 +22,7 @@ #include #include -#include +#include namespace osgViewer { @@ -252,7 +252,7 @@ protected: std::string _filename; int _autoinc; - std::ofstream _fout; + osgDB::ofstream _fout; int _keyEventToggleRecord; int _keyEventTogglePlayback; diff --git a/src/osg/Config.in b/src/osg/Config.in index 48cb92085..d8c13b134 100644 --- a/src/osg/Config.in +++ b/src/osg/Config.in @@ -28,5 +28,6 @@ #cmakedefine OSG_USE_FLOAT_BOUNDINGSPHERE #cmakedefine OSG_USE_FLOAT_BOUNDINGBOX #cmakedefine OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION +#cmakedefine OSG_USE_UTF8_FILENAME #endif diff --git a/src/osgDB/CMakeLists.txt b/src/osgDB/CMakeLists.txt index 431838c47..94bf2f42c 100644 --- a/src/osgDB/CMakeLists.txt +++ b/src/osgDB/CMakeLists.txt @@ -10,6 +10,7 @@ SET(HEADER_PATH ${OpenSceneGraph_SOURCE_DIR}/include/${LIB_NAME}) SET(LIB_PUBLIC_HEADERS ${HEADER_PATH}/Archive ${HEADER_PATH}/AuthenticationMap + ${HEADER_PATH}/ConvertUTF ${HEADER_PATH}/DatabasePager ${HEADER_PATH}/DotOsgWrapper ${HEADER_PATH}/DynamicLibrary @@ -20,6 +21,7 @@ SET(LIB_PUBLIC_HEADERS ${HEADER_PATH}/FileCache ${HEADER_PATH}/FileNameUtils ${HEADER_PATH}/FileUtils + ${HEADER_PATH}/fstream ${HEADER_PATH}/ImageOptions ${HEADER_PATH}/ImagePager ${HEADER_PATH}/Input @@ -41,6 +43,7 @@ ADD_LIBRARY(${LIB_NAME} ${LIB_PUBLIC_HEADERS} Archive.cpp AuthenticationMap.cpp + ConvertUTF.cpp DatabasePager.cpp DotOsgWrapper.cpp DynamicLibrary.cpp @@ -50,6 +53,7 @@ ADD_LIBRARY(${LIB_NAME} FileCache.cpp FileNameUtils.cpp FileUtils.cpp + fstream.cpp ImageOptions.cpp ImagePager.cpp Input.cpp diff --git a/src/osgDB/ConvertUTF.cpp b/src/osgDB/ConvertUTF.cpp new file mode 100644 index 000000000..db085ae57 --- /dev/null +++ b/src/osgDB/ConvertUTF.cpp @@ -0,0 +1,90 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 2008 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include +#include + +#if defined(WIN32) && !defined(__CYGWIN__) +#define WIN32_LEAN_AND_MEAN +#include +#endif + +namespace osgDB +{ + +std::string convertUTF16toUTF8(const wchar_t* source, unsigned sourceLength) +{ +#if defined(WIN32) && !defined(__CYGWIN__) + if (sourceLength == 0) + { + return std::string(); + } + + int destLen = WideCharToMultiByte(CP_UTF8, 0, source, sourceLength, 0, 0, 0, 0); + if (destLen <= 0) + { + osg::notify(osg::WARN) << "Cannot convert UTF-16 string to UTF-8." << std::endl; + return std::string(); + } + + std::string sDest(destLen, '\0'); + destLen = WideCharToMultiByte(CP_UTF8, 0, source, sourceLength, &sDest[0], destLen, 0, 0); + + if (destLen <= 0) + { + osg::notify(osg::WARN) << "Cannot convert UTF-16 string to UTF-8." << std::endl; + return std::string(); + } + + return sDest; +#else + //TODO: Implement for other platforms + osg::notify(osg::WARN) << "ConvertUTF16toUTF8 not implemented." << std::endl; + return std::string(); +#endif +} + +std::wstring convertUTF8toUTF16(const char* source, unsigned sourceLength) +{ +#if defined(WIN32) && !defined(__CYGWIN__) + if (sourceLength == 0) + { + return std::wstring(); + } + + int destLen = MultiByteToWideChar(CP_UTF8, 0, source, sourceLength, 0, 0); + if (destLen <= 0) + { + osg::notify(osg::WARN) << "Cannot convert UTF-8 string to UTF-16." << std::endl; + return std::wstring(); + } + + std::wstring sDest(destLen, L'\0'); + destLen = MultiByteToWideChar(CP_UTF8, 0, source, sourceLength, &sDest[0], destLen); + + if (destLen <= 0) + { + osg::notify(osg::WARN) << "Cannot convert UTF-8 string to UTF-16." << std::endl; + return std::wstring(); + } + + return sDest; +#else + //TODO: Implement for other platforms + osg::notify(osg::WARN) << "ConvertUTF8toUTF16 not implemented." << std::endl; + return std::wstring(); +#endif +} + +} + diff --git a/src/osgDB/FileUtils.cpp b/src/osgDB/FileUtils.cpp index 3a1ca1b56..994e9de64 100644 --- a/src/osgDB/FileUtils.cpp +++ b/src/osgDB/FileUtils.cpp @@ -11,7 +11,7 @@ * OpenSceneGraph Public License for more details. */ -// currently this impl is for _all_ platforms, execpt as defined. +// currently this impl is for _all_ platforms, except as defined. // the mac version will change soon to reflect the path scheme under osx, but // for now, the above include is commented out, and the below code takes precedence. @@ -64,6 +64,8 @@ # define S_ISDIR(mode) (mode&__S_IFDIR) #endif +#include +#include #include #include @@ -73,7 +75,33 @@ #include #include +namespace osgDB +{ +#ifdef OSG_USE_UTF8_FILENAME +#define OSGDB_STRING_TO_FILENAME(s) osgDB::convertUTF8toUTF16(s) +#define OSGDB_FILENAME_TO_STRING(s) osgDB::convertUTF16toUTF8(s) +#define OSGDB_FILENAME_TEXT(x) L ## x +#define OSGDB_WINDOWS_FUNCT(x) x ## W +typedef wchar_t filenamechar; +typedef std::wstring filenamestring; +#else +#define OSGDB_STRING_TO_FILENAME(s) s +#define OSGDB_FILENAME_TO_STRING(s) s +#define OSGDB_FILENAME_TEXT(x) x +#define OSGDB_WINDOWS_FUNCT(x) x ## A +typedef char filenamechar; +typedef std::string filenamestring; +#endif +} +FILE* osgDB::fopen(const char* filename, const char* mode) +{ +#ifdef OSG_USE_UTF8_FILENAME + return ::_wfopen(convertUTF8toUTF16(filename).c_str(), convertUTF8toUTF16(mode).c_str()); +#else + return ::fopen(filename, mode); +#endif +} bool osgDB::makeDirectory( const std::string &path ) { @@ -84,7 +112,11 @@ bool osgDB::makeDirectory( const std::string &path ) } struct stat64 stbuf; +#ifdef OSG_USE_UTF8_FILENAME + if( _wstat64( OSGDB_STRING_TO_FILENAME(path).c_str(), &stbuf ) == 0 ) +#else if( stat64( path.c_str(), &stbuf ) == 0 ) +#endif { if( S_ISDIR(stbuf.st_mode)) return true; @@ -103,7 +135,11 @@ bool osgDB::makeDirectory( const std::string &path ) if( dir.empty() ) break; +#ifdef OSG_USE_UTF8_FILENAME + if( _wstat64( OSGDB_STRING_TO_FILENAME(dir).c_str(), &stbuf ) < 0 ) +#else if( stat64( dir.c_str(), &stbuf ) < 0 ) +#endif { switch( errno ) { @@ -132,7 +168,11 @@ bool osgDB::makeDirectory( const std::string &path ) } #endif +#ifdef OSG_USE_UTF8_FILENAME + if ( _wmkdir(OSGDB_STRING_TO_FILENAME(dir).c_str())< 0 ) +#else if( mkdir( dir.c_str(), 0755 )< 0 ) +#endif { osg::notify(osg::DEBUG_INFO) << "osgDB::makeDirectory(): " << strerror(errno) << std::endl; return false; @@ -174,13 +214,21 @@ void osgDB::convertStringPathIntoFilePathList(const std::string& paths,FilePathL bool osgDB::fileExists(const std::string& filename) { +#ifdef OSG_USE_UTF8_FILENAME + return _waccess( OSGDB_STRING_TO_FILENAME(filename).c_str(), F_OK ) == 0; +#else return access( filename.c_str(), F_OK ) == 0; +#endif } osgDB::FileType osgDB::fileType(const std::string& filename) { struct stat64 fileStat; - if ( stat64(filename.c_str(), &fileStat) != 0 ) +#ifdef OSG_USE_UTF8_FILENAME + if ( _wstat64(OSGDB_STRING_TO_FILENAME(filename).c_str(), &fileStat) != 0 ) +#else + if ( stat64(filename.c_str(), &fileStat) != 0 ) +#endif { return FILE_NOT_FOUND; } // end if @@ -381,15 +429,15 @@ static void appendInstallationLibraryFilePaths(osgDB::FilePathList& filepath) { osgDB::DirectoryContents contents; - WIN32_FIND_DATA data; - HANDLE handle = FindFirstFile((dirName + "\\*").c_str(), &data); + OSGDB_WINDOWS_FUNCT(WIN32_FIND_DATA) data; + HANDLE handle = OSGDB_WINDOWS_FUNCT(FindFirstFile)((OSGDB_STRING_TO_FILENAME(dirName) + OSGDB_FILENAME_TEXT("\\*")).c_str(), &data); if (handle != INVALID_HANDLE_VALUE) { do { - contents.push_back(data.cFileName); + contents.push_back(OSGDB_FILENAME_TO_STRING(data.cFileName)); } - while (FindNextFile(handle, &data) != 0); + while (OSGDB_WINDOWS_FUNCT(FindNextFile)(handle, &data) != 0); FindClose(handle); } @@ -497,14 +545,14 @@ static void appendInstallationLibraryFilePaths(osgDB::FilePathList& filepath) // 1. The directory from which the application loaded. DWORD retval = 0; const DWORD size = MAX_PATH; - char path[size]; - retval = GetModuleFileName(NULL, path, size); + filenamechar path[size]; + retval = OSGDB_WINDOWS_FUNCT(GetModuleFileName)(NULL, path, size); if (retval != 0 && retval < size) { - std::string pathstr(path); - std::string executableDir(pathstr, 0, - pathstr.find_last_of("\\/")); - convertStringPathIntoFilePathList(executableDir, filepath); + filenamestring pathstr(path); + filenamestring executableDir(pathstr, 0, + pathstr.find_last_of(OSGDB_FILENAME_TEXT("\\/"))); + convertStringPathIntoFilePathList(OSGDB_FILENAME_TO_STRING(executableDir), filepath); } else { @@ -514,11 +562,12 @@ static void appendInstallationLibraryFilePaths(osgDB::FilePathList& filepath) // 2. The system directory. Use the GetSystemDirectory function to // get the path of this directory. - char systemDir[(UINT)size]; - retval = GetSystemDirectory(systemDir, (UINT)size); + filenamechar systemDir[(UINT)size]; + retval = OSGDB_WINDOWS_FUNCT(GetSystemDirectory)(systemDir, (UINT)size); + if (retval != 0 && retval < size) { - convertStringPathIntoFilePathList(std::string(systemDir), + convertStringPathIntoFilePathList(OSGDB_FILENAME_TO_STRING(systemDir), filepath); } else @@ -533,13 +582,13 @@ static void appendInstallationLibraryFilePaths(osgDB::FilePathList& filepath) // the path of this directory, but it is searched. // 4. The Windows directory. Use the GetWindowsDirectory function to // get the path of this directory. - char windowsDir[(UINT)size]; - retval = GetWindowsDirectory(windowsDir, (UINT)size); + filenamechar windowsDir[(UINT)size]; + retval = OSGDB_WINDOWS_FUNCT(GetWindowsDirectory)(windowsDir, (UINT)size); if (retval != 0 && retval < size) { - convertStringPathIntoFilePathList(std::string(windowsDir) + + convertStringPathIntoFilePathList(std::string(OSGDB_FILENAME_TO_STRING(windowsDir)) + "\\System", filepath); - convertStringPathIntoFilePathList(std::string(windowsDir), + convertStringPathIntoFilePathList(OSGDB_FILENAME_TO_STRING(windowsDir), filepath); } else @@ -557,14 +606,18 @@ static void appendInstallationLibraryFilePaths(osgDB::FilePathList& filepath) // 6. The directories that are listed in the PATH environment // variable. Note that this does not include the per-application // path specified by the App Paths registry key. - char* ptr; - if ((ptr = getenv( "PATH" ))) + filenamechar* ptr; +#ifdef OSG_USE_UTF8_FILENAME + if (ptr = _wgetenv(OSGDB_FILENAME_TEXT("PATH"))) +#else + if (ptr = getenv("PATH")) +#endif { // Note that on any sane Windows system, some of the paths above // will also be on the PATH (the values gotten in systemDir and // windowsDir), but the DLL search goes sequentially and stops // when a DLL is found, so I see no point in removing duplicates. - convertStringPathIntoFilePathList(ptr, filepath); + convertStringPathIntoFilePathList(OSGDB_FILENAME_TO_STRING(ptr), filepath); } appendInstallationLibraryFilePaths(filepath); diff --git a/src/osgDB/Output.cpp b/src/osgDB/Output.cpp index 426f8a01b..89f6cfa63 100644 --- a/src/osgDB/Output.cpp +++ b/src/osgDB/Output.cpp @@ -29,7 +29,7 @@ Output::Output() init(); } -Output::Output(const char* name) : ofstream(name) +Output::Output(const char* name) : osgDB::ofstream(name) { init(); _filename = name; @@ -70,7 +70,7 @@ void Output::setOptions(const ReaderWriter::Options* options) void Output::open(const char *name) { init(); - ofstream::open(name); + osgDB::ofstream::open(name); _filename = name; } diff --git a/src/osgDB/Registry.cpp b/src/osgDB/Registry.cpp index 680f59efe..c12fef902 100644 --- a/src/osgDB/Registry.cpp +++ b/src/osgDB/Registry.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -574,7 +575,7 @@ bool Registry::readPluginAliasConfigurationFile( const std::string& file ) return false; } - std::ifstream ifs; + osgDB::ifstream ifs; ifs.open( fileName.c_str() ); if (!ifs.good()) { diff --git a/src/osgDB/fstream.cpp b/src/osgDB/fstream.cpp new file mode 100644 index 000000000..4f7c84d75 --- /dev/null +++ b/src/osgDB/fstream.cpp @@ -0,0 +1,61 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include +#include + +#include + +namespace osgDB +{ + +#ifdef OSG_USE_UTF8_FILENAME +#define OSGDB_CONVERT_UTF8_FILENAME(s) convertUTF8toUTF16(s).c_str() +#else +#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) + { + std::fstream::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) + {} + ifstream::~ifstream(){} + void ifstream::open(const char* filename, + std::ios_base::openmode mode) + { + std::ifstream::open(OSGDB_CONVERT_UTF8_FILENAME(filename), mode); + } + + ofstream::ofstream(){} + ofstream::ofstream(const char* filename, + std::ios_base::openmode mode) : std::ofstream(OSGDB_CONVERT_UTF8_FILENAME(filename), mode) + {} + ofstream::~ofstream(){} + void ofstream::open(const char* filename, + std::ios_base::openmode mode) + { + std::ofstream::open(OSGDB_CONVERT_UTF8_FILENAME(filename), mode); + } + +} diff --git a/src/osgGA/AnimationPathManipulator.cpp b/src/osgGA/AnimationPathManipulator.cpp index 33d4f9675..7351354eb 100644 --- a/src/osgGA/AnimationPathManipulator.cpp +++ b/src/osgGA/AnimationPathManipulator.cpp @@ -1,6 +1,6 @@ #include -#include +#include using namespace osgGA; @@ -29,7 +29,7 @@ AnimationPathManipulator::AnimationPathManipulator( const std::string& filename _isPaused = false; - std::ifstream in(filename.c_str()); + osgDB::ifstream in(filename.c_str()); if (!in) { diff --git a/src/osgPlugins/3dc/ReaderWriter3DC.cpp b/src/osgPlugins/3dc/ReaderWriter3DC.cpp index 98e48faaa..f79a534ce 100644 --- a/src/osgPlugins/3dc/ReaderWriter3DC.cpp +++ b/src/osgPlugins/3dc/ReaderWriter3DC.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -37,7 +38,7 @@ class ReaderWriter3DC : public osgDB::ReaderWriter const int LINE_SIZE = 1024; char line[LINE_SIZE]; - std::ifstream fin(fileName.c_str()); + osgDB::ifstream fin(fileName.c_str()); unsigned int num = 0; while (fin) @@ -74,7 +75,7 @@ class ReaderWriter3DC : public osgDB::ReaderWriter fin.close(); - std::ifstream fin2(fileName.c_str()); + osgDB::ifstream fin2(fileName.c_str()); while (fin2) { fin2.getline(line,LINE_SIZE); diff --git a/src/osgPlugins/3ds/file.cpp b/src/osgPlugins/3ds/file.cpp index 7884e5e00..bd64f5af3 100644 --- a/src/osgPlugins/3ds/file.cpp +++ b/src/osgPlugins/3ds/file.cpp @@ -37,6 +37,8 @@ #include #endif +#include + /*! * \defgroup file Files @@ -68,7 +70,7 @@ lib3ds_file_load(const char *filename) FILE *f; Lib3dsFile *file; - f=fopen(filename, "rb"); + f=osgDB::fopen(filename, "rb"); if (!f) { return(0); } @@ -106,7 +108,7 @@ lib3ds_file_save(Lib3dsFile *file, const char *filename) { FILE *f; - f=fopen(filename, "wb"); + f=osgDB::fopen(filename, "wb"); if (!f) { return(LIB3DS_FALSE); } diff --git a/src/osgPlugins/OpenFlight/FltExportVisitor.cpp b/src/osgPlugins/OpenFlight/FltExportVisitor.cpp index 76ef12f3f..2db67d693 100644 --- a/src/osgPlugins/OpenFlight/FltExportVisitor.cpp +++ b/src/osgPlugins/OpenFlight/FltExportVisitor.cpp @@ -505,7 +505,7 @@ FltExportVisitor::complete( const osg::Node& node ) // Copy record data temp file into final OpenFlight file. // Yee-uck. TBD need better stream copy routine. char buf; - std::ifstream recIn; + osgDB::ifstream recIn; recIn.open( _recordsTempName.c_str(), std::ios::in | std::ios::binary ); while (!recIn.eof() ) { diff --git a/src/osgPlugins/OpenFlight/FltExportVisitor.h b/src/osgPlugins/OpenFlight/FltExportVisitor.h index e41d6aac9..853f25c3b 100644 --- a/src/osgPlugins/OpenFlight/FltExportVisitor.h +++ b/src/osgPlugins/OpenFlight/FltExportVisitor.h @@ -20,7 +20,7 @@ #include #include "ExportOptions.h" #include "Types.h" -#include +#include #include #include @@ -168,7 +168,7 @@ private: // _records is a temp file for most records. After the Header and palette // records are written to _dos, _records is copied onto _dos. - std::ofstream _recordsStr; + osgDB::ofstream _recordsStr; DataOutputStream* _records; std::string _recordsTempName; diff --git a/src/osgPlugins/OpenFlight/ReaderWriterATTR.cpp b/src/osgPlugins/OpenFlight/ReaderWriterATTR.cpp index 1b09a5d13..46ba43054 100644 --- a/src/osgPlugins/OpenFlight/ReaderWriterATTR.cpp +++ b/src/osgPlugins/OpenFlight/ReaderWriterATTR.cpp @@ -67,7 +67,7 @@ ReaderWriter::ReadResult ReaderWriterATTR::readObject(const std::string& file, c std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; - std::ifstream fin; + osgDB::ifstream fin; fin.imbue(std::locale::classic()); fin.open(fileName.c_str(), std::ios::in | std::ios::binary); @@ -209,7 +209,7 @@ ReaderWriterATTR::writeObject(const osg::Object& object, const std::string& file return WriteResult::FILE_NOT_HANDLED; } - std::ofstream fOut; + osgDB::ofstream fOut; fOut.open( fileName.c_str(), std::ios::out | std::ios::binary ); if ( fOut.fail()) diff --git a/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp b/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp index 0ee14b9fa..836b1a4c0 100644 --- a/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp +++ b/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp @@ -183,7 +183,7 @@ class FLTReaderWriter : public ReaderWriter // read file { - std::ifstream istream; + osgDB::ifstream istream; istream.imbue(std::locale::classic()); istream.open(fileName.c_str(), std::ios::in | std::ios::binary); @@ -441,7 +441,7 @@ class FLTReaderWriter : public ReaderWriter if (!filePath.empty()) _implicitPath = filePath; - std::ofstream fOut; + osgDB::ofstream fOut; fOut.open( fileName.c_str(), std::ios::out | std::ios::binary ); if ( fOut.fail()) { diff --git a/src/osgPlugins/OpenFlight/VertexPaletteManager.cpp b/src/osgPlugins/OpenFlight/VertexPaletteManager.cpp index 04b7a5de7..77fdada98 100644 --- a/src/osgPlugins/OpenFlight/VertexPaletteManager.cpp +++ b/src/osgPlugins/OpenFlight/VertexPaletteManager.cpp @@ -158,7 +158,7 @@ VertexPaletteManager::write( DataOutputStream& dos ) const // Open that temp file again, this time for reading. // Then copy to dos. char buf; - std::ifstream vertIn; + osgDB::ifstream vertIn; vertIn.open( _verticesTempName.c_str(), std::ios::in | std::ios::binary ); while (!vertIn.eof() ) { diff --git a/src/osgPlugins/OpenFlight/VertexPaletteManager.h b/src/osgPlugins/OpenFlight/VertexPaletteManager.h index eaaa8dc2e..aa4b0ffa4 100644 --- a/src/osgPlugins/OpenFlight/VertexPaletteManager.h +++ b/src/osgPlugins/OpenFlight/VertexPaletteManager.h @@ -21,7 +21,7 @@ #include "DataOutputStream.h" #include "ExportOptions.h" #include -#include +#include #include namespace osg { @@ -96,7 +96,7 @@ protected: typedef std::map< const osg::Array*, ArrayInfo > ArrayMap; ArrayMap _arrayMap; - mutable std::ofstream _verticesStr; + mutable osgDB::ofstream _verticesStr; DataOutputStream* _vertices; std::string _verticesTempName; diff --git a/src/osgPlugins/ac/ac3d.cpp b/src/osgPlugins/ac/ac3d.cpp index 28311f6d2..2b8c940b3 100644 --- a/src/osgPlugins/ac/ac3d.cpp +++ b/src/osgPlugins/ac/ac3d.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include "Exception.h" #include "Geode.h" @@ -89,7 +90,7 @@ class ReaderWriterAC : public osgDB::ReaderWriter if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; // allocate per file data and start reading - std::ifstream fin; + osgDB::ifstream fin; fin.open(fileName.c_str(), std::ios::in); if (!fin.is_open()) return ReadResult::FILE_NOT_FOUND; @@ -124,7 +125,7 @@ class ReaderWriterAC : public osgDB::ReaderWriter std::vectoriNumMaterials; const_cast(node).accept(vs); // this parses the tree to streamd Geodes std::vector glist=vs.getGeodes(); - std::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); + osgDB::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); // Write out the file header std::vector::iterator itr; fout << "AC3Db" << std::endl; diff --git a/src/osgPlugins/bmp/ReaderWriterBMP.cpp b/src/osgPlugins/bmp/ReaderWriterBMP.cpp index d1e360ab2..77906f35e 100644 --- a/src/osgPlugins/bmp/ReaderWriterBMP.cpp +++ b/src/osgPlugins/bmp/ReaderWriterBMP.cpp @@ -7,6 +7,7 @@ #include #include #include +#include typedef int int32; @@ -382,7 +383,7 @@ class ReaderWriterBMP : public osgDB::ReaderWriter std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; - std::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); + osgDB::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); if(!istream) return ReadResult::FILE_NOT_HANDLED; ReadResult rr = readBMPStream(istream); if(rr.validImage()) rr.getImage()->setFileName(file); @@ -492,7 +493,7 @@ class ReaderWriterBMP : public osgDB::ReaderWriter std::string ext = osgDB::getFileExtension(fileName); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; - std::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); + osgDB::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); if(!fout) return WriteResult::ERROR_IN_WRITING_FILE; bool success = WriteBMPStream(img, fout, fileName); diff --git a/src/osgPlugins/cfg/CameraConfig.cpp b/src/osgPlugins/cfg/CameraConfig.cpp index 58a54bc7b..9f8fb6c7e 100644 --- a/src/osgPlugins/cfg/CameraConfig.cpp +++ b/src/osgPlugins/cfg/CameraConfig.cpp @@ -15,6 +15,8 @@ #include #include +#include + #if defined(WIN32) && !defined(__CYGWIN__) #include #include @@ -573,11 +575,6 @@ void CameraConfig::scaleCameraOffset( osg::Matrix::value_type x, osg::Matrix::va memcpy( _offset_matrix, m.ptr(), sizeof( osg::Matrix::value_type[16] )); } -bool CameraConfig::fileExists(const std::string& filename) -{ - return access( filename.c_str(), F_OK ) == 0; -} - // Order of precedence: // std::string CameraConfig::findFile( std::string filename ) @@ -590,23 +587,23 @@ std::string CameraConfig::findFile( std::string filename ) if( ptr != NULL ) { path = std::string(ptr) + '/' + filename; - if( fileExists(path)) + if( osgDB::fileExists(path)) return path; } // Check standard location(s) //path.clear(); path = std::string( "/usr/local/share/Producer/Config/") + filename; - if( fileExists(path) ) + if( osgDB::fileExists(path) ) return path; //path.clear(); path = std::string( "/usr/share/Producer/Config/") + filename; - if( fileExists(path) ) + if( osgDB::fileExists(path) ) return path; // Check local directory - if(fileExists(filename)) + if(osgDB::fileExists(filename)) return filename; // Fail diff --git a/src/osgPlugins/cfg/CameraConfig.h b/src/osgPlugins/cfg/CameraConfig.h index 050847c0c..32223e915 100644 --- a/src/osgPlugins/cfg/CameraConfig.h +++ b/src/osgPlugins/cfg/CameraConfig.h @@ -231,8 +231,6 @@ class CameraConfig : public osg::Referenced unsigned int getNumberOfScreens(); - static bool fileExists(const std::string& ); - osg::Matrix::value_type _offset_matrix[16]; osg::Matrix::value_type _offset_shearx, _offset_sheary; diff --git a/src/osgPlugins/cfg/ConfigParser.cpp b/src/osgPlugins/cfg/ConfigParser.cpp index c8ca21a13..a7ccc1120 100644 --- a/src/osgPlugins/cfg/ConfigParser.cpp +++ b/src/osgPlugins/cfg/ConfigParser.cpp @@ -221,9 +221,10 @@ #define SUPPORT_CPP 1 #endif +#include + #include #include -#include #include #include "FlexLexer.h" @@ -2283,7 +2284,7 @@ bool CameraConfig::parseFile( const std::string &file ) else #endif { - std::ifstream ifs(fileName.c_str()); + osgDB::ifstream ifs(fileName.c_str()); flexer = new yyFlexLexer(&ifs); cfg = this; retval = ConfigParser_parse() == 0 ? true : false; diff --git a/src/osgPlugins/dds/ReaderWriterDDS.cpp b/src/osgPlugins/dds/ReaderWriterDDS.cpp index 29ac4b29d..117c60923 100644 --- a/src/osgPlugins/dds/ReaderWriterDDS.cpp +++ b/src/osgPlugins/dds/ReaderWriterDDS.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -954,7 +955,7 @@ public: if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; - std::ifstream stream(fileName.c_str(), std::ios::in | std::ios::binary); + osgDB::ifstream stream(fileName.c_str(), std::ios::in | std::ios::binary); if(!stream) return ReadResult::FILE_NOT_HANDLED; ReadResult rr = readImage(stream, options); if(rr.validImage()) rr.getImage()->setFileName(file); @@ -996,7 +997,7 @@ public: std::string ext = osgDB::getFileExtension(file); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; - std::ofstream fout(file.c_str(), std::ios::out | std::ios::binary); + osgDB::ofstream fout(file.c_str(), std::ios::out | std::ios::binary); if(!fout) return WriteResult::ERROR_IN_WRITING_FILE; return writeImage(image,fout,options); diff --git a/src/osgPlugins/dw/ReaderWriterDW.cpp b/src/osgPlugins/dw/ReaderWriterDW.cpp index 63b4bf49b..4a1000aee 100644 --- a/src/osgPlugins/dw/ReaderWriterDW.cpp +++ b/src/osgPlugins/dw/ReaderWriterDW.cpp @@ -828,7 +828,7 @@ class ReaderWriterDW : public osgDB::ReaderWriter FILE *fp; - if( (fp = fopen( fileName.c_str(), "r" )) == (FILE *)0L ) + if( (fp = osgDB::fopen( fileName.c_str(), "r" )) == (FILE *)0L ) { return std::string("Unable to open file \""+fileName+"\""); } diff --git a/src/osgPlugins/dxf/dxfReader.h b/src/osgPlugins/dxf/dxfReader.h index e3dd5bbfc..f8e3a300f 100644 --- a/src/osgPlugins/dxf/dxfReader.h +++ b/src/osgPlugins/dxf/dxfReader.h @@ -17,13 +17,14 @@ #ifndef DXF_READER #define DXF_READER 1 -#include #include #include #include #include +#include + class codeValue; /// readerBase. abstract base class for reading a dxf file @@ -86,7 +87,7 @@ protected: }; /// dxfReader. gets you through the dxf file, one group code/value pair at a time. -/// just instanciate, openFile(), then loop while(nextGroupCode()) +/// just instantiate, openFile(), then loop while(nextGroupCode()) class dxfReader : public osg::Referenced { public: @@ -95,7 +96,7 @@ public: bool openFile(std::string fileName); bool nextGroupCode(codeValue& cv); protected: - std::ifstream _ifs; + osgDB::ifstream _ifs; osg::ref_ptr _reader; }; diff --git a/src/osgPlugins/geo/ReaderWriterGEO.cpp b/src/osgPlugins/geo/ReaderWriterGEO.cpp index 76140d5bf..8a8bbbe5e 100644 --- a/src/osgPlugins/geo/ReaderWriterGEO.cpp +++ b/src/osgPlugins/geo/ReaderWriterGEO.cpp @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -397,7 +398,7 @@ class ReaderGEO osgDB::ReaderWriter::ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) { - std::ifstream fin(fileName.c_str(), std::ios::binary | std::ios::in ); + osgDB::ifstream fin(fileName.c_str(), std::ios::binary | std::ios::in ); if (fin.is_open() ) { // read the input file. // code for setting up the database path so that internally referenced file are searched for on relative paths. diff --git a/src/osgPlugins/glsl/ReaderWriterGLSL.cpp b/src/osgPlugins/glsl/ReaderWriterGLSL.cpp index 359ae85b7..61fcafbaa 100644 --- a/src/osgPlugins/glsl/ReaderWriterGLSL.cpp +++ b/src/osgPlugins/glsl/ReaderWriterGLSL.cpp @@ -5,6 +5,7 @@ #include #include #include +#include class ReaderWriterGLSL : public osgDB::ReaderWriter @@ -58,7 +59,7 @@ class ReaderWriterGLSL : public osgDB::ReaderWriter std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; - std::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); + osgDB::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); if(!istream) return ReadResult::FILE_NOT_HANDLED; ReadResult rr = readShader(istream, options); if(rr.validShader()) rr.getShader()->setFileName(file); @@ -82,7 +83,7 @@ class ReaderWriterGLSL : public osgDB::ReaderWriter std::string ext = osgDB::getFileExtension(fileName); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; - std::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); + osgDB::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); if(!fout) return WriteResult::ERROR_IN_WRITING_FILE; return writeShader(shader, fout); diff --git a/src/osgPlugins/hdr/ReaderWriterHDR.cpp b/src/osgPlugins/hdr/ReaderWriterHDR.cpp index 98d5698bd..6e1dd98e1 100644 --- a/src/osgPlugins/hdr/ReaderWriterHDR.cpp +++ b/src/osgPlugins/hdr/ReaderWriterHDR.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -189,7 +190,7 @@ public: std::string ext = osgDB::getFileExtension(file); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; - std::ofstream fout(file.c_str(), std::ios::out | std::ios::binary); + osgDB::ofstream fout(file.c_str(), std::ios::out | std::ios::binary); if(!fout) return WriteResult::ERROR_IN_WRITING_FILE; return writeImage(image,fout,options); diff --git a/src/osgPlugins/hdr/hdrloader.cpp b/src/osgPlugins/hdr/hdrloader.cpp index c02875576..7f2d72a02 100644 --- a/src/osgPlugins/hdr/hdrloader.cpp +++ b/src/osgPlugins/hdr/hdrloader.cpp @@ -32,6 +32,8 @@ #include #include +#include + typedef unsigned char RGBE[4]; #define R 0 #define G 1 @@ -49,7 +51,7 @@ static bool oldDecrunch(RGBE *scanline, int len, FILE *file); bool HDRLoader::isHDRFile(const char *_fileName) { FILE *file; - file = fopen(_fileName, "rb"); + file = osgDB::fopen(_fileName, "rb"); if (!file) return false; @@ -69,7 +71,7 @@ bool HDRLoader::load(const char *_fileName, const bool _rawRGBE, HDRLoaderResult char str[200]; FILE *file; - file = fopen(_fileName, "rb"); + file = osgDB::fopen(_fileName, "rb"); if (!file) return false; diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index 3bbeed492..d0e4348e1 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -112,8 +112,8 @@ #include #include #include +#include -#include #include using namespace ive; @@ -1424,7 +1424,7 @@ void DataOutputStream::writeImage(IncludeImageMode mode, osg::Image *image) // Include image file in stream if(image && !(image->getFileName().empty())) { std::string fullPath = osgDB::findDataFile(image->getFileName(),_options.get()); - std::ifstream infile(fullPath.c_str(), std::ios::in | std::ios::binary); + osgDB::ifstream infile(fullPath.c_str(), std::ios::in | std::ios::binary); if(infile) { //Write filename diff --git a/src/osgPlugins/ive/ReaderWriterIVE.cpp b/src/osgPlugins/ive/ReaderWriterIVE.cpp index 2f619bb16..33fe37951 100644 --- a/src/osgPlugins/ive/ReaderWriterIVE.cpp +++ b/src/osgPlugins/ive/ReaderWriterIVE.cpp @@ -5,6 +5,7 @@ #include #include +#include #include using namespace osg; @@ -51,7 +52,7 @@ class ReaderWriterIVE : public ReaderWriter osg::ref_ptr local_opt = options ? static_cast(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName)); - std::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); + osgDB::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); return readImage(istream, local_opt.get()); } @@ -67,7 +68,7 @@ class ReaderWriterIVE : public ReaderWriter osg::ref_ptr local_opt = options ? static_cast(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName)); - std::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); + osgDB::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); return readNode(istream,local_opt.get()); } @@ -121,7 +122,7 @@ class ReaderWriterIVE : public ReaderWriter osg::ref_ptr local_opt = options ? static_cast(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; if(local_opt->getDatabasePathList().empty()) local_opt->setDatabasePath(osgDB::getFilePath(fileName)); - std::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); + osgDB::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); if (!fout) return WriteResult::ERROR_IN_WRITING_FILE; WriteResult result = writeImage(image, fout, local_opt.get()); fout.close(); @@ -138,7 +139,7 @@ class ReaderWriterIVE : public ReaderWriter if(local_opt->getDatabasePathList().empty()) local_opt->setDatabasePath(osgDB::getFilePath(fileName)); - std::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); + osgDB::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); if (!fout) return WriteResult::ERROR_IN_WRITING_FILE; WriteResult result = writeNode(node, fout, local_opt.get()); diff --git a/src/osgPlugins/logo/ReaderWriterLOGO.cpp b/src/osgPlugins/logo/ReaderWriterLOGO.cpp index c894ebbf7..036f2fb2c 100644 --- a/src/osgPlugins/logo/ReaderWriterLOGO.cpp +++ b/src/osgPlugins/logo/ReaderWriterLOGO.cpp @@ -230,7 +230,7 @@ class LOGOReaderWriter : public osgDB::ReaderWriter Logos::RelativePosition pos = Logos::LowerRight; FILE *fp; - if( (fp = fopen( fileName.c_str(), "r")) == NULL ) + if( (fp = osgDB::fopen( fileName.c_str(), "r")) == NULL ) return NULL; while( !feof(fp)) { diff --git a/src/osgPlugins/lwo/Converter.cpp b/src/osgPlugins/lwo/Converter.cpp index 51b3365cf..a4c32a7cc 100644 --- a/src/osgPlugins/lwo/Converter.cpp +++ b/src/osgPlugins/lwo/Converter.cpp @@ -15,11 +15,10 @@ #include #include +#include #include "lwo2parser.h" -#include - using namespace lwosg; namespace @@ -268,7 +267,7 @@ osg::Group *Converter::convert(const std::string &filename) std::string file = osgDB::findDataFile(filename, db_options_.get()); if (file.empty()) return 0; - std::ifstream ifs(file.c_str(), std::ios_base::in | std::ios_base::binary); + osgDB::ifstream ifs(file.c_str(), std::ios_base::in | std::ios_base::binary); if (!ifs.is_open()) return 0; std::vector buffer; diff --git a/src/osgPlugins/lwo/old_Lwo2.h b/src/osgPlugins/lwo/old_Lwo2.h index 63f9f49d2..abeaddba8 100644 --- a/src/osgPlugins/lwo/old_Lwo2.h +++ b/src/osgPlugins/lwo/old_Lwo2.h @@ -29,7 +29,6 @@ #include #include #include -#include #include #include @@ -38,6 +37,8 @@ #include #include +#include + using namespace osg; using namespace std; @@ -64,7 +65,7 @@ class Lwo2 Lwo2Layer* _current_layer; vector< string > _tags; vector< string > _images; - ifstream _fin; + osgDB::ifstream _fin; unsigned char _read_char(); unsigned short _read_short(); diff --git a/src/osgPlugins/lwo/old_lw.cpp b/src/osgPlugins/lwo/old_lw.cpp index 8642c8593..407c5a648 100644 --- a/src/osgPlugins/lwo/old_lw.cpp +++ b/src/osgPlugins/lwo/old_lw.cpp @@ -22,6 +22,8 @@ #include #include +#include + #define MK_ID(a,b,c,d) ((((guint32)(a))<<24)| \ (((guint32)(b))<<16)| \ (((guint32)(c))<< 8)| \ @@ -326,7 +328,7 @@ static void read_pnts(FILE *f, gint nbytes, lwObject *lwo) gint lw_is_lwobject(const char *lw_file) { - FILE *f = fopen(lw_file, "rb"); + FILE *f = osgDB::fopen(lw_file, "rb"); if (f) { gint32 form = read_long(f); gint32 nlen = read_long(f); @@ -348,7 +350,7 @@ lwObject *lw_object_read(const char *lw_file, std::ostream& output) gint32 read_bytes = 0; /* open file */ - f = fopen(lw_file, "rb"); + f = osgDB::fopen(lw_file, "rb"); if (f == NULL) { output << "can't open file "< #include +#include #include #include -#include #include using namespace lwosg; @@ -92,7 +92,7 @@ osg::Group *SceneLoader::load(const std::string &filename, const osgDB::ReaderWr fname = filename; } - std::ifstream ifs(fname.c_str()); + osgDB::ifstream ifs(fname.c_str()); if (!ifs.is_open()) return 0; clear(); diff --git a/src/osgPlugins/obj/ReaderWriterOBJ.cpp b/src/osgPlugins/obj/ReaderWriterOBJ.cpp index 3052c5858..b1cacff65 100644 --- a/src/osgPlugins/obj/ReaderWriterOBJ.cpp +++ b/src/osgPlugins/obj/ReaderWriterOBJ.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -80,14 +81,14 @@ public: if (!acceptsExtension(osgDB::getFileExtension(fileName))) return WriteResult(WriteResult::FILE_NOT_HANDLED); - std::ofstream f(fileName.c_str()); + osgDB::ofstream f(fileName.c_str()); std::string materialFile = osgDB::getNameLessExtension(fileName) + ".mtl"; OBJWriterNodeVisitor nv(f, osgDB::getSimpleFileName(materialFile)); // we must cast away constness (const_cast(&node))->accept(nv); - std::ofstream mf(materialFile.c_str()); + osgDB::ofstream mf(materialFile.c_str()); nv.writeMaterials(mf); return WriteResult(WriteResult::FILE_SAVED); @@ -668,7 +669,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& fil if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; - std::ifstream fin(fileName.c_str()); + osgDB::ifstream fin(fileName.c_str()); if (fin) { diff --git a/src/osgPlugins/obj/obj.cpp b/src/osgPlugins/obj/obj.cpp index a3f7ec2bc..dcbc4d146 100644 --- a/src/osgPlugins/obj/obj.cpp +++ b/src/osgPlugins/obj/obj.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -23,6 +22,7 @@ #include #include +#include using namespace obj; @@ -597,7 +597,7 @@ bool Model::readOBJ(std::istream& fin, const osgDB::ReaderWriter::Options* optio osg::notify(osg::INFO) << "--" << fullPathFileName << "--" << std::endl; if (!fullPathFileName.empty()) { - std::ifstream mfin( fullPathFileName.c_str() ); + osgDB::ifstream mfin( fullPathFileName.c_str() ); if (mfin) { readMTL(mfin); diff --git a/src/osgPlugins/osg/FragmentProgram.cpp b/src/osgPlugins/osg/FragmentProgram.cpp index 472e98a67..280ebac7f 100644 --- a/src/osgPlugins/osg/FragmentProgram.cpp +++ b/src/osgPlugins/osg/FragmentProgram.cpp @@ -6,6 +6,7 @@ #include "osgDB/Registry" #include "osgDB/Input" #include "osgDB/Output" +#include "osgDB/fstream" #include "Matrix.h" @@ -83,7 +84,7 @@ bool FragmentProgram_readLocalData(Object& obj, Input& fr) fr += 2; iteratorAdvanced = true; - ifstream vfstream( filename.c_str() ); + osgDB::ifstream vfstream( filename.c_str() ); if( vfstream ) { ostringstream vstream; diff --git a/src/osgPlugins/osg/ReaderWriterOSG.cpp b/src/osgPlugins/osg/ReaderWriterOSG.cpp index 29451a265..469b8042f 100644 --- a/src/osgPlugins/osg/ReaderWriterOSG.cpp +++ b/src/osgPlugins/osg/ReaderWriterOSG.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -47,7 +48,7 @@ class OSGReaderWriter : public ReaderWriter osg::ref_ptr local_opt = opt ? static_cast(opt->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName)); - std::ifstream fin(fileName.c_str()); + osgDB::ifstream fin(fileName.c_str()); if (fin) { return readObject(fin, local_opt.get()); @@ -108,7 +109,7 @@ class OSGReaderWriter : public ReaderWriter osg::ref_ptr local_opt = opt ? static_cast(opt->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName)); - std::ifstream fin(fileName.c_str()); + osgDB::ifstream fin(fileName.c_str()); if (fin) { return readNode(fin, local_opt.get()); diff --git a/src/osgPlugins/osg/VertexProgram.cpp b/src/osgPlugins/osg/VertexProgram.cpp index 4e399ab8d..bdfbd3e7e 100644 --- a/src/osgPlugins/osg/VertexProgram.cpp +++ b/src/osgPlugins/osg/VertexProgram.cpp @@ -6,6 +6,7 @@ #include "osgDB/Registry" #include "osgDB/Input" #include "osgDB/Output" +#include "osgDB/fstream" #include "Matrix.h" @@ -85,7 +86,7 @@ bool VertexProgram_readLocalData(Object& obj, Input& fr) fr+=2; iteratorAdvanced = true; - ifstream vfstream( filename.c_str() ); + osgDB::ifstream vfstream( filename.c_str() ); if( vfstream ) { diff --git a/src/osgPlugins/osgTerrain/ReaderWriterOsgTerrain.cpp b/src/osgPlugins/osgTerrain/ReaderWriterOsgTerrain.cpp index d6d98fa19..563b7fcf9 100644 --- a/src/osgPlugins/osgTerrain/ReaderWriterOsgTerrain.cpp +++ b/src/osgPlugins/osgTerrain/ReaderWriterOsgTerrain.cpp @@ -57,7 +57,7 @@ class ReaderWriterTerrain : public osgDB::ReaderWriter osg::ref_ptr local_opt = opt ? static_cast(opt->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; local_opt->setDatabasePath(osgDB::getFilePath(fileName)); - std::ifstream fin(fileName.c_str()); + osgDB::ifstream fin(fileName.c_str()); if (fin) { return readNode(fin, local_opt.get()); diff --git a/src/osgPlugins/osgViewer/ReaderWriterOsgViewer.cpp b/src/osgPlugins/osgViewer/ReaderWriterOsgViewer.cpp index 1f90a38dd..1934ff2b6 100644 --- a/src/osgPlugins/osgViewer/ReaderWriterOsgViewer.cpp +++ b/src/osgPlugins/osgViewer/ReaderWriterOsgViewer.cpp @@ -66,7 +66,7 @@ public: if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; // code for setting up the database path so that internally referenced file are searched for on relative paths. - std::ifstream fin(fileName.c_str()); + osgDB::ifstream fin(fileName.c_str()); if (fin) { return readObject(fin, options); diff --git a/src/osgPlugins/osga/OSGA_Archive.h b/src/osgPlugins/osga/OSGA_Archive.h index 30e5dc31b..04aa0aa3c 100644 --- a/src/osgPlugins/osga/OSGA_Archive.h +++ b/src/osgPlugins/osga/OSGA_Archive.h @@ -95,7 +95,7 @@ class OSGA_Archive : public osgDB::Archive mutable OpenThreads::ReentrantMutex _serializerMutex; - class IndexBlock; + class IndexBlock; friend class IndexBlock; class IndexBlock : public osg::Referenced @@ -177,7 +177,7 @@ class OSGA_Archive : public osgDB::Archive const osgDB::ReaderWriter::Options* _options; }; - protected: + protected: struct ReadObjectFunctor; struct ReadImageFunctor; struct ReadHeightFieldFunctor; @@ -204,8 +204,8 @@ class OSGA_Archive : public osgDB::Archive static float s_currentSupportedVersion; float _version; ArchiveStatus _status; - std::ifstream _input; - std::fstream _output; + osgDB::ifstream _input; + osgDB::fstream _output; std::string _masterFileName; IndexBlockList _indexBlockList; diff --git a/src/osgPlugins/pic/ReaderWriterPIC.cpp b/src/osgPlugins/pic/ReaderWriterPIC.cpp index 81c5aa913..69f5c5f87 100644 --- a/src/osgPlugins/pic/ReaderWriterPIC.cpp +++ b/src/osgPlugins/pic/ReaderWriterPIC.cpp @@ -108,7 +108,7 @@ int *numComponents_ret) unsigned char palette[256][3]; unsigned char * tmpbuf, * buffer, * ptr; - FILE *fp = fopen(filename, "rb"); + FILE *fp = osgDB::fopen(filename, "rb"); if (!fp) return NULL; picerror = ERROR_NO_ERROR; diff --git a/src/osgPlugins/pnm/ReaderWriterPNM.cpp b/src/osgPlugins/pnm/ReaderWriterPNM.cpp index c7a51876c..6d9bca20d 100644 --- a/src/osgPlugins/pnm/ReaderWriterPNM.cpp +++ b/src/osgPlugins/pnm/ReaderWriterPNM.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -273,7 +274,7 @@ class ReaderWriterPNM : public osgDB::ReaderWriter int max_value = 0; // Open file. - fp = fopen(fileName.c_str(), "rb"); + fp = osgDB::fopen(fileName.c_str(), "rb"); // Read header items. int row; @@ -476,7 +477,7 @@ class ReaderWriterPNM : public osgDB::ReaderWriter // only support rgb images right now. if (image.getPixelFormat()!=GL_RGB || image.getDataType()!=GL_UNSIGNED_BYTE) return WriteResult("Error image pixel format not supported by pnm writer."); - std::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); + osgDB::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); if(!fout) return WriteResult::ERROR_IN_WRITING_FILE; return writeImage(image,fout,options); diff --git a/src/osgPlugins/rgb/ReaderWriterRGB.cpp b/src/osgPlugins/rgb/ReaderWriterRGB.cpp index 2b74af806..620269aa1 100644 --- a/src/osgPlugins/rgb/ReaderWriterRGB.cpp +++ b/src/osgPlugins/rgb/ReaderWriterRGB.cpp @@ -523,7 +523,7 @@ class ReaderWriterRGB : public osgDB::ReaderWriter std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; - std::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); + osgDB::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); if(!istream) return ReadResult::FILE_NOT_HANDLED; ReadResult rr = readRGBStream(istream); if(rr.validImage()) rr.getImage()->setFileName(file); @@ -655,7 +655,7 @@ class ReaderWriterRGB : public osgDB::ReaderWriter std::string ext = osgDB::getFileExtension(fileName); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; - std::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); + osgDB::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); if(!fout) return WriteResult::ERROR_IN_WRITING_FILE; return writeRGBStream(img,fout,fileName); diff --git a/src/osgPlugins/shp/ESRIShapeReaderWriter.cpp b/src/osgPlugins/shp/ESRIShapeReaderWriter.cpp index fee600d60..7c09dd2d9 100644 --- a/src/osgPlugins/shp/ESRIShapeReaderWriter.cpp +++ b/src/osgPlugins/shp/ESRIShapeReaderWriter.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -80,7 +81,7 @@ class ESRIShapeReaderWriter : public osgDB::ReaderWriter std::string projFileName(osgDB::getNameLessExtension(fileName) + ".prj"); if (osgDB::fileExists(projFileName)) { - std::ifstream fin(projFileName.c_str()); + osgDB::ifstream fin(projFileName.c_str()); if (fin) { std::string projstring; diff --git a/src/osgPlugins/stl/ReaderWriterSTL.cpp b/src/osgPlugins/stl/ReaderWriterSTL.cpp index efc0b886d..7c3ffed36 100644 --- a/src/osgPlugins/stl/ReaderWriterSTL.cpp +++ b/src/osgPlugins/stl/ReaderWriterSTL.cpp @@ -119,7 +119,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& fil osg::notify(osg::INFO) << "ReaderWriterSTL::readNode(" << fileName.c_str() << ")\n"; // determine ASCII vs. binary mode - FILE* fp = fopen(fileName.c_str(), "rb"); + FILE* fp = osgDB::fopen(fileName.c_str(), "rb"); if (!fp) { return ReadResult::FILE_NOT_FOUND; } @@ -169,7 +169,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& fil if (!isBinary) { fclose(fp); - fp = fopen(fileName.c_str(), "r"); + fp = osgDB::fopen(fileName.c_str(), "r"); } // read diff --git a/src/osgPlugins/tga/ReaderWriterTGA.cpp b/src/osgPlugins/tga/ReaderWriterTGA.cpp index 938d554fa..e3e09bb05 100644 --- a/src/osgPlugins/tga/ReaderWriterTGA.cpp +++ b/src/osgPlugins/tga/ReaderWriterTGA.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -535,7 +536,7 @@ class ReaderWriterTGA : public osgDB::ReaderWriter std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; - std::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); + osgDB::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); if(!istream) return ReadResult::FILE_NOT_HANDLED; ReadResult rr = readTGAStream(istream); if(rr.validImage()) rr.getImage()->setFileName(file); diff --git a/src/osgPlugins/txf/ReaderWriterTXF.cpp b/src/osgPlugins/txf/ReaderWriterTXF.cpp index 1ba5a5f1e..0828743ae 100644 --- a/src/osgPlugins/txf/ReaderWriterTXF.cpp +++ b/src/osgPlugins/txf/ReaderWriterTXF.cpp @@ -11,10 +11,9 @@ * OpenSceneGraph Public License for more details. */ -#include - #include #include +#include #include #include @@ -38,7 +37,7 @@ class ReaderWriterTXF : public osgDB::ReaderWriter std::string fileName = osgDB::findDataFile(file, options); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; - std::ifstream stream; + osgDB::ifstream stream; stream.open(fileName.c_str(), std::ios::in | std::ios::binary); if (!stream.is_open()) return ReadResult::FILE_NOT_FOUND; diff --git a/src/osgPlugins/txp/TXPArchive.cpp b/src/osgPlugins/txp/TXPArchive.cpp index 6c030af1b..63b504a44 100644 --- a/src/osgPlugins/txp/TXPArchive.cpp +++ b/src/osgPlugins/txp/TXPArchive.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -23,7 +24,6 @@ #include #include #include -#include #if defined(linux) # include @@ -599,7 +599,7 @@ bool TXPArchive::loadTextStyles() std::map< std::string, std::string > fontmap; std::string fmapfname = std::string(getDir())+"\\fontmap.txt"; - std::ifstream fmapfile; + osgDB::ifstream fmapfile; fmapfile.open(fmapfname.c_str(),std::ios::in); if (fmapfile.is_open()) diff --git a/src/osgPlugins/txp/trpage_print.cpp b/src/osgPlugins/txp/trpage_print.cpp index 07fe6471c..2b3e776b5 100644 --- a/src/osgPlugins/txp/trpage_print.cpp +++ b/src/osgPlugins/txp/trpage_print.cpp @@ -13,6 +13,8 @@ ************************ */ +#include + #include #include #include @@ -75,7 +77,7 @@ trpgFilePrintBuffer::trpgFilePrintBuffer(FILE *inFp) trpgFilePrintBuffer::trpgFilePrintBuffer(char *file) { isMine = true; - fp = fopen(file,"w"); + fp = osgDB::fopen(file,"w"); valid = fp != NULL; } diff --git a/src/osgPlugins/txp/trpage_rarchive.cpp b/src/osgPlugins/txp/trpage_rarchive.cpp index b607e5749..96856267c 100644 --- a/src/osgPlugins/txp/trpage_rarchive.cpp +++ b/src/osgPlugins/txp/trpage_rarchive.cpp @@ -13,6 +13,8 @@ ************************ */ +#include + #include #include #include @@ -64,7 +66,7 @@ bool trpgr_Archive::OpenFile(const char *name) CloseFile(); - if (!(fp = fopen(file,"rb"))) + if (!(fp = osgDB::fopen(file,"rb"))) return false; // Look for a magic # and endianness @@ -138,7 +140,7 @@ bool trpgr_Archive::ReadSubArchive(int row, int col, trpgEndian cpuNess) //open the block archive // the block archive will be in the base dir + \\cols\\row\\archive.txp sprintf(blockpath,"%s%s%d%s%d%sarchive.txp",dir,PATHSEPERATOR,col,PATHSEPERATOR,row,PATHSEPERATOR); - FILE *bfp = fopen(blockpath,"rb"); + FILE *bfp = osgDB::fopen(blockpath,"rb"); if(!bfp) { return false; } @@ -383,7 +385,7 @@ bool trpgr_Archive::ReadExternalTile(uint32 x,uint32 y,uint32 lod,trpgMemReadBuf // Open the file and read the contents FILE *fp= 0; try { - if (!(fp = fopen(filename,"rb"))) { + if (!(fp = osgDB::fopen(filename,"rb"))) { throw 1; } diff --git a/src/osgPlugins/txp/trpage_readbuf.cpp b/src/osgPlugins/txp/trpage_readbuf.cpp index 2a41e9677..97ec85269 100644 --- a/src/osgPlugins/txp/trpage_readbuf.cpp +++ b/src/osgPlugins/txp/trpage_readbuf.cpp @@ -12,6 +12,9 @@ Tel: (520) 323-7990 ************************ */ + +#include + #include #include #include @@ -465,7 +468,7 @@ void trpgrAppFile::Init(trpgEndian inNess,const char *fileName) ness = inNess; cpuNess = trpg_cpu_byte_order(); - if (!(fp = fopen(fileName,"rb"))) + if (!(fp = osgDB::fopen(fileName,"rb"))) return; valid = true; diff --git a/src/osgPlugins/txp/trpage_warchive.cpp b/src/osgPlugins/txp/trpage_warchive.cpp index 8bf1aed15..9c0016d35 100644 --- a/src/osgPlugins/txp/trpage_warchive.cpp +++ b/src/osgPlugins/txp/trpage_warchive.cpp @@ -13,6 +13,8 @@ ************************ */ +#include + #include #include #include @@ -410,7 +412,7 @@ bool trpgwArchive::OpenFile(const char *in_dir,const char *name) sprintf(filename,"%s" PATHSEPERATOR "%s",dir,name); - if (!(fp = fopen(filename,"wb"))) + if (!(fp = osgDB::fopen(filename,"wb"))) return false; return true; @@ -831,7 +833,7 @@ bool trpgwArchive::WriteTile(unsigned int x,unsigned int y,unsigned int lod, flo char filename[1024]; // Note: Windows specific sprintf(filename,"%s" PATHSEPERATOR "tile_%d_%d_%d.tpt",dir,x,y,lod); - if (!(tfp = fopen(filename,"wb"))) + if (!(tfp = osgDB::fopen(filename,"wb"))) return false; // Write the header first diff --git a/src/osgPlugins/txp/trpage_writebuf.cpp b/src/osgPlugins/txp/trpage_writebuf.cpp index 194e890fb..33f5dbeda 100644 --- a/src/osgPlugins/txp/trpage_writebuf.cpp +++ b/src/osgPlugins/txp/trpage_writebuf.cpp @@ -13,6 +13,8 @@ ************************ */ +#include + #include #include #include @@ -342,12 +344,12 @@ void trpgwAppFile::Init(trpgEndian inNess,const char *fileName,bool reuse) cpuNess = trpg_cpu_byte_order(); if (reuse==false) { - if (!(fp = fopen(fileName,"wb"))) + if (!(fp = osgDB::fopen(fileName,"wb"))) return; lengthSoFar = 0; valid = true; } else { - if (!(fp = fopen(fileName,"ab"))) + if (!(fp = osgDB::fopen(fileName,"ab"))) return; // ftell is still zero, dammit. Arg. fseek(fp,0,SEEK_END); diff --git a/src/osgPlugins/x/directx.cpp b/src/osgPlugins/x/directx.cpp index 86bea59fa..5f704efbc 100644 --- a/src/osgPlugins/x/directx.cpp +++ b/src/osgPlugins/x/directx.cpp @@ -35,6 +35,7 @@ #include #include +#include using namespace DX; using namespace std; @@ -63,7 +64,7 @@ bool Object::load(const char* filename) if (!filename) return false; - ifstream fin(filename); + osgDB::ifstream fin(filename); if (fin.bad()) { osg::notify(osg::WARN) << "Object::load: Unable to open: " << filename << endl; return false; diff --git a/src/osgViewer/ViewerEventHandlers.cpp b/src/osgViewer/ViewerEventHandlers.cpp index e8e7af0fb..0d6841a29 100644 --- a/src/osgViewer/ViewerEventHandlers.cpp +++ b/src/osgViewer/ViewerEventHandlers.cpp @@ -16,7 +16,6 @@ #include #include -#include #include #include @@ -506,7 +505,7 @@ bool RecordCameraPathHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GU // In the future this will need to be written continuously, rather // than all at once. - std::ofstream out(_filename.c_str()); + osgDB::ofstream out(_filename.c_str()); osg::notify(osg::NOTICE)<<"Writing camera file: "<<_filename<write(out); out.close(); diff --git a/src/osgWidget/Python.cpp b/src/osgWidget/Python.cpp index 777310798..2771491ca 100644 --- a/src/osgWidget/Python.cpp +++ b/src/osgWidget/Python.cpp @@ -172,7 +172,7 @@ bool PythonEngine::runFile(const std::string& filePath) { return false; } - FILE* f = fopen(filePath.c_str(), "r"); + FILE* f = osgDB::fopen(filePath.c_str(), "r"); PyObject* r = PyRun_File(f, filePath.c_str(), Py_file_input, _data->main, _data->main); fclose(f);