This commit is contained in:
law%netscape.com 1998-12-09 01:04:53 +00:00
Родитель 5a28b7b2fd
Коммит e89799a864
10 изменённых файлов: 178 добавлений и 130 удалений

Просмотреть файл

@ -158,13 +158,13 @@ class nsNativeFileSpec
StringPtr GetLeafPName() { return mSpec.name; }
ConstStr255Param GetLeafPName() const { return mSpec.name; }
#else
bool Valid() const { return TRUE; } // Fixme.
bool Valid() const { return true; } // Fixme.
#endif
#if DEBUG
friend ostream& operator << (ostream& s, const nsNativeFileSpec& spec);
friend std::ostream& operator << (std::ostream& s, const nsNativeFileSpec& spec);
#endif
string GetLeafName() const;
std::string GetLeafName() const;
void SetLeafName(const std::string& inLeafName);
bool Exists() const;
void MakeUnique();
@ -175,7 +175,7 @@ class nsNativeFileSpec
#ifdef XP_MAC
FSSpec mSpec;
OSErr mError;
#elif defined(XP_UNIX) || defined(XP_WIN)
#elif defined(XP_UNIX) || defined(XP_PC)
std::string mPath;
#endif
}; // class nsNativeFileSpec
@ -321,7 +321,7 @@ inline void nsNativeFileSpec::operator = (const nsFilePath& inPath)
}
#endif //XP_UNIX
#if defined(XP_UNIX) || defined(XP_WIN)
#if defined(XP_UNIX) || defined(XP_PC)
//----------------------------------------------------------------------------------------
inline nsNativeFileSpec::nsNativeFileSpec(const nsNativeFileSpec& inSpec)
//----------------------------------------------------------------------------------------
@ -330,7 +330,7 @@ inline nsNativeFileSpec::nsNativeFileSpec(const nsNativeFileSpec& inSpec)
}
#endif //XP_UNIX
#if defined(XP_UNIX) || defined(XP_WIN)
#if defined(XP_UNIX) || defined(XP_PC)
//----------------------------------------------------------------------------------------
inline nsNativeFileSpec::nsNativeFileSpec(const std::string& inString)
//----------------------------------------------------------------------------------------
@ -339,7 +339,7 @@ inline nsNativeFileSpec::nsNativeFileSpec(const std::string& inString)
}
#endif //XP_UNIX
#if defined(XP_UNIX) || defined(XP_WIN)
#if defined(XP_UNIX) || defined(XP_PC)
//----------------------------------------------------------------------------------------
inline void nsNativeFileSpec::operator = (const nsNativeFileSpec& inSpec)
//----------------------------------------------------------------------------------------
@ -349,18 +349,18 @@ inline void nsNativeFileSpec::operator = (const nsNativeFileSpec& inSpec)
#endif //XP_UNIX
#if defined(XP_UNIX) || defined(XP_WIN)
#if defined(XP_UNIX) || defined(XP_PC)
//----------------------------------------------------------------------------------------
inline nsNativeFileSpec::operator = (const std::string& inString)
inline void nsNativeFileSpec::operator = (const std::string& inString)
//----------------------------------------------------------------------------------------
{
mPath = inString;
}
#endif //XP_UNIX
#if (defined(XP_UNIX) || defined(XP_WIN)) && DEBUG
#if (defined(XP_UNIX) || defined(XP_PC)) && DEBUG
//----------------------------------------------------------------------------------------
inline ostream& operator << (ostream& s, const nsNativeFileSpec& spec)
inline std::ostream& operator << (std::ostream& s, const nsNativeFileSpec& spec)
//----------------------------------------------------------------------------------------
{
return (s << (std::string&)spec.mPath);

Просмотреть файл

@ -110,7 +110,7 @@ namespace nsFileStreamHelpers
{
PRFileDesc* open(
const nsFilePath& inFile,
ios_base::openmode mode,
std::ios_base::openmode mode,
PRIntn accessMode);
} // nsFileStreamHelpers
@ -122,9 +122,9 @@ namespace nsFileStreamHelpers
template<class charT, class traits>
class nsFileBufferT
//========================================================================================
: public basic_streambuf<charT, traits>
: public std::basic_streambuf<charT, traits>
{
typedef codecvt_base::result result;
typedef std::codecvt_base::result result;
public:
typedef charT char_type;
@ -135,8 +135,8 @@ public:
typedef typename traits::state_type state_type;
typedef nsFileBufferT<charT, traits> filebuf_type;
typedef codecvt<charT, char, state_type> ofacet_type;
typedef codecvt<char, charT, state_type> ifacet_type;
typedef std::codecvt<charT, char, state_type> ofacet_type;
typedef std::codecvt<char, charT, state_type> ifacet_type;
nsFileBufferT();
nsFileBufferT(PRFileDesc* pfile_arg);
@ -144,7 +144,7 @@ public:
bool is_open() const;
filebuf_type* open(
const nsFilePath& inFile,
ios_base::openmode mode,
std::ios_base::openmode mode,
PRIntn accessMode);
filebuf_type* close();
@ -153,28 +153,28 @@ protected:
virtual int_type pbackfail(int_type c=traits::eof());
virtual int_type underflow();
virtual pos_type seekoff(
off_type off, ios_base::seekdir way,
ios_base::openmode which=ios_base::in|ios_base::out);
off_type off, std::ios_base::seekdir way,
std::ios_base::openmode which=std::ios_base::in|std::ios_base::out);
virtual pos_type seekpos(pos_type sp,
ios_base::openmode which=ios_base::in|ios_base::out);
virtual basic_streambuf<charT, traits>* setbuf(char_type* s, streamsize n);
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);
virtual int sync();
virtual int_type uflow();
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);
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);
private:
PRFileDesc* mFileDesc;
ios_base::openmode mode_;
std::ios_base::openmode mode_;
}; // class nsFileBufferT
//========================================================================================
template<class charT, class traits>
class nsInputFileStreamT
//========================================================================================
: public basic_istream<charT, traits>
: public std::basic_istream<charT, traits>
{
typedef nsFileBufferT<charT, traits> filebuf_type;
@ -188,7 +188,7 @@ public:
nsInputFileStreamT();
explicit nsInputFileStreamT(
const nsFilePath& inFile,
ios_base::openmode mode=ios_base::in,
std::ios_base::openmode mode=std::ios_base::in,
PRIntn accessMode = 0x00400);
virtual ~nsInputFileStreamT();
@ -197,7 +197,7 @@ public:
inline bool is_open();
inline void open(
const nsFilePath& inFile,
ios_base::openmode mode=ios_base::in,
std::ios_base::openmode mode=std::ios_base::in,
PRIntn accessMode = 0x00400);
inline void close();
@ -209,7 +209,7 @@ private:
template<class charT, class traits>
class nsOutputFileStreamT
//========================================================================================
: public basic_ostream<charT, traits>
: public std::basic_ostream<charT, traits>
{
typedef nsFileBufferT<charT, traits> filebuf_type;
@ -283,7 +283,7 @@ template<class charT, class traits>
nsFileBufferT<charT, traits>::filebuf_type*
nsFileBufferT<charT, traits>::open(
const nsFilePath& inFile,
ios_base::openmode mode,
std::ios_base::openmode mode,
PRIntn accessMode)
//----------------------------------------------------------------------------------------
{
@ -319,8 +319,8 @@ nsFileBufferT<charT, traits>:: sync()
//----------------------------------------------------------------------------------------
template<class charT, class traits>
inline basic_streambuf<charT, traits>*
nsFileBufferT<charT, traits>::setbuf(char_type*, streamsize)
inline std::basic_streambuf<charT, traits>*
nsFileBufferT<charT, traits>::setbuf(char_type*, std::streamsize)
//----------------------------------------------------------------------------------------
{
return (!mFileDesc) ? 0 : this;
@ -383,7 +383,7 @@ inline nsFileBufferT<charT, traits>::int_type nsFileBufferT<charT, traits>::unde
//----------------------------------------------------------------------------------------
template<class charT, class traits>
streamsize nsFileBufferT<charT, traits>::xsputn(const char_type* s, streamsize n)
std::streamsize nsFileBufferT<charT, traits>::xsputn(const char_type* s, std::streamsize n)
//----------------------------------------------------------------------------------------
{
#ifdef NS_EXPLICIT_FUNC_TEMPLATE_ARG
@ -449,36 +449,36 @@ inline nsFileBufferT<charT, traits>::int_type nsFileBufferT<charT, traits>::uflo
//----------------------------------------------------------------------------------------
template<class charT, class traits>
inline streamsize nsFileBufferT<charT, traits>::xsgetn(char_type* s, streamsize n)
inline std::streamsize nsFileBufferT<charT, traits>::xsgetn(char_type* s, std::streamsize n)
//----------------------------------------------------------------------------------------
{
return mFileDesc ? (streamsize)PR_Read(mFileDesc, s, sizeof(char) * size_t(n)) : 0;
return mFileDesc ? (std::streamsize)PR_Read(mFileDesc, s, sizeof(char) * size_t(n)) : 0;
}
//----------------------------------------------------------------------------------------
template<class charT, class traits>
inline void nsFileBufferT<charT, traits>::imbue(const locale& loc_arg)
inline void nsFileBufferT<charT, traits>::imbue(const std::locale& loc_arg)
//----------------------------------------------------------------------------------------
{
loc = loc_arg;
}
template<class charT, class traits>
inline streamsize
inline std::streamsize
nsFileBufferT<charT, traits>::showmanyc()
{
return (streamsize)PR_Available(mFileDesc);
return (std::streamsize)PR_Available(mFileDesc);
}
//----------------------------------------------------------------------------------------
template<class charT, class traits>
nsFileBufferT<charT, traits>::pos_type nsFileBufferT<charT, traits>::seekoff(
off_type off,
ios_base::seekdir way,
ios_base::openmode /* which */)
std::ios_base::seekdir way,
std::ios_base::openmode /* which */)
//----------------------------------------------------------------------------------------
{
if (!mFileDesc || ((way&ios_base::beg) && off<0) || ((way&ios_base::end) && off > 0))
if (!mFileDesc || ((way&std::ios_base::beg) && off<0) || ((way&std::ios_base::end) && off > 0))
return pos_type(-1);
PRSeekWhence poseek = PR_SEEK_CUR;
switch (way)
@ -497,7 +497,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, ios_base::openmode)
nsFileBufferT<charT, traits>::seekpos(pos_type sp, std::ios_base::openmode)
//----------------------------------------------------------------------------------------
{
if (!mFileDesc || sp==pos_type(-1))
@ -656,7 +656,7 @@ inline void nsOutputFileStreamT<charT, traits>:: close()
//========================================================================================
template<class charT, class traits>
class nsIOFileStreamT : public basic_iostream<charT, traits>
class nsIOFileStreamT : public std::basic_iostream<charT, traits>
//========================================================================================
{
typedef nsFileBufferT<charT, traits> filebuf_type;
@ -671,7 +671,7 @@ public:
nsIOFileStreamT();
explicit nsIOFileStreamT(
const nsFilePath& inFile,
ios_base::openmode mode = ios_base::in|ios_base::out,
std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out,
PRIntn accessMode = 0x00600);
virtual ~nsIOFileStreamT();
@ -680,7 +680,7 @@ public:
inline bool is_open();
inline void open(
const nsFilePath& inFile,
ios_base::openmode mode = ios_base::in|ios_base::out,
std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out,
PRIntn accessMode = 0x00600);
inline void close();
@ -765,16 +765,16 @@ nsIOFileStreamT<charT, traits>::close()
// Specializations of the stream templates
//========================================================================================
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;
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;
#ifdef NS_USING_WIDE_CHAR
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;
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;
#endif // NS_USING_WIDE_CHAR
#endif /* _FILESTREAM_H_ */

Просмотреть файл

@ -70,7 +70,7 @@ std::string nsFileSpecHelpers::GetLeaf(const std::string& inPath, char inSeparat
#ifdef XP_MAC
#include "nsFileSpecMac.cpp" // Macintosh-specific implementations
#elif defined(XP_WIN)
#elif defined(XP_PC)
#include "nsFileSpecWin.cpp" // Windows-specific implementations
#elif defined(XP_UNIX)
#include "nsFileSpecUnix.cpp" // Unix-specific implementations
@ -128,7 +128,7 @@ void nsFileURL::operator = (const nsFileURL& inOther)
nsFileURL::nsFileURL(const nsFilePath& inOther)
//----------------------------------------------------------------------------------------
{
mURL = kFileURLPrefix + ((string&)inOther);
mURL = kFileURLPrefix + ((std::string&)inOther);
#ifdef XP_MAC
mNativeFileSpec = inOther.GetNativeSpec();
#endif
@ -137,7 +137,7 @@ nsFileURL::nsFileURL(const nsFilePath& inOther)
void nsFileURL::operator = (const nsFilePath& inOther)
//----------------------------------------------------------------------------------------
{
mURL = kFileURLPrefix + ((string&)inOther);
mURL = kFileURLPrefix + ((std::string&)inOther);
#ifdef XP_MAC
mNativeFileSpec = inOther.GetNativeSpec();
#endif
@ -180,8 +180,8 @@ nsFilePath::nsFilePath(const std::string& inString)
//----------------------------------------------------------------------------------------
nsFilePath::nsFilePath(const nsFileURL& inOther)
//----------------------------------------------------------------------------------------
: mPath(((string&)inOther).substr(
kFileURLPrefixLength, ((string&)inOther).length() - kFileURLPrefixLength))
: mPath(((std::string&)inOther).substr(
kFileURLPrefixLength, ((std::string&)inOther).length() - kFileURLPrefixLength))
#ifdef XP_MAC
, mNativeFileSpec(inOther.GetNativeSpec())
#endif
@ -203,8 +203,8 @@ void nsFilePath::operator = (const std::string& inString)
void nsFilePath::operator = (const nsFileURL& inOther)
//----------------------------------------------------------------------------------------
{
mPath = ((string&)inOther).substr(
kFileURLPrefixLength, ((string&)inOther).length() - kFileURLPrefixLength);
mPath = ((std::string&)inOther).substr(
kFileURLPrefixLength, ((std::string&)inOther).length() - kFileURLPrefixLength);
#ifdef XP_MAC
mNativeFileSpec = inOther.GetNativeSpec();
#endif
@ -258,8 +258,8 @@ void nsNativeFileSpec::MakeUnique()
if ( ++index > 999 ) // something's very wrong
return;
char buf[nsFileSpecHelpers::kMaxFilenameLength + 1];
ostrstream newName(buf, nsFileSpecHelpers::kMaxFilenameLength);
newName << altName.c_str() << "-" << index << suffix.c_str() << ends;
std::ostrstream newName(buf, nsFileSpecHelpers::kMaxFilenameLength);
newName << altName.c_str() << "-" << index << suffix.c_str() << std::ends;
SetLeafName(newName.str()); // or: SetLeafName(buf)
}
} // nsNativeFileSpec::MakeUnique

Просмотреть файл

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

Просмотреть файл

@ -41,17 +41,39 @@ void nsNativeFileSpec::operator = (const nsFilePath& inPath)
}
} // nsNativeFileSpec::operator =
//----------------------------------------------------------------------------------------
nsFilePath::nsFilePath(const nsNativeFileSpec& inSpec)
//----------------------------------------------------------------------------------------
{
// Convert '\' to '/'
std::string& str = (std::string&)inSpec;
for (std::string::size_type i = 0; i < str.length(); i++)
{
char c = str[i];
if (c == '\\')
c = '/';
mPath.append(&c, 1);
}
} // nsFilePath::nsFilePath
//----------------------------------------------------------------------------------------
void nsNativeFileSpec::SetLeafName(const std::string& inLeafName)
//----------------------------------------------------------------------------------------
{
nsFileHelpers::LeafReplace(mPath, '\\', inLeafName);
nsFileSpecHelpers::LeafReplace(mPath, '\\', inLeafName);
} // nsNativeFileSpec::SetLeafName
//----------------------------------------------------------------------------------------
std::string nsNativeFileSpec::GetLeafName() const
//----------------------------------------------------------------------------------------
{
return nsFileHelpers::GetLeaf(mPath, '\\');
return nsFileSpecHelpers::GetLeaf(mPath, '\\');
} // nsNativeFileSpec::GetLeafName
//----------------------------------------------------------------------------------------
bool nsNativeFileSpec::Exists() const
//----------------------------------------------------------------------------------------
{
return false; // fixme
} // nsNativeFileSpec::Exists

Просмотреть файл

@ -70,7 +70,7 @@ std::string nsFileSpecHelpers::GetLeaf(const std::string& inPath, char inSeparat
#ifdef XP_MAC
#include "nsFileSpecMac.cpp" // Macintosh-specific implementations
#elif defined(XP_WIN)
#elif defined(XP_PC)
#include "nsFileSpecWin.cpp" // Windows-specific implementations
#elif defined(XP_UNIX)
#include "nsFileSpecUnix.cpp" // Unix-specific implementations
@ -128,7 +128,7 @@ void nsFileURL::operator = (const nsFileURL& inOther)
nsFileURL::nsFileURL(const nsFilePath& inOther)
//----------------------------------------------------------------------------------------
{
mURL = kFileURLPrefix + ((string&)inOther);
mURL = kFileURLPrefix + ((std::string&)inOther);
#ifdef XP_MAC
mNativeFileSpec = inOther.GetNativeSpec();
#endif
@ -137,7 +137,7 @@ nsFileURL::nsFileURL(const nsFilePath& inOther)
void nsFileURL::operator = (const nsFilePath& inOther)
//----------------------------------------------------------------------------------------
{
mURL = kFileURLPrefix + ((string&)inOther);
mURL = kFileURLPrefix + ((std::string&)inOther);
#ifdef XP_MAC
mNativeFileSpec = inOther.GetNativeSpec();
#endif
@ -180,8 +180,8 @@ nsFilePath::nsFilePath(const std::string& inString)
//----------------------------------------------------------------------------------------
nsFilePath::nsFilePath(const nsFileURL& inOther)
//----------------------------------------------------------------------------------------
: mPath(((string&)inOther).substr(
kFileURLPrefixLength, ((string&)inOther).length() - kFileURLPrefixLength))
: mPath(((std::string&)inOther).substr(
kFileURLPrefixLength, ((std::string&)inOther).length() - kFileURLPrefixLength))
#ifdef XP_MAC
, mNativeFileSpec(inOther.GetNativeSpec())
#endif
@ -203,8 +203,8 @@ void nsFilePath::operator = (const std::string& inString)
void nsFilePath::operator = (const nsFileURL& inOther)
//----------------------------------------------------------------------------------------
{
mPath = ((string&)inOther).substr(
kFileURLPrefixLength, ((string&)inOther).length() - kFileURLPrefixLength);
mPath = ((std::string&)inOther).substr(
kFileURLPrefixLength, ((std::string&)inOther).length() - kFileURLPrefixLength);
#ifdef XP_MAC
mNativeFileSpec = inOther.GetNativeSpec();
#endif
@ -258,8 +258,8 @@ void nsNativeFileSpec::MakeUnique()
if ( ++index > 999 ) // something's very wrong
return;
char buf[nsFileSpecHelpers::kMaxFilenameLength + 1];
ostrstream newName(buf, nsFileSpecHelpers::kMaxFilenameLength);
newName << altName.c_str() << "-" << index << suffix.c_str() << ends;
std::ostrstream newName(buf, nsFileSpecHelpers::kMaxFilenameLength);
newName << altName.c_str() << "-" << index << suffix.c_str() << std::ends;
SetLeafName(newName.str()); // or: SetLeafName(buf)
}
} // nsNativeFileSpec::MakeUnique

Просмотреть файл

@ -158,13 +158,13 @@ class nsNativeFileSpec
StringPtr GetLeafPName() { return mSpec.name; }
ConstStr255Param GetLeafPName() const { return mSpec.name; }
#else
bool Valid() const { return TRUE; } // Fixme.
bool Valid() const { return true; } // Fixme.
#endif
#if DEBUG
friend ostream& operator << (ostream& s, const nsNativeFileSpec& spec);
friend std::ostream& operator << (std::ostream& s, const nsNativeFileSpec& spec);
#endif
string GetLeafName() const;
std::string GetLeafName() const;
void SetLeafName(const std::string& inLeafName);
bool Exists() const;
void MakeUnique();
@ -175,7 +175,7 @@ class nsNativeFileSpec
#ifdef XP_MAC
FSSpec mSpec;
OSErr mError;
#elif defined(XP_UNIX) || defined(XP_WIN)
#elif defined(XP_UNIX) || defined(XP_PC)
std::string mPath;
#endif
}; // class nsNativeFileSpec
@ -321,7 +321,7 @@ inline void nsNativeFileSpec::operator = (const nsFilePath& inPath)
}
#endif //XP_UNIX
#if defined(XP_UNIX) || defined(XP_WIN)
#if defined(XP_UNIX) || defined(XP_PC)
//----------------------------------------------------------------------------------------
inline nsNativeFileSpec::nsNativeFileSpec(const nsNativeFileSpec& inSpec)
//----------------------------------------------------------------------------------------
@ -330,7 +330,7 @@ inline nsNativeFileSpec::nsNativeFileSpec(const nsNativeFileSpec& inSpec)
}
#endif //XP_UNIX
#if defined(XP_UNIX) || defined(XP_WIN)
#if defined(XP_UNIX) || defined(XP_PC)
//----------------------------------------------------------------------------------------
inline nsNativeFileSpec::nsNativeFileSpec(const std::string& inString)
//----------------------------------------------------------------------------------------
@ -339,7 +339,7 @@ inline nsNativeFileSpec::nsNativeFileSpec(const std::string& inString)
}
#endif //XP_UNIX
#if defined(XP_UNIX) || defined(XP_WIN)
#if defined(XP_UNIX) || defined(XP_PC)
//----------------------------------------------------------------------------------------
inline void nsNativeFileSpec::operator = (const nsNativeFileSpec& inSpec)
//----------------------------------------------------------------------------------------
@ -349,18 +349,18 @@ inline void nsNativeFileSpec::operator = (const nsNativeFileSpec& inSpec)
#endif //XP_UNIX
#if defined(XP_UNIX) || defined(XP_WIN)
#if defined(XP_UNIX) || defined(XP_PC)
//----------------------------------------------------------------------------------------
inline nsNativeFileSpec::operator = (const std::string& inString)
inline void nsNativeFileSpec::operator = (const std::string& inString)
//----------------------------------------------------------------------------------------
{
mPath = inString;
}
#endif //XP_UNIX
#if (defined(XP_UNIX) || defined(XP_WIN)) && DEBUG
#if (defined(XP_UNIX) || defined(XP_PC)) && DEBUG
//----------------------------------------------------------------------------------------
inline ostream& operator << (ostream& s, const nsNativeFileSpec& spec)
inline std::ostream& operator << (std::ostream& s, const nsNativeFileSpec& spec)
//----------------------------------------------------------------------------------------
{
return (s << (std::string&)spec.mPath);

Просмотреть файл

@ -41,17 +41,39 @@ void nsNativeFileSpec::operator = (const nsFilePath& inPath)
}
} // nsNativeFileSpec::operator =
//----------------------------------------------------------------------------------------
nsFilePath::nsFilePath(const nsNativeFileSpec& inSpec)
//----------------------------------------------------------------------------------------
{
// Convert '\' to '/'
std::string& str = (std::string&)inSpec;
for (std::string::size_type i = 0; i < str.length(); i++)
{
char c = str[i];
if (c == '\\')
c = '/';
mPath.append(&c, 1);
}
} // nsFilePath::nsFilePath
//----------------------------------------------------------------------------------------
void nsNativeFileSpec::SetLeafName(const std::string& inLeafName)
//----------------------------------------------------------------------------------------
{
nsFileHelpers::LeafReplace(mPath, '\\', inLeafName);
nsFileSpecHelpers::LeafReplace(mPath, '\\', inLeafName);
} // nsNativeFileSpec::SetLeafName
//----------------------------------------------------------------------------------------
std::string nsNativeFileSpec::GetLeafName() const
//----------------------------------------------------------------------------------------
{
return nsFileHelpers::GetLeaf(mPath, '\\');
return nsFileSpecHelpers::GetLeaf(mPath, '\\');
} // nsNativeFileSpec::GetLeafName
//----------------------------------------------------------------------------------------
bool nsNativeFileSpec::Exists() const
//----------------------------------------------------------------------------------------
{
return false; // fixme
} // nsNativeFileSpec::Exists

Просмотреть файл

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

Просмотреть файл

@ -110,7 +110,7 @@ namespace nsFileStreamHelpers
{
PRFileDesc* open(
const nsFilePath& inFile,
ios_base::openmode mode,
std::ios_base::openmode mode,
PRIntn accessMode);
} // nsFileStreamHelpers
@ -122,9 +122,9 @@ namespace nsFileStreamHelpers
template<class charT, class traits>
class nsFileBufferT
//========================================================================================
: public basic_streambuf<charT, traits>
: public std::basic_streambuf<charT, traits>
{
typedef codecvt_base::result result;
typedef std::codecvt_base::result result;
public:
typedef charT char_type;
@ -135,8 +135,8 @@ public:
typedef typename traits::state_type state_type;
typedef nsFileBufferT<charT, traits> filebuf_type;
typedef codecvt<charT, char, state_type> ofacet_type;
typedef codecvt<char, charT, state_type> ifacet_type;
typedef std::codecvt<charT, char, state_type> ofacet_type;
typedef std::codecvt<char, charT, state_type> ifacet_type;
nsFileBufferT();
nsFileBufferT(PRFileDesc* pfile_arg);
@ -144,7 +144,7 @@ public:
bool is_open() const;
filebuf_type* open(
const nsFilePath& inFile,
ios_base::openmode mode,
std::ios_base::openmode mode,
PRIntn accessMode);
filebuf_type* close();
@ -153,28 +153,28 @@ protected:
virtual int_type pbackfail(int_type c=traits::eof());
virtual int_type underflow();
virtual pos_type seekoff(
off_type off, ios_base::seekdir way,
ios_base::openmode which=ios_base::in|ios_base::out);
off_type off, std::ios_base::seekdir way,
std::ios_base::openmode which=std::ios_base::in|std::ios_base::out);
virtual pos_type seekpos(pos_type sp,
ios_base::openmode which=ios_base::in|ios_base::out);
virtual basic_streambuf<charT, traits>* setbuf(char_type* s, streamsize n);
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);
virtual int sync();
virtual int_type uflow();
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);
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);
private:
PRFileDesc* mFileDesc;
ios_base::openmode mode_;
std::ios_base::openmode mode_;
}; // class nsFileBufferT
//========================================================================================
template<class charT, class traits>
class nsInputFileStreamT
//========================================================================================
: public basic_istream<charT, traits>
: public std::basic_istream<charT, traits>
{
typedef nsFileBufferT<charT, traits> filebuf_type;
@ -188,7 +188,7 @@ public:
nsInputFileStreamT();
explicit nsInputFileStreamT(
const nsFilePath& inFile,
ios_base::openmode mode=ios_base::in,
std::ios_base::openmode mode=std::ios_base::in,
PRIntn accessMode = 0x00400);
virtual ~nsInputFileStreamT();
@ -197,7 +197,7 @@ public:
inline bool is_open();
inline void open(
const nsFilePath& inFile,
ios_base::openmode mode=ios_base::in,
std::ios_base::openmode mode=std::ios_base::in,
PRIntn accessMode = 0x00400);
inline void close();
@ -209,7 +209,7 @@ private:
template<class charT, class traits>
class nsOutputFileStreamT
//========================================================================================
: public basic_ostream<charT, traits>
: public std::basic_ostream<charT, traits>
{
typedef nsFileBufferT<charT, traits> filebuf_type;
@ -283,7 +283,7 @@ template<class charT, class traits>
nsFileBufferT<charT, traits>::filebuf_type*
nsFileBufferT<charT, traits>::open(
const nsFilePath& inFile,
ios_base::openmode mode,
std::ios_base::openmode mode,
PRIntn accessMode)
//----------------------------------------------------------------------------------------
{
@ -319,8 +319,8 @@ nsFileBufferT<charT, traits>:: sync()
//----------------------------------------------------------------------------------------
template<class charT, class traits>
inline basic_streambuf<charT, traits>*
nsFileBufferT<charT, traits>::setbuf(char_type*, streamsize)
inline std::basic_streambuf<charT, traits>*
nsFileBufferT<charT, traits>::setbuf(char_type*, std::streamsize)
//----------------------------------------------------------------------------------------
{
return (!mFileDesc) ? 0 : this;
@ -383,7 +383,7 @@ inline nsFileBufferT<charT, traits>::int_type nsFileBufferT<charT, traits>::unde
//----------------------------------------------------------------------------------------
template<class charT, class traits>
streamsize nsFileBufferT<charT, traits>::xsputn(const char_type* s, streamsize n)
std::streamsize nsFileBufferT<charT, traits>::xsputn(const char_type* s, std::streamsize n)
//----------------------------------------------------------------------------------------
{
#ifdef NS_EXPLICIT_FUNC_TEMPLATE_ARG
@ -449,36 +449,36 @@ inline nsFileBufferT<charT, traits>::int_type nsFileBufferT<charT, traits>::uflo
//----------------------------------------------------------------------------------------
template<class charT, class traits>
inline streamsize nsFileBufferT<charT, traits>::xsgetn(char_type* s, streamsize n)
inline std::streamsize nsFileBufferT<charT, traits>::xsgetn(char_type* s, std::streamsize n)
//----------------------------------------------------------------------------------------
{
return mFileDesc ? (streamsize)PR_Read(mFileDesc, s, sizeof(char) * size_t(n)) : 0;
return mFileDesc ? (std::streamsize)PR_Read(mFileDesc, s, sizeof(char) * size_t(n)) : 0;
}
//----------------------------------------------------------------------------------------
template<class charT, class traits>
inline void nsFileBufferT<charT, traits>::imbue(const locale& loc_arg)
inline void nsFileBufferT<charT, traits>::imbue(const std::locale& loc_arg)
//----------------------------------------------------------------------------------------
{
loc = loc_arg;
}
template<class charT, class traits>
inline streamsize
inline std::streamsize
nsFileBufferT<charT, traits>::showmanyc()
{
return (streamsize)PR_Available(mFileDesc);
return (std::streamsize)PR_Available(mFileDesc);
}
//----------------------------------------------------------------------------------------
template<class charT, class traits>
nsFileBufferT<charT, traits>::pos_type nsFileBufferT<charT, traits>::seekoff(
off_type off,
ios_base::seekdir way,
ios_base::openmode /* which */)
std::ios_base::seekdir way,
std::ios_base::openmode /* which */)
//----------------------------------------------------------------------------------------
{
if (!mFileDesc || ((way&ios_base::beg) && off<0) || ((way&ios_base::end) && off > 0))
if (!mFileDesc || ((way&std::ios_base::beg) && off<0) || ((way&std::ios_base::end) && off > 0))
return pos_type(-1);
PRSeekWhence poseek = PR_SEEK_CUR;
switch (way)
@ -497,7 +497,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, ios_base::openmode)
nsFileBufferT<charT, traits>::seekpos(pos_type sp, std::ios_base::openmode)
//----------------------------------------------------------------------------------------
{
if (!mFileDesc || sp==pos_type(-1))
@ -656,7 +656,7 @@ inline void nsOutputFileStreamT<charT, traits>:: close()
//========================================================================================
template<class charT, class traits>
class nsIOFileStreamT : public basic_iostream<charT, traits>
class nsIOFileStreamT : public std::basic_iostream<charT, traits>
//========================================================================================
{
typedef nsFileBufferT<charT, traits> filebuf_type;
@ -671,7 +671,7 @@ public:
nsIOFileStreamT();
explicit nsIOFileStreamT(
const nsFilePath& inFile,
ios_base::openmode mode = ios_base::in|ios_base::out,
std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out,
PRIntn accessMode = 0x00600);
virtual ~nsIOFileStreamT();
@ -680,7 +680,7 @@ public:
inline bool is_open();
inline void open(
const nsFilePath& inFile,
ios_base::openmode mode = ios_base::in|ios_base::out,
std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out,
PRIntn accessMode = 0x00600);
inline void close();
@ -765,16 +765,16 @@ nsIOFileStreamT<charT, traits>::close()
// Specializations of the stream templates
//========================================================================================
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;
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;
#ifdef NS_USING_WIDE_CHAR
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;
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;
#endif // NS_USING_WIDE_CHAR
#endif /* _FILESTREAM_H_ */