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:
36
include/osgDB/ConvertUTF
Normal file
36
include/osgDB/ConvertUTF
Normal 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
|
||||
@@ -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 );
|
||||
|
||||
|
||||
@@ -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
68
include/osgDB/fstream
Normal 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
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user