From Michael Platings, Converted std::fstream/ifstream/ofstream to osgDB::fstream/ifstream/ofstream and

fopen to osgDB::fopen to facilitate support for wide character filenames using UT8 encoding.
This commit is contained in:
Robert Osfield 2008-11-07 15:08:08 +00:00
parent 0ccf7d8383
commit 720551d549
76 changed files with 516 additions and 161 deletions

View File

@ -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)
################################################################################

View File

@ -3,6 +3,7 @@ SET(TARGET_SRC osgversion.cpp )
SET(TARGET_COMMON_LIBRARIES
OpenThreads
osg
osgDB
)
SETUP_COMMANDLINE_APPLICATION(osgversion)

View File

@ -8,13 +8,13 @@
#include <osg/BoundingBox>
#include <osg/BoundingSphere>
#include <osgDB/fstream>
#include <OpenThreads/Version>
#include <set>
#include <vector>
#include <iostream>
#include <fstream>
// 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)

View File

@ -3,13 +3,13 @@
#include <osgDB/ReadFile>
#include <osgDB/FileNameUtils>
#include <osgDB/fstream>
#include <iostream>
#include <fstream>
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 `"<<cppFileName<<"` for writing."<<std::endl;

View File

@ -9,18 +9,18 @@
#include <assert.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <osg/Geometry>
#include <osg/Geode>
#include <osgDB/FileUtils>
#include <osgDB/fstream>
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;

View File

@ -21,7 +21,6 @@
#include <iostream>
#include <list>
#include <string>
#include <fstream>
#include <sstream>
#include <osg/Geode>
@ -48,6 +47,7 @@
#include <osgDB/ReadFile>
#include <osgDB/FileUtils>
#include <osgDB/fstream>
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;

View File

@ -21,10 +21,10 @@
#include <osg/GLU>
#include <osg/Notify>
#include <osgDB/ReadFile>
#include <osgDB/fstream>
#include <osg/GraphicsContext>
#include <fstream>
#include <iostream>
@ -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());

View File

@ -46,6 +46,7 @@
#include <osg/CoordinateSystemNode>
#include <osgDB/FileUtils>
#include <osgDB/fstream>
#include <osgDB/ReadFile>
#include <osgText/Text>
@ -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;

View File

@ -17,6 +17,7 @@
*/
#include <osgViewer/Viewer>
#include <osgDB/fstream>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgUtil/Optimizer>
@ -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);

View File

@ -30,6 +30,7 @@
#include <osgDB/FileUtils>
#include <osgDB/fstream>
#include <osgDB/ReadFile>
#include <osgUtil/GLObjectsVisitor>
@ -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;

View File

@ -27,10 +27,11 @@
#include <osg/Timer>
#include <osg/Notify>
#include <osgDB/fstream>
#include <string>
#include <vector>
#include <list>
#include <fstream>
/**
@ -119,7 +120,7 @@ private:
TraceLevel _traceLevel;
std::ostream* _outputStreamPtr;
std::ofstream _nullStream;
osgDB::ofstream _nullStream;
};
#endif /* DOXYGEN_SHOULD_SKIP_THIS */

View File

@ -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 "<<filename<<std::endl;
osg::TransferFunction1D::ValueMap valueMap;
std::ifstream fin(foundFile.c_str());
osgDB::ifstream fin(foundFile.c_str());
while(fin)
{
float value, red, green, blue, alpha;
@ -1958,7 +1958,7 @@ int main( int argc, char **argv )
std::string raw_filename, transfer_filename;
int xdim(0), ydim(0), zdim(0);
std::ifstream header(vh_filename.c_str());
osgDB::ifstream header(vh_filename.c_str());
if (header)
{
header >> 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;

36
include/osgDB/ConvertUTF Normal file
View File

@ -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 <osg/Config>
#include <osgDB/Export>
#include <string>
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

View File

@ -20,6 +20,7 @@
#include <deque>
#include <string>
#include <stdio.h>
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 );

View File

@ -17,16 +17,16 @@
#include <osg/Object>
#include <osgDB/ReaderWriter>
#include <osgDB/fstream>
#include <string>
#include <map>
#include <fstream>
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:

68
include/osgDB/fstream Normal file
View File

@ -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 <osgDB/Export>
#include <fstream>
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

View File

@ -22,7 +22,7 @@
#include <osgViewer/GraphicsWindow>
#include <osgViewer/Viewer>
#include <fstream>
#include <osgDB/fstream>
namespace osgViewer {
@ -252,7 +252,7 @@ protected:
std::string _filename;
int _autoinc;
std::ofstream _fout;
osgDB::ofstream _fout;
int _keyEventToggleRecord;
int _keyEventTogglePlayback;

View File

@ -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

View File

@ -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

90
src/osgDB/ConvertUTF.cpp Normal file
View File

@ -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 <osgDB/ConvertUTF>
#include <osg/Notify>
#if defined(WIN32) && !defined(__CYGWIN__)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#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
}
}

View File

@ -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 <osg/Config>
#include <osgDB/ConvertUTF>
#include <osg/Notify>
#include <osgDB/FileUtils>
@ -73,7 +75,33 @@
#include <errno.h>
#include <stack>
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);

View File

@ -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;
}

View File

@ -28,6 +28,7 @@
#include <osgDB/Registry>
#include <osgDB/FileUtils>
#include <osgDB/FileNameUtils>
#include <osgDB/fstream>
#include <osgDB/Archive>
#include <algorithm>
@ -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())
{

61
src/osgDB/fstream.cpp Normal file
View File

@ -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 <osgDB/fstream>
#include <osgDB/ConvertUTF>
#include <osg/Config>
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);
}
}

View File

@ -1,6 +1,6 @@
#include <osgGA/AnimationPathManipulator>
#include <fstream>
#include <osgDB/fstream>
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)
{

View File

@ -4,6 +4,7 @@
#include <osgDB/FileNameUtils>
#include <osgDB/FileUtils>
#include <osgDB/fstream>
#include <osgDB/Registry>
#include <iostream>
@ -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);

View File

@ -37,6 +37,8 @@
#include <dmalloc.h>
#endif
#include <osgDB/FileUtils>
/*!
* \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);
}

View File

@ -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() )
{

View File

@ -20,7 +20,7 @@
#include <osg/NodeVisitor>
#include "ExportOptions.h"
#include "Types.h"
#include <fstream>
#include <osgDB/fstream>
#include <set>
#include <memory>
@ -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;

View File

@ -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())

View File

@ -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())
{

View File

@ -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() )
{

View File

@ -21,7 +21,7 @@
#include "DataOutputStream.h"
#include "ExportOptions.h"
#include <osg/Array>
#include <fstream>
#include <osgDB/fstream>
#include <map>
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;

View File

@ -33,6 +33,7 @@
#include <osgDB/Registry>
#include <osgDB/ReadFile>
#include <osgDB/FileUtils>
#include <osgDB/fstream>
#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::vector<unsigned int>iNumMaterials;
const_cast<osg::Node&>(node).accept(vs); // this parses the tree to streamd Geodes
std::vector<const osg::Geode *> 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<const osg::Geode *>::iterator itr;
fout << "AC3Db" << std::endl;

View File

@ -7,6 +7,7 @@
#include <osgDB/Registry>
#include <osgDB/FileNameUtils>
#include <osgDB/FileUtils>
#include <osgDB/fstream>
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);

View File

@ -15,6 +15,8 @@
#include <osg/ref_ptr>
#include <osg/io_utils>
#include <osgDB/FileUtils>
#if defined(WIN32) && !defined(__CYGWIN__)
#include <io.h>
#include <windows.h>
@ -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

View File

@ -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;

View File

@ -221,9 +221,10 @@
#define SUPPORT_CPP 1
#endif
#include <osgDB/fstream>
#include <string.h>
#include <stdio.h>
#include <fstream>
#include <string>
#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;

View File

@ -23,6 +23,7 @@
#include <osgDB/Registry>
#include <osgDB/FileNameUtils>
#include <osgDB/FileUtils>
#include <osgDB/fstream>
#include <iomanip>
#include <stdio.h>
@ -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);

View File

@ -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+"\"");
}

View File

@ -17,13 +17,14 @@
#ifndef DXF_READER
#define DXF_READER 1
#include <fstream>
#include <string>
#include <sstream>
#include <osg/Referenced>
#include <osg/ref_ptr>
#include <osgDB/fstream>
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<readerBase> _reader;
};

View File

@ -33,6 +33,7 @@
#include <osgDB/FileNameUtils>
#include <osgDB/FileUtils>
#include <osgDB/fstream>
#include <osgDB/Registry>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
@ -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.

View File

@ -5,6 +5,7 @@
#include <osgDB/Registry>
#include <osgDB/FileNameUtils>
#include <osgDB/FileUtils>
#include <osgDB/fstream>
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);

View File

@ -34,6 +34,7 @@
#include <osgDB/Registry>
#include <osgDB/FileNameUtils>
#include <osgDB/FileUtils>
#include <osgDB/fstream>
#include <stdio.h>
#include <assert.h>
@ -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);

View File

@ -32,6 +32,8 @@
#include <memory.h>
#include <stdio.h>
#include <osgDB/FileUtils>
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;

View File

@ -112,8 +112,8 @@
#include <osg/Notify>
#include <osg/io_utils>
#include <osgDB/FileUtils>
#include <osgDB/fstream>
#include <fstream>
#include <sstream>
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

View File

@ -5,6 +5,7 @@
#include <osgDB/FileNameUtils>
#include <osgDB/FileUtils>
#include <osgDB/fstream>
#include <osgDB/Registry>
using namespace osg;
@ -51,7 +52,7 @@ class ReaderWriterIVE : public ReaderWriter
osg::ref_ptr<Options> local_opt = options ? static_cast<Options*>(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<Options> local_opt = options ? static_cast<Options*>(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<Options> local_opt = options ? static_cast<Options*>(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());

View File

@ -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))
{

View File

@ -15,11 +15,10 @@
#include <osg/LightModel>
#include <osgDB/FileUtils>
#include <osgDB/fstream>
#include "lwo2parser.h"
#include <fstream>
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<char> buffer;

View File

@ -29,7 +29,6 @@
#include <vector>
#include <map>
#include <string>
#include <fstream>
#include <osg/Referenced>
#include <osg/Vec2>
@ -38,6 +37,8 @@
#include <osg/Group>
#include <osg/Notify>
#include <osgDB/fstream>
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();

View File

@ -22,6 +22,8 @@
#include <stdlib.h>
#include <string.h>
#include <osgDB/FileUtils>
#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 "<<lw_file<<std::endl;
return NULL;

View File

@ -14,10 +14,10 @@
#include <osgDB/FileUtils>
#include <osgDB/FileNameUtils>
#include <osgDB/fstream>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <fstream>
#include <sstream>
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();

View File

@ -38,6 +38,7 @@
#include <osgDB/ReadFile>
#include <osgDB/FileUtils>
#include <osgDB/FileNameUtils>
#include <osgDB/fstream>
#include <osgUtil/TriStripVisitor>
#include <osgUtil/SmoothingVisitor>
@ -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<osg::Node*>(&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)
{

View File

@ -13,7 +13,6 @@
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <stdio.h>
@ -23,6 +22,7 @@
#include <osgDB/FileUtils>
#include <osgDB/FileNameUtils>
#include <osgDB/fstream>
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);

View File

@ -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;

View File

@ -6,6 +6,7 @@
#include <osgDB/FileNameUtils>
#include <osgDB/FileUtils>
#include <osgDB/fstream>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
@ -47,7 +48,7 @@ class OSGReaderWriter : public ReaderWriter
osg::ref_ptr<Options> local_opt = opt ? static_cast<Options*>(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<Options> local_opt = opt ? static_cast<Options*>(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());

View File

@ -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 )
{

View File

@ -57,7 +57,7 @@ class ReaderWriterTerrain : public osgDB::ReaderWriter
osg::ref_ptr<Options> local_opt = opt ? static_cast<Options*>(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());

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -8,6 +8,7 @@
#include <osgDB/Registry>
#include <osgDB/FileNameUtils>
#include <osgDB/FileUtils>
#include <osgDB/fstream>
#include <stdio.h>
@ -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);

View File

@ -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);

View File

@ -1,5 +1,6 @@
#include <osgDB/FileNameUtils>
#include <osgDB/FileUtils>
#include <osgDB/fstream>
#include <osgDB/Registry>
#include <osgTerrain/Locator>
@ -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;

View File

@ -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

View File

@ -6,6 +6,7 @@
#include <osgDB/Registry>
#include <osgDB/FileNameUtils>
#include <osgDB/FileUtils>
#include <osgDB/fstream>
#include <stdio.h>
#include <assert.h>
@ -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);

View File

@ -11,10 +11,9 @@
* OpenSceneGraph Public License for more details.
*/
#include <fstream>
#include <osgDB/FileNameUtils>
#include <osgDB/FileUtils>
#include <osgDB/fstream>
#include <osgDB/Registry>
#include <osg/Notify>
@ -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;

View File

@ -16,6 +16,7 @@
#include <osgDB/FileUtils>
#include <osgDB/FileUtils>
#include <osgDB/FileNameUtils>
#include <osgDB/fstream>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgSim/Sector>
@ -23,7 +24,6 @@
#include <osgSim/LightPointNode>
#include <osgSim/BlinkSequence>
#include <iostream>
#include <fstream>
#if defined(linux)
# include <unistd.h>
@ -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())

View File

@ -13,6 +13,8 @@
************************
*/
#include <osgDB/FileUtils>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@ -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;
}

View File

@ -13,6 +13,8 @@
************************
*/
#include <osgDB/FileUtils>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@ -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;
}

View File

@ -12,6 +12,9 @@
Tel: (520) 323-7990
************************
*/
#include <osgDB/FileUtils>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@ -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;

View File

@ -13,6 +13,8 @@
************************
*/
#include <osgDB/FileUtils>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@ -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

View File

@ -13,6 +13,8 @@
************************
*/
#include <osgDB/FileUtils>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@ -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);

View File

@ -35,6 +35,7 @@
#include <math.h>
#include <osg/Notify>
#include <osgDB/fstream>
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;

View File

@ -16,7 +16,6 @@
#include <limits.h>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <osgDB/FileNameUtils>
@ -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<<std::endl;
_animPath->write(out);
out.close();

View File

@ -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);