Tried to make this a little more gcc friendly - created some NS_USING_NAMESPACE/ NS_NAMESPACE ugliness. Sigh.

git-svn-id: svn://10.0.0.236/trunk@16031 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mcmullen%netscape.com 1998-12-09 05:09:28 +00:00
parent c9e7bd13c8
commit 0588941742
14 changed files with 320 additions and 234 deletions

View File

@ -104,6 +104,27 @@
#define _FILESPEC_H_
#include <string>
//========================================================================================
// Compiler-specific macros, as needed
//========================================================================================
#if defined(__MWERKS__) || defined(XP_PC)
#define NS_USING_NAMESPACE
#endif
#ifdef NS_USING_NAMESPACE
#define NS_NAMESPACE_PROTOTYPE
#define NS_NAMESPACE namespace
#define NS_NAMESPACE_END
using std::string;
using std::ostream;
#else
#define NS_NAMESPACE_PROTOTYPE static
#define NS_NAMESPACE struct
#define NS_NAMESPACE_END ;
#endif
//=========================== End Compiler-specific macros ===============================
#include "nsDebug.h"
#ifdef XP_MAC
#include <Files.h>
@ -128,12 +149,12 @@ class nsNativeFileSpec
{
public:
nsNativeFileSpec();
explicit nsNativeFileSpec(const std::string& inString);
explicit nsNativeFileSpec(const string& inString);
nsNativeFileSpec(const nsFilePath& inPath);
nsNativeFileSpec(const nsFileURL& inURL);
nsNativeFileSpec(const nsNativeFileSpec& inPath);
void operator = (const std::string& inPath);
void operator = (const string& inPath);
void operator = (const nsFilePath& inPath);
void operator = (const nsFileURL& inURL);
void operator = (const nsNativeFileSpec& inOther);
@ -162,21 +183,21 @@ class nsNativeFileSpec
#endif
#if DEBUG
friend std::ostream& operator << (std::ostream& s, const nsNativeFileSpec& spec);
friend ostream& operator << (ostream& s, const nsNativeFileSpec& spec);
#endif
std::string GetLeafName() const;
void SetLeafName(const std::string& inLeafName);
string GetLeafName() const;
void SetLeafName(const string& inLeafName);
bool Exists() const;
void MakeUnique();
void MakeUnique(const std::string& inSuggestedLeafName);
void MakeUnique(const string& inSuggestedLeafName);
private:
friend class nsFilePath;
#ifdef XP_MAC
FSSpec mSpec;
OSErr mError;
FSSpec mSpec;
OSErr mError;
#elif defined(XP_UNIX) || defined(XP_PC)
std::string mPath;
string mPath;
#endif
}; // class nsNativeFileSpec
@ -189,16 +210,16 @@ class nsFileURL
{
public:
nsFileURL(const nsFileURL& inURL);
explicit nsFileURL(const std::string& inString);
explicit nsFileURL(const string& inString);
nsFileURL(const nsFilePath& inPath);
nsFileURL(const nsNativeFileSpec& inPath);
// std::string GetString() const { return mPath; }
// string GetString() const { return mPath; }
// may be needed for implementation reasons,
// but should not provide a conversion constructor.
void operator = (const nsFileURL& inURL);
void operator = (const std::string& inString);
void operator = (const string& inString);
void operator = (const nsFilePath& inOther);
void operator = (const nsNativeFileSpec& inOther);
@ -208,10 +229,10 @@ class nsFileURL
#endif
private:
// Should not be defined (only nsFilePath is to be treated as strings.
operator std::string& ();
operator string& ();
private:
std::string mURL;
string mURL;
#ifdef XP_MAC
// Since the path on the macintosh does not uniquely specify a file (volumes
// can have the same name), stash the secret nsNativeFileSpec, too.
@ -227,7 +248,7 @@ class nsFilePath
{
public:
nsFilePath(const nsFilePath& inPath);
explicit nsFilePath(const std::string& inString);
explicit nsFilePath(const string& inString);
nsFilePath(const nsFileURL& inURL);
nsFilePath(const nsNativeFileSpec& inPath);
@ -236,13 +257,13 @@ class nsFilePath
// This is the only automatic conversion to const char*
// that is provided, and it allows the
// path to be "passed" to NSPR file routines.
operator std::string& () { return mPath; }
operator string& () { return mPath; }
// This is the only automatic conversion to string
// that is provided, because a naked string should
// only mean a standard file path.
void operator = (const nsFilePath& inPath);
void operator = (const std::string& inString);
void operator = (const string& inString);
void operator = (const nsFileURL& inURL);
void operator = (const nsNativeFileSpec& inOther);
@ -254,7 +275,7 @@ class nsFilePath
private:
std::string mPath;
string mPath;
#ifdef XP_MAC
// Since the path on the macintosh does not uniquely specify a file (volumes
// can have the same name), stash the secret nsNativeFileSpec, too.
@ -270,14 +291,14 @@ class nsFilePath
//----------------------------------------------------------------------------------------
inline nsFilePath::nsFilePath(const nsNativeFileSpec& inOther)
//----------------------------------------------------------------------------------------
: mPath((std::string&)inOther)
: mPath((string&)inOther)
{
}
//----------------------------------------------------------------------------------------
inline void nsFilePath::operator = (const nsNativeFileSpec& inOther)
//----------------------------------------------------------------------------------------
{
mPath = (std::string&)inOther;
mPath = (string&)inOther;
}
#endif // XP_UNIX
@ -307,7 +328,7 @@ inline void nsNativeFileSpec::operator = (const nsFileURL& inURL)
//----------------------------------------------------------------------------------------
inline nsNativeFileSpec::nsNativeFileSpec(const nsFilePath& inPath)
//----------------------------------------------------------------------------------------
: mPath((std::string&)inPath)
: mPath((string&)inPath)
{
}
#endif // XP_UNIX
@ -317,7 +338,7 @@ inline nsNativeFileSpec::nsNativeFileSpec(const nsFilePath& inPath)
inline void nsNativeFileSpec::operator = (const nsFilePath& inPath)
//----------------------------------------------------------------------------------------
{
mPath = (std::string&)inPath;
mPath = (string&)inPath;
}
#endif //XP_UNIX
@ -325,14 +346,14 @@ inline void nsNativeFileSpec::operator = (const nsFilePath& inPath)
//----------------------------------------------------------------------------------------
inline nsNativeFileSpec::nsNativeFileSpec(const nsNativeFileSpec& inSpec)
//----------------------------------------------------------------------------------------
: mPath((std::string&)inSpec)
: mPath((string&)inSpec)
{
}
#endif //XP_UNIX
#if defined(XP_UNIX) || defined(XP_PC)
//----------------------------------------------------------------------------------------
inline nsNativeFileSpec::nsNativeFileSpec(const std::string& inString)
inline nsNativeFileSpec::nsNativeFileSpec(const string& inString)
//----------------------------------------------------------------------------------------
: mPath(inString)
{
@ -344,14 +365,14 @@ inline nsNativeFileSpec::nsNativeFileSpec(const std::string& inString)
inline void nsNativeFileSpec::operator = (const nsNativeFileSpec& inSpec)
//----------------------------------------------------------------------------------------
{
mPath = (std::string&)inSpec;
mPath = (string&)inSpec;
}
#endif //XP_UNIX
#if defined(XP_UNIX) || defined(XP_PC)
//----------------------------------------------------------------------------------------
inline void nsNativeFileSpec::operator = (const std::string& inString)
inline nsNativeFileSpec::operator = (const string& inString)
//----------------------------------------------------------------------------------------
{
mPath = inString;
@ -360,10 +381,10 @@ inline void nsNativeFileSpec::operator = (const std::string& inString)
#if (defined(XP_UNIX) || defined(XP_PC)) && DEBUG
//----------------------------------------------------------------------------------------
inline std::ostream& operator << (std::ostream& s, const nsNativeFileSpec& spec)
inline ostream& operator << (ostream& s, const nsNativeFileSpec& spec)
//----------------------------------------------------------------------------------------
{
return (s << (std::string&)spec.mPath);
return (s << (string&)spec.mPath);
}
#endif // DEBUG && XP_UNIX

View File

@ -72,7 +72,8 @@
#ifndef _FILESTREAM_H_
#define _FILESTREAM_H_
#include <istream>
#include <istream.h>
#ifdef XP_MAC
#include "pprio.h" // To get PR_ImportFile
#else
@ -83,6 +84,30 @@
//========================================================================================
// Compiler-specific macros, as needed
//========================================================================================
#if defined(__MWERKS__) || defined(XP_PC)
#define NS_USING_NAMESPACE
#endif
#ifdef NS_USING_NAMESPACE
#define NS_NAMESPACE_PROTOTYPE
#define NS_NAMESPACE namespace
#define NS_NAMESPACE_END
using std::ios_base;
using std::basic_streambuf;
using std::codecvt_base;
using std::codecvt;
using std::streamsize;
using std::locale;
using std::basic_istream;
using std::basic_ostream;
using std::basic_iostream;
using std::char_traits;
#else
#define NS_NAMESPACE_PROTOTYPE static
#define NS_NAMESPACE struct
#define NS_NAMESPACE_END ;
#endif
#ifdef __MWERKS__
#ifdef MSIPL_WCHART
@ -103,16 +128,16 @@
#endif //==================== End Compiler-specific macros ===============================
//========================================================================================
namespace nsFileStreamHelpers
NS_NAMESPACE nsFileStreamHelpers
// Prototypes for common (non-template) implementations in the .cpp file which do not
// need the template args (charT, traits).
//========================================================================================
{
PRFileDesc* open(
NS_NAMESPACE_PROTOTYPE PRFileDesc* open(
const nsFilePath& inFile,
std::ios_base::openmode mode,
ios_base::openmode mode,
PRIntn accessMode);
} // nsFileStreamHelpers
} NS_NAMESPACE_END // nsFileStreamHelpers
//========================================================================================
// Template declarations
@ -122,9 +147,9 @@ namespace nsFileStreamHelpers
template<class charT, class traits>
class nsFileBufferT
//========================================================================================
: public std::basic_streambuf<charT, traits>
: public basic_streambuf<charT, traits>
{
typedef std::codecvt_base::result result;
typedef codecvt_base::result result;
public:
typedef charT char_type;
@ -135,8 +160,8 @@ public:
typedef typename traits::state_type state_type;
typedef nsFileBufferT<charT, traits> filebuf_type;
typedef std::codecvt<charT, char, state_type> ofacet_type;
typedef std::codecvt<char, charT, state_type> ifacet_type;
typedef codecvt<charT, char, state_type> ofacet_type;
typedef codecvt<char, charT, state_type> ifacet_type;
nsFileBufferT();
nsFileBufferT(PRFileDesc* pfile_arg);
@ -144,7 +169,7 @@ public:
bool is_open() const;
filebuf_type* open(
const nsFilePath& inFile,
std::ios_base::openmode mode,
ios_base::openmode mode,
PRIntn accessMode);
filebuf_type* close();
@ -153,28 +178,28 @@ protected:
virtual int_type pbackfail(int_type c=traits::eof());
virtual int_type underflow();
virtual pos_type seekoff(
off_type off, std::ios_base::seekdir way,
std::ios_base::openmode which=std::ios_base::in|std::ios_base::out);
off_type off, ios_base::seekdir way,
ios_base::openmode which=ios_base::in|ios_base::out);
virtual pos_type seekpos(pos_type sp,
std::ios_base::openmode which=std::ios_base::in|std::ios_base::out);
virtual std::basic_streambuf<charT, traits>* setbuf(char_type* s, std::streamsize n);
ios_base::openmode which=ios_base::in|ios_base::out);
virtual basic_streambuf<charT, traits>* setbuf(char_type* s, streamsize n);
virtual int sync();
virtual int_type uflow();
virtual void imbue(const std::locale& loc);
virtual std::streamsize showmanyc();
virtual std::streamsize xsgetn(char_type* s, std::streamsize n);
virtual std::streamsize xsputn(const char_type* s, std::streamsize n);
virtual void imbue(const locale& loc);
virtual streamsize showmanyc();
virtual streamsize xsgetn(char_type* s, streamsize n);
virtual streamsize xsputn(const char_type* s, streamsize n);
private:
PRFileDesc* mFileDesc;
std::ios_base::openmode mode_;
ios_base::openmode mode_;
}; // class nsFileBufferT
//========================================================================================
template<class charT, class traits>
class nsInputFileStreamT
//========================================================================================
: public std::basic_istream<charT, traits>
: public basic_istream<charT, traits>
{
typedef nsFileBufferT<charT, traits> filebuf_type;
@ -188,7 +213,7 @@ public:
nsInputFileStreamT();
explicit nsInputFileStreamT(
const nsFilePath& inFile,
std::ios_base::openmode mode=std::ios_base::in,
ios_base::openmode mode=ios_base::in,
PRIntn accessMode = 0x00400);
virtual ~nsInputFileStreamT();
@ -197,7 +222,7 @@ public:
inline bool is_open();
inline void open(
const nsFilePath& inFile,
std::ios_base::openmode mode=std::ios_base::in,
ios_base::openmode mode=ios_base::in,
PRIntn accessMode = 0x00400);
inline void close();
@ -209,7 +234,7 @@ private:
template<class charT, class traits>
class nsOutputFileStreamT
//========================================================================================
: public std::basic_ostream<charT, traits>
: public basic_ostream<charT, traits>
{
typedef nsFileBufferT<charT, traits> filebuf_type;
@ -283,7 +308,7 @@ template<class charT, class traits>
nsFileBufferT<charT, traits>::filebuf_type*
nsFileBufferT<charT, traits>::open(
const nsFilePath& inFile,
std::ios_base::openmode mode,
ios_base::openmode mode,
PRIntn accessMode)
//----------------------------------------------------------------------------------------
{
@ -319,8 +344,8 @@ nsFileBufferT<charT, traits>:: sync()
//----------------------------------------------------------------------------------------
template<class charT, class traits>
inline std::basic_streambuf<charT, traits>*
nsFileBufferT<charT, traits>::setbuf(char_type*, std::streamsize)
inline basic_streambuf<charT, traits>*
nsFileBufferT<charT, traits>::setbuf(char_type*, streamsize)
//----------------------------------------------------------------------------------------
{
return (!mFileDesc) ? 0 : this;
@ -383,7 +408,7 @@ inline nsFileBufferT<charT, traits>::int_type nsFileBufferT<charT, traits>::unde
//----------------------------------------------------------------------------------------
template<class charT, class traits>
std::streamsize nsFileBufferT<charT, traits>::xsputn(const char_type* s, std::streamsize n)
streamsize nsFileBufferT<charT, traits>::xsputn(const char_type* s, streamsize n)
//----------------------------------------------------------------------------------------
{
#ifdef NS_EXPLICIT_FUNC_TEMPLATE_ARG
@ -449,36 +474,36 @@ inline nsFileBufferT<charT, traits>::int_type nsFileBufferT<charT, traits>::uflo
//----------------------------------------------------------------------------------------
template<class charT, class traits>
inline std::streamsize nsFileBufferT<charT, traits>::xsgetn(char_type* s, std::streamsize n)
inline streamsize nsFileBufferT<charT, traits>::xsgetn(char_type* s, streamsize n)
//----------------------------------------------------------------------------------------
{
return mFileDesc ? (std::streamsize)PR_Read(mFileDesc, s, sizeof(char) * size_t(n)) : 0;
return mFileDesc ? (streamsize)PR_Read(mFileDesc, s, sizeof(char) * size_t(n)) : 0;
}
//----------------------------------------------------------------------------------------
template<class charT, class traits>
inline void nsFileBufferT<charT, traits>::imbue(const std::locale& loc_arg)
inline void nsFileBufferT<charT, traits>::imbue(const locale& loc_arg)
//----------------------------------------------------------------------------------------
{
loc = loc_arg;
}
template<class charT, class traits>
inline std::streamsize
inline streamsize
nsFileBufferT<charT, traits>::showmanyc()
{
return (std::streamsize)PR_Available(mFileDesc);
return (streamsize)PR_Available(mFileDesc);
}
//----------------------------------------------------------------------------------------
template<class charT, class traits>
nsFileBufferT<charT, traits>::pos_type nsFileBufferT<charT, traits>::seekoff(
off_type off,
std::ios_base::seekdir way,
std::ios_base::openmode /* which */)
ios_base::seekdir way,
ios_base::openmode /* which */)
//----------------------------------------------------------------------------------------
{
if (!mFileDesc || ((way&std::ios_base::beg) && off<0) || ((way&std::ios_base::end) && off > 0))
if (!mFileDesc || ((way&ios_base::beg) && off<0) || ((way&ios_base::end) && off > 0))
return pos_type(-1);
PRSeekWhence poseek = PR_SEEK_CUR;
switch (way)
@ -497,7 +522,7 @@ nsFileBufferT<charT, traits>::pos_type nsFileBufferT<charT, traits>::seekoff(
//----------------------------------------------------------------------------------------
template<class charT, class traits>
nsFileBufferT<charT, traits>::pos_type
nsFileBufferT<charT, traits>::seekpos(pos_type sp, std::ios_base::openmode)
nsFileBufferT<charT, traits>::seekpos(pos_type sp, ios_base::openmode)
//----------------------------------------------------------------------------------------
{
if (!mFileDesc || sp==pos_type(-1))
@ -656,7 +681,7 @@ inline void nsOutputFileStreamT<charT, traits>:: close()
//========================================================================================
template<class charT, class traits>
class nsIOFileStreamT : public std::basic_iostream<charT, traits>
class nsIOFileStreamT : public basic_iostream<charT, traits>
//========================================================================================
{
typedef nsFileBufferT<charT, traits> filebuf_type;
@ -671,7 +696,7 @@ public:
nsIOFileStreamT();
explicit nsIOFileStreamT(
const nsFilePath& inFile,
std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out,
ios_base::openmode mode = ios_base::in|ios_base::out,
PRIntn accessMode = 0x00600);
virtual ~nsIOFileStreamT();
@ -680,7 +705,7 @@ public:
inline bool is_open();
inline void open(
const nsFilePath& inFile,
std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out,
ios_base::openmode mode = ios_base::in|ios_base::out,
PRIntn accessMode = 0x00600);
inline void close();
@ -765,16 +790,16 @@ nsIOFileStreamT<charT, traits>::close()
// Specializations of the stream templates
//========================================================================================
typedef nsFileBufferT<char, std::char_traits<char> > nsFileBuffer;
typedef nsInputFileStreamT<char, std::char_traits<char> > nsInputFileStream;
typedef nsOutputFileStreamT<char, std::char_traits<char> > nsOutputFileStream;
typedef nsIOFileStreamT<char, std::char_traits<char> > nsIOFileStream;
typedef nsFileBufferT<char, char_traits<char> > nsFileBuffer;
typedef nsInputFileStreamT<char, char_traits<char> > nsInputFileStream;
typedef nsOutputFileStreamT<char, char_traits<char> > nsOutputFileStream;
typedef nsIOFileStreamT<char, char_traits<char> > nsIOFileStream;
#ifdef NS_USING_WIDE_CHAR
typedef nsFileBufferT<wchar_t, std::char_traits<wchar_t> > nsWideFileBuffer;
typedef nsInputFileStreamT<wchar_t, std::char_traits<wchar_t> > nsWideInputFileStream;
typedef nsOutputFileStreamT<wchar_t, std::char_traits<wchar_t> > nsWideOutputFileStream;
typedef nsIOFileStreamT<wchar_t, std::char_traits<wchar_t> > nsWideIOFileStream;
typedef nsFileBufferT<wchar_t, char_traits<wchar_t> > nsWideFileBuffer;
typedef nsInputFileStreamT<wchar_t, char_traits<wchar_t> > nsWideInputFileStream;
typedef nsOutputFileStreamT<wchar_t, char_traits<wchar_t> > nsWideOutputFileStream;
typedef nsIOFileStreamT<wchar_t, char_traits<wchar_t> > nsWideIOFileStream;
#endif // NS_USING_WIDE_CHAR
#endif /* _FILESTREAM_H_ */

View File

@ -459,7 +459,7 @@ nsNativeFileSpec::nsNativeFileSpec(const nsNativeFileSpec& inSpec)
}
//----------------------------------------------------------------------------------------
nsNativeFileSpec::nsNativeFileSpec(const std::string& inString)
nsNativeFileSpec::nsNativeFileSpec(const string& inString)
//----------------------------------------------------------------------------------------
{
mError = MacFileHelpers::FSSpecFromFullUnixPath(inString.c_str(), mSpec, true);
@ -499,7 +499,7 @@ ostream& operator << (ostream& s, const nsNativeFileSpec& spec)
#endif // DEBUG
//----------------------------------------------------------------------------------------
void nsNativeFileSpec::operator = (const std::string& inString)
void nsNativeFileSpec::operator = (const string& inString)
//----------------------------------------------------------------------------------------
{
mError = MacFileHelpers::FSSpecFromFullUnixPath(inString.c_str(), mSpec, true);
@ -529,7 +529,7 @@ bool nsNativeFileSpec::Exists() const
} // nsNativeFileSpec::operator =
//----------------------------------------------------------------------------------------
void nsNativeFileSpec::SetLeafName(const std::string& inLeafName)
void nsNativeFileSpec::SetLeafName(const string& inLeafName)
//----------------------------------------------------------------------------------------
{
*mSpec.name = inLeafName.length();
@ -537,13 +537,13 @@ void nsNativeFileSpec::SetLeafName(const std::string& inLeafName)
} // nsNativeFileSpec::SetLeafName
//----------------------------------------------------------------------------------------
std::string nsNativeFileSpec::GetLeafName() const
string nsNativeFileSpec::GetLeafName() const
//----------------------------------------------------------------------------------------
{
char leaf[64];
memcpy(leaf, &mSpec.name[1], mSpec.name[0]);
leaf[mSpec.name[0]] = '\0';
return std::string(leaf);
return string(leaf);
} // nsNativeFileSpec::GetLeafName
//========================================================================================

View File

@ -21,13 +21,13 @@
#include "prtypes.h"
#if DEBUG
#include <ostream>
#include <ostream.h>
#endif
#include <strstream>
#include <strstream.h>
//========================================================================================
namespace nsFileSpecHelpers
NS_NAMESPACE nsFileSpecHelpers
//========================================================================================
{
enum
@ -35,33 +35,33 @@ namespace nsFileSpecHelpers
, kMaxAltDigitLength = 5
, kMaxAltNameLength = (kMaxFilenameLength - (kMaxAltDigitLength + 1))
};
void LeafReplace(
std::string& ioPath,
NS_NAMESPACE_PROTOTYPE void LeafReplace(
string& ioPath,
char inSeparator,
const std::string& inLeafName);
std::string GetLeaf(const std::string& inPath, char inSeparator);
}
const string& inLeafName);
NS_NAMESPACE_PROTOTYPE string GetLeaf(const string& inPath, char inSeparator);
} NS_NAMESPACE_END
//----------------------------------------------------------------------------------------
void nsFileSpecHelpers::LeafReplace(
std::string& ioPath,
string& ioPath,
char inSeparator,
const std::string& inLeafName)
const string& inLeafName)
//----------------------------------------------------------------------------------------
{
// Find the existing leaf name
std::string::size_type lastSeparator = ioPath.rfind(inSeparator);
std::string::size_type myLength = ioPath.length();
string::size_type lastSeparator = ioPath.rfind(inSeparator);
string::size_type myLength = ioPath.length();
if (lastSeparator < myLength)
ioPath = ioPath.substr(0, lastSeparator + 1) + inLeafName;
} // nsNativeFileSpec::SetLeafName
//----------------------------------------------------------------------------------------
std::string nsFileSpecHelpers::GetLeaf(const std::string& inPath, char inSeparator)
string nsFileSpecHelpers::GetLeaf(const string& inPath, char inSeparator)
//----------------------------------------------------------------------------------------
{
std::string::size_type lastSeparator = inPath.rfind(inSeparator);
std::string::size_type myLength = inPath.length();
string::size_type lastSeparator = inPath.rfind(inSeparator);
string::size_type myLength = inPath.length();
if (lastSeparator < myLength)
return inPath.substr(1 + lastSeparator, myLength - lastSeparator - 1);
return inPath;
@ -76,13 +76,12 @@ std::string nsFileSpecHelpers::GetLeaf(const std::string& inPath, char inSeparat
#include "nsFileSpecUnix.cpp" // Unix-specific implementations
#endif
//========================================================================================
// nsFileURL implementation
//========================================================================================
//----------------------------------------------------------------------------------------
nsFileURL::nsFileURL(const std::string& inString)
nsFileURL::nsFileURL(const string& inString)
//----------------------------------------------------------------------------------------
: mURL(inString)
#ifdef XP_MAC
@ -93,7 +92,7 @@ nsFileURL::nsFileURL(const std::string& inString)
}
//----------------------------------------------------------------------------------------
void nsFileURL::operator = (const std::string& inString)
void nsFileURL::operator = (const string& inString)
//----------------------------------------------------------------------------------------
{
mURL = inString;
@ -147,7 +146,7 @@ void nsFileURL::operator = (const nsFilePath& inOther)
nsFileURL::nsFileURL(const nsNativeFileSpec& inOther)
//----------------------------------------------------------------------------------------
{
mURL = kFileURLPrefix + (std::string&)nsFilePath(inOther);
mURL = kFileURLPrefix + (string&)nsFilePath(inOther);
#ifdef XP_MAC
mNativeFileSpec = inOther;
#endif
@ -156,7 +155,7 @@ nsFileURL::nsFileURL(const nsNativeFileSpec& inOther)
void nsFileURL::operator = (const nsNativeFileSpec& inOther)
//----------------------------------------------------------------------------------------
{
mURL = kFileURLPrefix + (std::string&)nsFilePath(inOther);
mURL = kFileURLPrefix + (string&)nsFilePath(inOther);
#ifdef XP_MAC
mNativeFileSpec = inOther;
#endif
@ -167,7 +166,7 @@ void nsFileURL::operator = (const nsNativeFileSpec& inOther)
//========================================================================================
//----------------------------------------------------------------------------------------
nsFilePath::nsFilePath(const std::string& inString)
nsFilePath::nsFilePath(const string& inString)
//----------------------------------------------------------------------------------------
: mPath(inString)
#ifdef XP_MAC
@ -189,7 +188,7 @@ nsFilePath::nsFilePath(const nsFileURL& inOther)
}
//----------------------------------------------------------------------------------------
void nsFilePath::operator = (const std::string& inString)
void nsFilePath::operator = (const string& inString)
//----------------------------------------------------------------------------------------
{
mPath = inString;
@ -223,7 +222,7 @@ nsNativeFileSpec::nsNativeFileSpec()
#endif
//----------------------------------------------------------------------------------------
void nsNativeFileSpec::MakeUnique(const std::string& inSuggestedLeafName)
void nsNativeFileSpec::MakeUnique(const string& inSuggestedLeafName)
//----------------------------------------------------------------------------------------
{
if (inSuggestedLeafName.length() > 0)
@ -240,15 +239,15 @@ void nsNativeFileSpec::MakeUnique()
return;
short index = 0;
std::string altName = GetLeafName();
std::string::size_type lastDot = altName.rfind('.');
std::string suffix;
string altName = GetLeafName();
string::size_type lastDot = altName.rfind('.');
string suffix;
if (lastDot < altName.length())
{
suffix = altName.substr(lastDot, altName.length() - lastDot); // include '.'
altName = altName.substr(0, lastDot);
}
const std::string::size_type kMaxRootLength
const string::size_type kMaxRootLength
= nsFileSpecHelpers::kMaxAltNameLength - suffix.length() - 1;
if (altName.length() > kMaxRootLength)
altName = altName.substr(0, kMaxRootLength);

View File

@ -26,8 +26,6 @@
#include <Errors.h>
#endif
using std::ios_base;
//----------------------------------------------------------------------------------------
PRFileDesc* nsFileStreamHelpers::open(
const nsFilePath& inFile,

View File

@ -20,14 +20,14 @@
// implementations.
//----------------------------------------------------------------------------------------
void nsNativeFileSpec::SetLeafName(const std::string& inLeafName)
void nsNativeFileSpec::SetLeafName(const string& inLeafName)
//----------------------------------------------------------------------------------------
{
nsFileHelpers::LeafReplace(mPath, '/', inLeafName);
} // nsNativeFileSpec::SetLeafName
//----------------------------------------------------------------------------------------
std::string nsNativeFileSpec::GetLeafName() const
string nsNativeFileSpec::GetLeafName() const
//----------------------------------------------------------------------------------------
{
return nsFileHelpers::GetLeaf(mPath, '/');

View File

@ -31,8 +31,8 @@ void nsNativeFileSpec::operator = (const nsFilePath& inPath)
//----------------------------------------------------------------------------------------
{
// Convert '/' to '\'
std::string& str = (std::string&)inPath;
for (std::string::size_type i = 0; i < str.length(); i++)
string& str = (string&)inPath;
for (string::size_type i = 0; i < str.length(); i++)
{
char c = str[i];
if (c == '/')
@ -46,8 +46,8 @@ nsFilePath::nsFilePath(const nsNativeFileSpec& inSpec)
//----------------------------------------------------------------------------------------
{
// Convert '\' to '/'
std::string& str = (std::string&)inSpec;
for (std::string::size_type i = 0; i < str.length(); i++)
string& str = (string&)inSpec;
for (string::size_type i = 0; i < str.length(); i++)
{
char c = str[i];
if (c == '\\')
@ -57,14 +57,14 @@ nsFilePath::nsFilePath(const nsNativeFileSpec& inSpec)
} // nsFilePath::nsFilePath
//----------------------------------------------------------------------------------------
void nsNativeFileSpec::SetLeafName(const std::string& inLeafName)
void nsNativeFileSpec::SetLeafName(const string& inLeafName)
//----------------------------------------------------------------------------------------
{
nsFileSpecHelpers::LeafReplace(mPath, '\\', inLeafName);
} // nsNativeFileSpec::SetLeafName
//----------------------------------------------------------------------------------------
std::string nsNativeFileSpec::GetLeafName() const
string nsNativeFileSpec::GetLeafName() const
//----------------------------------------------------------------------------------------
{
return nsFileSpecHelpers::GetLeaf(mPath, '\\');

View File

@ -21,13 +21,13 @@
#include "prtypes.h"
#if DEBUG
#include <ostream>
#include <ostream.h>
#endif
#include <strstream>
#include <strstream.h>
//========================================================================================
namespace nsFileSpecHelpers
NS_NAMESPACE nsFileSpecHelpers
//========================================================================================
{
enum
@ -35,33 +35,33 @@ namespace nsFileSpecHelpers
, kMaxAltDigitLength = 5
, kMaxAltNameLength = (kMaxFilenameLength - (kMaxAltDigitLength + 1))
};
void LeafReplace(
std::string& ioPath,
NS_NAMESPACE_PROTOTYPE void LeafReplace(
string& ioPath,
char inSeparator,
const std::string& inLeafName);
std::string GetLeaf(const std::string& inPath, char inSeparator);
}
const string& inLeafName);
NS_NAMESPACE_PROTOTYPE string GetLeaf(const string& inPath, char inSeparator);
} NS_NAMESPACE_END
//----------------------------------------------------------------------------------------
void nsFileSpecHelpers::LeafReplace(
std::string& ioPath,
string& ioPath,
char inSeparator,
const std::string& inLeafName)
const string& inLeafName)
//----------------------------------------------------------------------------------------
{
// Find the existing leaf name
std::string::size_type lastSeparator = ioPath.rfind(inSeparator);
std::string::size_type myLength = ioPath.length();
string::size_type lastSeparator = ioPath.rfind(inSeparator);
string::size_type myLength = ioPath.length();
if (lastSeparator < myLength)
ioPath = ioPath.substr(0, lastSeparator + 1) + inLeafName;
} // nsNativeFileSpec::SetLeafName
//----------------------------------------------------------------------------------------
std::string nsFileSpecHelpers::GetLeaf(const std::string& inPath, char inSeparator)
string nsFileSpecHelpers::GetLeaf(const string& inPath, char inSeparator)
//----------------------------------------------------------------------------------------
{
std::string::size_type lastSeparator = inPath.rfind(inSeparator);
std::string::size_type myLength = inPath.length();
string::size_type lastSeparator = inPath.rfind(inSeparator);
string::size_type myLength = inPath.length();
if (lastSeparator < myLength)
return inPath.substr(1 + lastSeparator, myLength - lastSeparator - 1);
return inPath;
@ -76,13 +76,12 @@ std::string nsFileSpecHelpers::GetLeaf(const std::string& inPath, char inSeparat
#include "nsFileSpecUnix.cpp" // Unix-specific implementations
#endif
//========================================================================================
// nsFileURL implementation
//========================================================================================
//----------------------------------------------------------------------------------------
nsFileURL::nsFileURL(const std::string& inString)
nsFileURL::nsFileURL(const string& inString)
//----------------------------------------------------------------------------------------
: mURL(inString)
#ifdef XP_MAC
@ -93,7 +92,7 @@ nsFileURL::nsFileURL(const std::string& inString)
}
//----------------------------------------------------------------------------------------
void nsFileURL::operator = (const std::string& inString)
void nsFileURL::operator = (const string& inString)
//----------------------------------------------------------------------------------------
{
mURL = inString;
@ -147,7 +146,7 @@ void nsFileURL::operator = (const nsFilePath& inOther)
nsFileURL::nsFileURL(const nsNativeFileSpec& inOther)
//----------------------------------------------------------------------------------------
{
mURL = kFileURLPrefix + (std::string&)nsFilePath(inOther);
mURL = kFileURLPrefix + (string&)nsFilePath(inOther);
#ifdef XP_MAC
mNativeFileSpec = inOther;
#endif
@ -156,7 +155,7 @@ nsFileURL::nsFileURL(const nsNativeFileSpec& inOther)
void nsFileURL::operator = (const nsNativeFileSpec& inOther)
//----------------------------------------------------------------------------------------
{
mURL = kFileURLPrefix + (std::string&)nsFilePath(inOther);
mURL = kFileURLPrefix + (string&)nsFilePath(inOther);
#ifdef XP_MAC
mNativeFileSpec = inOther;
#endif
@ -167,7 +166,7 @@ void nsFileURL::operator = (const nsNativeFileSpec& inOther)
//========================================================================================
//----------------------------------------------------------------------------------------
nsFilePath::nsFilePath(const std::string& inString)
nsFilePath::nsFilePath(const string& inString)
//----------------------------------------------------------------------------------------
: mPath(inString)
#ifdef XP_MAC
@ -189,7 +188,7 @@ nsFilePath::nsFilePath(const nsFileURL& inOther)
}
//----------------------------------------------------------------------------------------
void nsFilePath::operator = (const std::string& inString)
void nsFilePath::operator = (const string& inString)
//----------------------------------------------------------------------------------------
{
mPath = inString;
@ -223,7 +222,7 @@ nsNativeFileSpec::nsNativeFileSpec()
#endif
//----------------------------------------------------------------------------------------
void nsNativeFileSpec::MakeUnique(const std::string& inSuggestedLeafName)
void nsNativeFileSpec::MakeUnique(const string& inSuggestedLeafName)
//----------------------------------------------------------------------------------------
{
if (inSuggestedLeafName.length() > 0)
@ -240,15 +239,15 @@ void nsNativeFileSpec::MakeUnique()
return;
short index = 0;
std::string altName = GetLeafName();
std::string::size_type lastDot = altName.rfind('.');
std::string suffix;
string altName = GetLeafName();
string::size_type lastDot = altName.rfind('.');
string suffix;
if (lastDot < altName.length())
{
suffix = altName.substr(lastDot, altName.length() - lastDot); // include '.'
altName = altName.substr(0, lastDot);
}
const std::string::size_type kMaxRootLength
const string::size_type kMaxRootLength
= nsFileSpecHelpers::kMaxAltNameLength - suffix.length() - 1;
if (altName.length() > kMaxRootLength)
altName = altName.substr(0, kMaxRootLength);

View File

@ -104,6 +104,27 @@
#define _FILESPEC_H_
#include <string>
//========================================================================================
// Compiler-specific macros, as needed
//========================================================================================
#if defined(__MWERKS__) || defined(XP_PC)
#define NS_USING_NAMESPACE
#endif
#ifdef NS_USING_NAMESPACE
#define NS_NAMESPACE_PROTOTYPE
#define NS_NAMESPACE namespace
#define NS_NAMESPACE_END
using std::string;
using std::ostream;
#else
#define NS_NAMESPACE_PROTOTYPE static
#define NS_NAMESPACE struct
#define NS_NAMESPACE_END ;
#endif
//=========================== End Compiler-specific macros ===============================
#include "nsDebug.h"
#ifdef XP_MAC
#include <Files.h>
@ -128,12 +149,12 @@ class nsNativeFileSpec
{
public:
nsNativeFileSpec();
explicit nsNativeFileSpec(const std::string& inString);
explicit nsNativeFileSpec(const string& inString);
nsNativeFileSpec(const nsFilePath& inPath);
nsNativeFileSpec(const nsFileURL& inURL);
nsNativeFileSpec(const nsNativeFileSpec& inPath);
void operator = (const std::string& inPath);
void operator = (const string& inPath);
void operator = (const nsFilePath& inPath);
void operator = (const nsFileURL& inURL);
void operator = (const nsNativeFileSpec& inOther);
@ -162,21 +183,21 @@ class nsNativeFileSpec
#endif
#if DEBUG
friend std::ostream& operator << (std::ostream& s, const nsNativeFileSpec& spec);
friend ostream& operator << (ostream& s, const nsNativeFileSpec& spec);
#endif
std::string GetLeafName() const;
void SetLeafName(const std::string& inLeafName);
string GetLeafName() const;
void SetLeafName(const string& inLeafName);
bool Exists() const;
void MakeUnique();
void MakeUnique(const std::string& inSuggestedLeafName);
void MakeUnique(const string& inSuggestedLeafName);
private:
friend class nsFilePath;
#ifdef XP_MAC
FSSpec mSpec;
OSErr mError;
FSSpec mSpec;
OSErr mError;
#elif defined(XP_UNIX) || defined(XP_PC)
std::string mPath;
string mPath;
#endif
}; // class nsNativeFileSpec
@ -189,16 +210,16 @@ class nsFileURL
{
public:
nsFileURL(const nsFileURL& inURL);
explicit nsFileURL(const std::string& inString);
explicit nsFileURL(const string& inString);
nsFileURL(const nsFilePath& inPath);
nsFileURL(const nsNativeFileSpec& inPath);
// std::string GetString() const { return mPath; }
// string GetString() const { return mPath; }
// may be needed for implementation reasons,
// but should not provide a conversion constructor.
void operator = (const nsFileURL& inURL);
void operator = (const std::string& inString);
void operator = (const string& inString);
void operator = (const nsFilePath& inOther);
void operator = (const nsNativeFileSpec& inOther);
@ -208,10 +229,10 @@ class nsFileURL
#endif
private:
// Should not be defined (only nsFilePath is to be treated as strings.
operator std::string& ();
operator string& ();
private:
std::string mURL;
string mURL;
#ifdef XP_MAC
// Since the path on the macintosh does not uniquely specify a file (volumes
// can have the same name), stash the secret nsNativeFileSpec, too.
@ -227,7 +248,7 @@ class nsFilePath
{
public:
nsFilePath(const nsFilePath& inPath);
explicit nsFilePath(const std::string& inString);
explicit nsFilePath(const string& inString);
nsFilePath(const nsFileURL& inURL);
nsFilePath(const nsNativeFileSpec& inPath);
@ -236,13 +257,13 @@ class nsFilePath
// This is the only automatic conversion to const char*
// that is provided, and it allows the
// path to be "passed" to NSPR file routines.
operator std::string& () { return mPath; }
operator string& () { return mPath; }
// This is the only automatic conversion to string
// that is provided, because a naked string should
// only mean a standard file path.
void operator = (const nsFilePath& inPath);
void operator = (const std::string& inString);
void operator = (const string& inString);
void operator = (const nsFileURL& inURL);
void operator = (const nsNativeFileSpec& inOther);
@ -254,7 +275,7 @@ class nsFilePath
private:
std::string mPath;
string mPath;
#ifdef XP_MAC
// Since the path on the macintosh does not uniquely specify a file (volumes
// can have the same name), stash the secret nsNativeFileSpec, too.
@ -270,14 +291,14 @@ class nsFilePath
//----------------------------------------------------------------------------------------
inline nsFilePath::nsFilePath(const nsNativeFileSpec& inOther)
//----------------------------------------------------------------------------------------
: mPath((std::string&)inOther)
: mPath((string&)inOther)
{
}
//----------------------------------------------------------------------------------------
inline void nsFilePath::operator = (const nsNativeFileSpec& inOther)
//----------------------------------------------------------------------------------------
{
mPath = (std::string&)inOther;
mPath = (string&)inOther;
}
#endif // XP_UNIX
@ -307,7 +328,7 @@ inline void nsNativeFileSpec::operator = (const nsFileURL& inURL)
//----------------------------------------------------------------------------------------
inline nsNativeFileSpec::nsNativeFileSpec(const nsFilePath& inPath)
//----------------------------------------------------------------------------------------
: mPath((std::string&)inPath)
: mPath((string&)inPath)
{
}
#endif // XP_UNIX
@ -317,7 +338,7 @@ inline nsNativeFileSpec::nsNativeFileSpec(const nsFilePath& inPath)
inline void nsNativeFileSpec::operator = (const nsFilePath& inPath)
//----------------------------------------------------------------------------------------
{
mPath = (std::string&)inPath;
mPath = (string&)inPath;
}
#endif //XP_UNIX
@ -325,14 +346,14 @@ inline void nsNativeFileSpec::operator = (const nsFilePath& inPath)
//----------------------------------------------------------------------------------------
inline nsNativeFileSpec::nsNativeFileSpec(const nsNativeFileSpec& inSpec)
//----------------------------------------------------------------------------------------
: mPath((std::string&)inSpec)
: mPath((string&)inSpec)
{
}
#endif //XP_UNIX
#if defined(XP_UNIX) || defined(XP_PC)
//----------------------------------------------------------------------------------------
inline nsNativeFileSpec::nsNativeFileSpec(const std::string& inString)
inline nsNativeFileSpec::nsNativeFileSpec(const string& inString)
//----------------------------------------------------------------------------------------
: mPath(inString)
{
@ -344,14 +365,14 @@ inline nsNativeFileSpec::nsNativeFileSpec(const std::string& inString)
inline void nsNativeFileSpec::operator = (const nsNativeFileSpec& inSpec)
//----------------------------------------------------------------------------------------
{
mPath = (std::string&)inSpec;
mPath = (string&)inSpec;
}
#endif //XP_UNIX
#if defined(XP_UNIX) || defined(XP_PC)
//----------------------------------------------------------------------------------------
inline void nsNativeFileSpec::operator = (const std::string& inString)
inline nsNativeFileSpec::operator = (const string& inString)
//----------------------------------------------------------------------------------------
{
mPath = inString;
@ -360,10 +381,10 @@ inline void nsNativeFileSpec::operator = (const std::string& inString)
#if (defined(XP_UNIX) || defined(XP_PC)) && DEBUG
//----------------------------------------------------------------------------------------
inline std::ostream& operator << (std::ostream& s, const nsNativeFileSpec& spec)
inline ostream& operator << (ostream& s, const nsNativeFileSpec& spec)
//----------------------------------------------------------------------------------------
{
return (s << (std::string&)spec.mPath);
return (s << (string&)spec.mPath);
}
#endif // DEBUG && XP_UNIX

View File

@ -459,7 +459,7 @@ nsNativeFileSpec::nsNativeFileSpec(const nsNativeFileSpec& inSpec)
}
//----------------------------------------------------------------------------------------
nsNativeFileSpec::nsNativeFileSpec(const std::string& inString)
nsNativeFileSpec::nsNativeFileSpec(const string& inString)
//----------------------------------------------------------------------------------------
{
mError = MacFileHelpers::FSSpecFromFullUnixPath(inString.c_str(), mSpec, true);
@ -499,7 +499,7 @@ ostream& operator << (ostream& s, const nsNativeFileSpec& spec)
#endif // DEBUG
//----------------------------------------------------------------------------------------
void nsNativeFileSpec::operator = (const std::string& inString)
void nsNativeFileSpec::operator = (const string& inString)
//----------------------------------------------------------------------------------------
{
mError = MacFileHelpers::FSSpecFromFullUnixPath(inString.c_str(), mSpec, true);
@ -529,7 +529,7 @@ bool nsNativeFileSpec::Exists() const
} // nsNativeFileSpec::operator =
//----------------------------------------------------------------------------------------
void nsNativeFileSpec::SetLeafName(const std::string& inLeafName)
void nsNativeFileSpec::SetLeafName(const string& inLeafName)
//----------------------------------------------------------------------------------------
{
*mSpec.name = inLeafName.length();
@ -537,13 +537,13 @@ void nsNativeFileSpec::SetLeafName(const std::string& inLeafName)
} // nsNativeFileSpec::SetLeafName
//----------------------------------------------------------------------------------------
std::string nsNativeFileSpec::GetLeafName() const
string nsNativeFileSpec::GetLeafName() const
//----------------------------------------------------------------------------------------
{
char leaf[64];
memcpy(leaf, &mSpec.name[1], mSpec.name[0]);
leaf[mSpec.name[0]] = '\0';
return std::string(leaf);
return string(leaf);
} // nsNativeFileSpec::GetLeafName
//========================================================================================

View File

@ -20,14 +20,14 @@
// implementations.
//----------------------------------------------------------------------------------------
void nsNativeFileSpec::SetLeafName(const std::string& inLeafName)
void nsNativeFileSpec::SetLeafName(const string& inLeafName)
//----------------------------------------------------------------------------------------
{
nsFileHelpers::LeafReplace(mPath, '/', inLeafName);
} // nsNativeFileSpec::SetLeafName
//----------------------------------------------------------------------------------------
std::string nsNativeFileSpec::GetLeafName() const
string nsNativeFileSpec::GetLeafName() const
//----------------------------------------------------------------------------------------
{
return nsFileHelpers::GetLeaf(mPath, '/');

View File

@ -31,8 +31,8 @@ void nsNativeFileSpec::operator = (const nsFilePath& inPath)
//----------------------------------------------------------------------------------------
{
// Convert '/' to '\'
std::string& str = (std::string&)inPath;
for (std::string::size_type i = 0; i < str.length(); i++)
string& str = (string&)inPath;
for (string::size_type i = 0; i < str.length(); i++)
{
char c = str[i];
if (c == '/')
@ -46,8 +46,8 @@ nsFilePath::nsFilePath(const nsNativeFileSpec& inSpec)
//----------------------------------------------------------------------------------------
{
// Convert '\' to '/'
std::string& str = (std::string&)inSpec;
for (std::string::size_type i = 0; i < str.length(); i++)
string& str = (string&)inSpec;
for (string::size_type i = 0; i < str.length(); i++)
{
char c = str[i];
if (c == '\\')
@ -57,14 +57,14 @@ nsFilePath::nsFilePath(const nsNativeFileSpec& inSpec)
} // nsFilePath::nsFilePath
//----------------------------------------------------------------------------------------
void nsNativeFileSpec::SetLeafName(const std::string& inLeafName)
void nsNativeFileSpec::SetLeafName(const string& inLeafName)
//----------------------------------------------------------------------------------------
{
nsFileSpecHelpers::LeafReplace(mPath, '\\', inLeafName);
} // nsNativeFileSpec::SetLeafName
//----------------------------------------------------------------------------------------
std::string nsNativeFileSpec::GetLeafName() const
string nsNativeFileSpec::GetLeafName() const
//----------------------------------------------------------------------------------------
{
return nsFileSpecHelpers::GetLeaf(mPath, '\\');

View File

@ -26,8 +26,6 @@
#include <Errors.h>
#endif
using std::ios_base;
//----------------------------------------------------------------------------------------
PRFileDesc* nsFileStreamHelpers::open(
const nsFilePath& inFile,

View File

@ -72,7 +72,8 @@
#ifndef _FILESTREAM_H_
#define _FILESTREAM_H_
#include <istream>
#include <istream.h>
#ifdef XP_MAC
#include "pprio.h" // To get PR_ImportFile
#else
@ -83,6 +84,30 @@
//========================================================================================
// Compiler-specific macros, as needed
//========================================================================================
#if defined(__MWERKS__) || defined(XP_PC)
#define NS_USING_NAMESPACE
#endif
#ifdef NS_USING_NAMESPACE
#define NS_NAMESPACE_PROTOTYPE
#define NS_NAMESPACE namespace
#define NS_NAMESPACE_END
using std::ios_base;
using std::basic_streambuf;
using std::codecvt_base;
using std::codecvt;
using std::streamsize;
using std::locale;
using std::basic_istream;
using std::basic_ostream;
using std::basic_iostream;
using std::char_traits;
#else
#define NS_NAMESPACE_PROTOTYPE static
#define NS_NAMESPACE struct
#define NS_NAMESPACE_END ;
#endif
#ifdef __MWERKS__
#ifdef MSIPL_WCHART
@ -103,16 +128,16 @@
#endif //==================== End Compiler-specific macros ===============================
//========================================================================================
namespace nsFileStreamHelpers
NS_NAMESPACE nsFileStreamHelpers
// Prototypes for common (non-template) implementations in the .cpp file which do not
// need the template args (charT, traits).
//========================================================================================
{
PRFileDesc* open(
NS_NAMESPACE_PROTOTYPE PRFileDesc* open(
const nsFilePath& inFile,
std::ios_base::openmode mode,
ios_base::openmode mode,
PRIntn accessMode);
} // nsFileStreamHelpers
} NS_NAMESPACE_END // nsFileStreamHelpers
//========================================================================================
// Template declarations
@ -122,9 +147,9 @@ namespace nsFileStreamHelpers
template<class charT, class traits>
class nsFileBufferT
//========================================================================================
: public std::basic_streambuf<charT, traits>
: public basic_streambuf<charT, traits>
{
typedef std::codecvt_base::result result;
typedef codecvt_base::result result;
public:
typedef charT char_type;
@ -135,8 +160,8 @@ public:
typedef typename traits::state_type state_type;
typedef nsFileBufferT<charT, traits> filebuf_type;
typedef std::codecvt<charT, char, state_type> ofacet_type;
typedef std::codecvt<char, charT, state_type> ifacet_type;
typedef codecvt<charT, char, state_type> ofacet_type;
typedef codecvt<char, charT, state_type> ifacet_type;
nsFileBufferT();
nsFileBufferT(PRFileDesc* pfile_arg);
@ -144,7 +169,7 @@ public:
bool is_open() const;
filebuf_type* open(
const nsFilePath& inFile,
std::ios_base::openmode mode,
ios_base::openmode mode,
PRIntn accessMode);
filebuf_type* close();
@ -153,28 +178,28 @@ protected:
virtual int_type pbackfail(int_type c=traits::eof());
virtual int_type underflow();
virtual pos_type seekoff(
off_type off, std::ios_base::seekdir way,
std::ios_base::openmode which=std::ios_base::in|std::ios_base::out);
off_type off, ios_base::seekdir way,
ios_base::openmode which=ios_base::in|ios_base::out);
virtual pos_type seekpos(pos_type sp,
std::ios_base::openmode which=std::ios_base::in|std::ios_base::out);
virtual std::basic_streambuf<charT, traits>* setbuf(char_type* s, std::streamsize n);
ios_base::openmode which=ios_base::in|ios_base::out);
virtual basic_streambuf<charT, traits>* setbuf(char_type* s, streamsize n);
virtual int sync();
virtual int_type uflow();
virtual void imbue(const std::locale& loc);
virtual std::streamsize showmanyc();
virtual std::streamsize xsgetn(char_type* s, std::streamsize n);
virtual std::streamsize xsputn(const char_type* s, std::streamsize n);
virtual void imbue(const locale& loc);
virtual streamsize showmanyc();
virtual streamsize xsgetn(char_type* s, streamsize n);
virtual streamsize xsputn(const char_type* s, streamsize n);
private:
PRFileDesc* mFileDesc;
std::ios_base::openmode mode_;
ios_base::openmode mode_;
}; // class nsFileBufferT
//========================================================================================
template<class charT, class traits>
class nsInputFileStreamT
//========================================================================================
: public std::basic_istream<charT, traits>
: public basic_istream<charT, traits>
{
typedef nsFileBufferT<charT, traits> filebuf_type;
@ -188,7 +213,7 @@ public:
nsInputFileStreamT();
explicit nsInputFileStreamT(
const nsFilePath& inFile,
std::ios_base::openmode mode=std::ios_base::in,
ios_base::openmode mode=ios_base::in,
PRIntn accessMode = 0x00400);
virtual ~nsInputFileStreamT();
@ -197,7 +222,7 @@ public:
inline bool is_open();
inline void open(
const nsFilePath& inFile,
std::ios_base::openmode mode=std::ios_base::in,
ios_base::openmode mode=ios_base::in,
PRIntn accessMode = 0x00400);
inline void close();
@ -209,7 +234,7 @@ private:
template<class charT, class traits>
class nsOutputFileStreamT
//========================================================================================
: public std::basic_ostream<charT, traits>
: public basic_ostream<charT, traits>
{
typedef nsFileBufferT<charT, traits> filebuf_type;
@ -283,7 +308,7 @@ template<class charT, class traits>
nsFileBufferT<charT, traits>::filebuf_type*
nsFileBufferT<charT, traits>::open(
const nsFilePath& inFile,
std::ios_base::openmode mode,
ios_base::openmode mode,
PRIntn accessMode)
//----------------------------------------------------------------------------------------
{
@ -319,8 +344,8 @@ nsFileBufferT<charT, traits>:: sync()
//----------------------------------------------------------------------------------------
template<class charT, class traits>
inline std::basic_streambuf<charT, traits>*
nsFileBufferT<charT, traits>::setbuf(char_type*, std::streamsize)
inline basic_streambuf<charT, traits>*
nsFileBufferT<charT, traits>::setbuf(char_type*, streamsize)
//----------------------------------------------------------------------------------------
{
return (!mFileDesc) ? 0 : this;
@ -383,7 +408,7 @@ inline nsFileBufferT<charT, traits>::int_type nsFileBufferT<charT, traits>::unde
//----------------------------------------------------------------------------------------
template<class charT, class traits>
std::streamsize nsFileBufferT<charT, traits>::xsputn(const char_type* s, std::streamsize n)
streamsize nsFileBufferT<charT, traits>::xsputn(const char_type* s, streamsize n)
//----------------------------------------------------------------------------------------
{
#ifdef NS_EXPLICIT_FUNC_TEMPLATE_ARG
@ -449,36 +474,36 @@ inline nsFileBufferT<charT, traits>::int_type nsFileBufferT<charT, traits>::uflo
//----------------------------------------------------------------------------------------
template<class charT, class traits>
inline std::streamsize nsFileBufferT<charT, traits>::xsgetn(char_type* s, std::streamsize n)
inline streamsize nsFileBufferT<charT, traits>::xsgetn(char_type* s, streamsize n)
//----------------------------------------------------------------------------------------
{
return mFileDesc ? (std::streamsize)PR_Read(mFileDesc, s, sizeof(char) * size_t(n)) : 0;
return mFileDesc ? (streamsize)PR_Read(mFileDesc, s, sizeof(char) * size_t(n)) : 0;
}
//----------------------------------------------------------------------------------------
template<class charT, class traits>
inline void nsFileBufferT<charT, traits>::imbue(const std::locale& loc_arg)
inline void nsFileBufferT<charT, traits>::imbue(const locale& loc_arg)
//----------------------------------------------------------------------------------------
{
loc = loc_arg;
}
template<class charT, class traits>
inline std::streamsize
inline streamsize
nsFileBufferT<charT, traits>::showmanyc()
{
return (std::streamsize)PR_Available(mFileDesc);
return (streamsize)PR_Available(mFileDesc);
}
//----------------------------------------------------------------------------------------
template<class charT, class traits>
nsFileBufferT<charT, traits>::pos_type nsFileBufferT<charT, traits>::seekoff(
off_type off,
std::ios_base::seekdir way,
std::ios_base::openmode /* which */)
ios_base::seekdir way,
ios_base::openmode /* which */)
//----------------------------------------------------------------------------------------
{
if (!mFileDesc || ((way&std::ios_base::beg) && off<0) || ((way&std::ios_base::end) && off > 0))
if (!mFileDesc || ((way&ios_base::beg) && off<0) || ((way&ios_base::end) && off > 0))
return pos_type(-1);
PRSeekWhence poseek = PR_SEEK_CUR;
switch (way)
@ -497,7 +522,7 @@ nsFileBufferT<charT, traits>::pos_type nsFileBufferT<charT, traits>::seekoff(
//----------------------------------------------------------------------------------------
template<class charT, class traits>
nsFileBufferT<charT, traits>::pos_type
nsFileBufferT<charT, traits>::seekpos(pos_type sp, std::ios_base::openmode)
nsFileBufferT<charT, traits>::seekpos(pos_type sp, ios_base::openmode)
//----------------------------------------------------------------------------------------
{
if (!mFileDesc || sp==pos_type(-1))
@ -656,7 +681,7 @@ inline void nsOutputFileStreamT<charT, traits>:: close()
//========================================================================================
template<class charT, class traits>
class nsIOFileStreamT : public std::basic_iostream<charT, traits>
class nsIOFileStreamT : public basic_iostream<charT, traits>
//========================================================================================
{
typedef nsFileBufferT<charT, traits> filebuf_type;
@ -671,7 +696,7 @@ public:
nsIOFileStreamT();
explicit nsIOFileStreamT(
const nsFilePath& inFile,
std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out,
ios_base::openmode mode = ios_base::in|ios_base::out,
PRIntn accessMode = 0x00600);
virtual ~nsIOFileStreamT();
@ -680,7 +705,7 @@ public:
inline bool is_open();
inline void open(
const nsFilePath& inFile,
std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out,
ios_base::openmode mode = ios_base::in|ios_base::out,
PRIntn accessMode = 0x00600);
inline void close();
@ -765,16 +790,16 @@ nsIOFileStreamT<charT, traits>::close()
// Specializations of the stream templates
//========================================================================================
typedef nsFileBufferT<char, std::char_traits<char> > nsFileBuffer;
typedef nsInputFileStreamT<char, std::char_traits<char> > nsInputFileStream;
typedef nsOutputFileStreamT<char, std::char_traits<char> > nsOutputFileStream;
typedef nsIOFileStreamT<char, std::char_traits<char> > nsIOFileStream;
typedef nsFileBufferT<char, char_traits<char> > nsFileBuffer;
typedef nsInputFileStreamT<char, char_traits<char> > nsInputFileStream;
typedef nsOutputFileStreamT<char, char_traits<char> > nsOutputFileStream;
typedef nsIOFileStreamT<char, char_traits<char> > nsIOFileStream;
#ifdef NS_USING_WIDE_CHAR
typedef nsFileBufferT<wchar_t, std::char_traits<wchar_t> > nsWideFileBuffer;
typedef nsInputFileStreamT<wchar_t, std::char_traits<wchar_t> > nsWideInputFileStream;
typedef nsOutputFileStreamT<wchar_t, std::char_traits<wchar_t> > nsWideOutputFileStream;
typedef nsIOFileStreamT<wchar_t, std::char_traits<wchar_t> > nsWideIOFileStream;
typedef nsFileBufferT<wchar_t, char_traits<wchar_t> > nsWideFileBuffer;
typedef nsInputFileStreamT<wchar_t, char_traits<wchar_t> > nsWideInputFileStream;
typedef nsOutputFileStreamT<wchar_t, char_traits<wchar_t> > nsWideOutputFileStream;
typedef nsIOFileStreamT<wchar_t, char_traits<wchar_t> > nsWideIOFileStream;
#endif // NS_USING_WIDE_CHAR
#endif /* _FILESTREAM_H_ */