1998-12-08 05:15:50 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0(the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright(C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
|
1998-12-09 01:45:42 +03:00
|
|
|
// First checked in on 98/11/20 by John R. McMullen in the wrong directory.
|
|
|
|
// Checked in again 98/12/04.
|
|
|
|
// Polished version 98/12/08.
|
1999-02-25 23:49:47 +03:00
|
|
|
// Completely rewritten to integrate with nsIInputStream and nsIOutputStream (the
|
|
|
|
// xpcom stream objects.
|
1998-12-08 05:15:50 +03:00
|
|
|
|
1998-12-09 01:45:42 +03:00
|
|
|
//========================================================================================
|
|
|
|
//
|
|
|
|
// Classes defined:
|
|
|
|
//
|
1999-02-25 23:49:47 +03:00
|
|
|
// nsInputStream, nsOutputStream
|
|
|
|
// These are the lightweight STATICALLY LINKED wrappers for
|
|
|
|
// the xpcom objects nsIInputStream and nsIOutputstream.
|
|
|
|
// Possible uses:
|
|
|
|
// If you are implementing a function that accepts one of these xpcom
|
|
|
|
// streams, just make one of these little jobbies on the stack, and
|
|
|
|
// the handy << or >> notation can be yours.
|
|
|
|
//
|
1998-12-19 02:06:54 +03:00
|
|
|
// nsInputFileStream, nsOutputFileStream
|
1999-02-25 23:49:47 +03:00
|
|
|
// These are the STATICALLY LINKED versions of the file i/o streams,
|
|
|
|
// which wrap the NSPR file i/o plus console i/o.
|
|
|
|
//
|
|
|
|
// Related files:
|
|
|
|
// prio.h the NSPR file i/o C API), which is wrapped by
|
|
|
|
// THIS FILE statically linked C++ wrappers, which in turn are wrapped by
|
|
|
|
// nsIFileStream.h COM wrappers for this file, which are wrapped by
|
|
|
|
// nsAutoFileStream.h more easily used, nicer syntax wrappers for the
|
|
|
|
// COMified ones. Wrapper of a wrapper of a wrapper.
|
1998-12-09 01:45:42 +03:00
|
|
|
//
|
|
|
|
// This suite provide the following services:
|
|
|
|
//
|
|
|
|
// 1. Encapsulates all platform-specific file details, so that file i/o
|
|
|
|
// can be done correctly without any platform #ifdefs
|
|
|
|
//
|
|
|
|
// 2. Uses NSPR file services (NOT ansi file I/O), in order to get best
|
|
|
|
// native performance. This performance difference is especially large on
|
|
|
|
// macintosh.
|
|
|
|
//
|
1998-12-19 02:06:54 +03:00
|
|
|
// 3. Allows all the power of the ansi stream syntax.
|
1998-12-09 01:45:42 +03:00
|
|
|
//
|
|
|
|
// Basic example:
|
|
|
|
//
|
1999-02-25 23:49:47 +03:00
|
|
|
// nsFileSpec myPath("/Development/iotest.txt");
|
1998-12-09 01:45:42 +03:00
|
|
|
//
|
|
|
|
// nsOutputFileStream testStream(myPath);
|
1998-12-19 02:06:54 +03:00
|
|
|
// testStream << "Hello World" << nsEndl;
|
1998-12-09 01:45:42 +03:00
|
|
|
//
|
1999-02-25 23:49:47 +03:00
|
|
|
// 4. Requires streams to be constructed using typesafe nsFileSpec specifier
|
|
|
|
// (not the notorious and bug prone const char*), namely nsFileSpec. See
|
1998-12-09 01:45:42 +03:00
|
|
|
// nsFileSpec.h for more details.
|
|
|
|
//
|
1998-12-16 01:45:09 +03:00
|
|
|
// 5. Fixes a bug that have been there for a long time, and
|
|
|
|
// is inevitable if you use NSPR alone:
|
1998-12-09 01:45:42 +03:00
|
|
|
//
|
|
|
|
// The problem on platforms (Macintosh) in which a path does not fully
|
1998-12-16 01:45:09 +03:00
|
|
|
// specify a file, because two volumes can have the same name.
|
1998-12-09 01:45:42 +03:00
|
|
|
//
|
|
|
|
// Not yet provided:
|
|
|
|
//
|
|
|
|
// Endian-awareness for reading and writing crossplatform binary files. At this
|
|
|
|
// time there seems to be no demand for this.
|
|
|
|
//
|
|
|
|
//========================================================================================
|
|
|
|
|
|
|
|
#ifndef _FILESTREAM_H_
|
|
|
|
#define _FILESTREAM_H_
|
1998-12-08 05:15:50 +03:00
|
|
|
|
1998-12-12 04:25:32 +03:00
|
|
|
#include "nscore.h"
|
1998-12-11 04:42:04 +03:00
|
|
|
|
1998-12-09 01:45:42 +03:00
|
|
|
#ifdef XP_MAC
|
|
|
|
#include "pprio.h" // To get PR_ImportFile
|
|
|
|
#else
|
1998-12-08 05:15:50 +03:00
|
|
|
#include "prio.h"
|
1998-12-09 01:45:42 +03:00
|
|
|
#endif
|
1999-02-25 23:49:47 +03:00
|
|
|
|
|
|
|
#include "nsIFileStream.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
class nsFileSpec;
|
|
|
|
class nsInputFileStream;
|
|
|
|
class nsOutputFileStream;
|
1998-12-08 05:15:50 +03:00
|
|
|
|
1998-12-09 01:45:42 +03:00
|
|
|
//========================================================================================
|
|
|
|
// Compiler-specific macros, as needed
|
|
|
|
//========================================================================================
|
1998-12-11 04:42:04 +03:00
|
|
|
#if !defined(NS_USING_NAMESPACE) && (defined(__MWERKS__) || defined(XP_PC))
|
1998-12-09 08:09:28 +03:00
|
|
|
#define NS_USING_NAMESPACE
|
|
|
|
#endif
|
|
|
|
|
1998-12-16 01:45:09 +03:00
|
|
|
#if !defined(NS_USING_STL) && (defined(__MWERKS__) || defined(XP_PC))
|
|
|
|
#define NS_USING_STL
|
|
|
|
#endif
|
|
|
|
|
1998-12-09 08:09:28 +03:00
|
|
|
#ifdef NS_USING_NAMESPACE
|
1998-12-16 01:45:09 +03:00
|
|
|
|
1998-12-09 08:09:28 +03:00
|
|
|
#define NS_NAMESPACE_PROTOTYPE
|
|
|
|
#define NS_NAMESPACE namespace
|
|
|
|
#define NS_NAMESPACE_END
|
1998-12-16 01:45:09 +03:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define NS_NAMESPACE_PROTOTYPE static
|
|
|
|
#define NS_NAMESPACE struct
|
|
|
|
#define NS_NAMESPACE_END ;
|
1998-12-11 21:17:22 +03:00
|
|
|
|
1998-12-16 01:45:09 +03:00
|
|
|
#endif // NS_USING_NAMESPACE
|
|
|
|
|
1998-12-29 03:24:32 +03:00
|
|
|
#ifndef XP_MAC
|
|
|
|
// PR_STDOUT and PR_STDIN are fatal on Macintosh. So for console i/o, we must use the std
|
|
|
|
// stream stuff instead. However, we have to require that cout and cin are passed in
|
|
|
|
// to the constructor because in the current build, there is a copy in the base.shlb,
|
|
|
|
// and another in the caller's file. Passing it in as a parameter ensures that the
|
|
|
|
// caller and this library are using the same global object. Groan.
|
|
|
|
//
|
|
|
|
// Unix currently does not support iostreams at all. Their compilers do not support
|
|
|
|
// ANSI C++, or even ARM C++.
|
|
|
|
//
|
|
|
|
// Windows supports them, but only if you turn on the -GX compile flag, to support
|
|
|
|
// exceptions.
|
|
|
|
|
|
|
|
// Catch 22.
|
|
|
|
#define NS_USE_PR_STDIO
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NS_USE_PR_STDIO
|
|
|
|
class istream;
|
|
|
|
class ostream;
|
|
|
|
#define CONSOLE_IN 0
|
|
|
|
#define CONSOLE_OUT 0
|
|
|
|
#else
|
1998-12-19 02:06:54 +03:00
|
|
|
#include <iostream>
|
|
|
|
using std::istream;
|
|
|
|
using std::ostream;
|
1998-12-29 03:24:32 +03:00
|
|
|
#define CONSOLE_IN &std::cin
|
|
|
|
#define CONSOLE_OUT &std::cout
|
1998-12-08 05:15:50 +03:00
|
|
|
#endif
|
1998-12-16 01:45:09 +03:00
|
|
|
|
1998-12-11 21:17:22 +03:00
|
|
|
//=========================== End Compiler-specific macros ===============================
|
1998-12-09 01:45:42 +03:00
|
|
|
|
|
|
|
//========================================================================================
|
1999-02-25 23:49:47 +03:00
|
|
|
class NS_BASE nsInputStream
|
|
|
|
// This is a convenience class, for use on the STACK ("new" junkies: get detoxed first).
|
|
|
|
// Given a COM-style stream, this allows you to use the >> operators. It also acquires and
|
|
|
|
// reference counts its stream.
|
|
|
|
// Please read the comments at the top of this file
|
1998-12-08 05:15:50 +03:00
|
|
|
//========================================================================================
|
|
|
|
{
|
|
|
|
public:
|
1999-02-25 23:49:47 +03:00
|
|
|
nsInputStream(nsIInputStream* inStream)
|
|
|
|
: mInputStream(do_QueryInterface(inStream))
|
|
|
|
, mEOF(PR_FALSE)
|
|
|
|
{}
|
|
|
|
virtual ~nsInputStream();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> GetIStream() const
|
|
|
|
{
|
|
|
|
return mInputStream;
|
|
|
|
}
|
|
|
|
char eof() const { return mEOF; }
|
|
|
|
char get();
|
|
|
|
PRInt32 read(void* s, PRInt32 n)
|
|
|
|
{
|
|
|
|
if (!mInputStream)
|
|
|
|
return 0;
|
|
|
|
PRInt32 result = 0;
|
|
|
|
mInputStream->Read((char*)s, 0, n, (PRUint32*)&result);
|
|
|
|
if (result < n)
|
|
|
|
mEOF = PR_TRUE;
|
|
|
|
return result;
|
|
|
|
}
|
1998-12-09 01:45:42 +03:00
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
// Input streamers. Add more as needed (int&, unsigned int& etc). (but you have to
|
|
|
|
// add delegators to the derived classes, too, because these operators don't inherit).
|
|
|
|
nsInputStream& operator >> (char& ch);
|
1998-12-09 01:45:42 +03:00
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
// Support manipulators
|
|
|
|
nsInputStream& operator >> (nsInputStream& (*pf)(nsInputStream&))
|
|
|
|
{
|
|
|
|
return pf(*this);
|
|
|
|
}
|
|
|
|
private:
|
1999-01-27 02:49:33 +03:00
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
nsInputStream& operator >> (char* buf); // TOO DANGEROUS. DON'T DEFINE.
|
|
|
|
|
|
|
|
// DATA
|
1998-12-08 05:15:50 +03:00
|
|
|
protected:
|
1999-02-25 23:49:47 +03:00
|
|
|
nsCOMPtr<nsIInputStream> mInputStream;
|
1999-01-27 02:49:33 +03:00
|
|
|
PRBool mEOF;
|
1999-02-25 23:49:47 +03:00
|
|
|
}; // class nsInputStream
|
|
|
|
|
|
|
|
typedef nsInputStream nsBasicInStream; // historic support for this name
|
1998-12-08 05:15:50 +03:00
|
|
|
|
|
|
|
//========================================================================================
|
1999-02-25 23:49:47 +03:00
|
|
|
class NS_BASE nsOutputStream
|
|
|
|
// This is a convenience class, for use on the STACK ("new" junkies, get detoxed first).
|
|
|
|
// Given a COM-style stream, this allows you to use the << operators. It also acquires and
|
|
|
|
// reference counts its stream.
|
|
|
|
// Please read the comments at the top of this file
|
1998-12-08 05:15:50 +03:00
|
|
|
//========================================================================================
|
|
|
|
{
|
|
|
|
public:
|
1999-02-25 23:49:47 +03:00
|
|
|
nsOutputStream() {}
|
|
|
|
nsOutputStream(nsIOutputStream* inStream)
|
|
|
|
: mOutputStream(do_QueryInterface(inStream))
|
|
|
|
{}
|
|
|
|
|
|
|
|
virtual ~nsOutputStream();
|
1998-12-19 02:06:54 +03:00
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
nsCOMPtr<nsIOutputStream> GetIStream() const
|
|
|
|
{
|
|
|
|
return mOutputStream;
|
|
|
|
}
|
|
|
|
void put(char c);
|
|
|
|
PRInt32 write(const void* s, PRInt32 n)
|
|
|
|
{
|
|
|
|
if (!mOutputStream)
|
|
|
|
return 0;
|
|
|
|
PRInt32 result = 0;
|
|
|
|
mOutputStream->Write((char*)s, 0, n, (PRUint32*)&result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
virtual void flush();
|
|
|
|
|
|
|
|
// Output streamers. Add more as needed (but you have to add delegators to the derived
|
|
|
|
// classes, too, because these operators don't inherit).
|
|
|
|
nsOutputStream& operator << (const char* buf);
|
|
|
|
nsOutputStream& operator << (char ch);
|
|
|
|
nsOutputStream& operator << (short val);
|
|
|
|
nsOutputStream& operator << (unsigned short val);
|
|
|
|
nsOutputStream& operator << (long val);
|
|
|
|
nsOutputStream& operator << (unsigned long val);
|
|
|
|
|
|
|
|
// Support manipulators
|
|
|
|
nsOutputStream& operator << (nsOutputStream& (*pf)(nsOutputStream&))
|
1998-12-19 02:06:54 +03:00
|
|
|
{
|
|
|
|
return pf(*this);
|
1999-02-25 23:49:47 +03:00
|
|
|
}
|
1999-01-27 02:49:33 +03:00
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
// DATA
|
1999-01-27 02:49:33 +03:00
|
|
|
protected:
|
1999-02-25 23:49:47 +03:00
|
|
|
nsCOMPtr<nsIOutputStream> mOutputStream;
|
|
|
|
}; // class nsOutputStream
|
1999-01-27 02:49:33 +03:00
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
typedef nsOutputStream nsBasicOutStream; // Historic support for this name
|
1999-01-27 02:49:33 +03:00
|
|
|
|
|
|
|
//========================================================================================
|
1999-02-25 23:49:47 +03:00
|
|
|
class NS_BASE nsFileClient
|
|
|
|
// Because COM does not allow us to write functions which return a boolean value etc,
|
|
|
|
// this class is here to take care of the tedious "declare variable then call with
|
|
|
|
// the address of the variable" chores.
|
1999-01-27 02:49:33 +03:00
|
|
|
//========================================================================================
|
|
|
|
{
|
|
|
|
public:
|
1999-02-25 23:49:47 +03:00
|
|
|
nsFileClient() // for delayed opening
|
|
|
|
: mResult(NS_OK)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
nsFileClient(const nsCOMPtr<nsIFile>& inFile)
|
|
|
|
: mFile(do_QueryInterface(inFile))
|
|
|
|
, mResult(NS_OK)
|
1999-01-27 02:49:33 +03:00
|
|
|
{
|
|
|
|
}
|
1998-12-19 02:06:54 +03:00
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
PRBool is_file() const
|
|
|
|
{
|
|
|
|
return mFile ? PR_TRUE : PR_FALSE;
|
|
|
|
}
|
|
|
|
void open(
|
|
|
|
const nsFileSpec& inFile,
|
|
|
|
int nsprMode,
|
|
|
|
PRIntn accessMode)
|
|
|
|
{
|
|
|
|
if (mFile)
|
|
|
|
mResult = mFile->Open(inFile, nsprMode, accessMode);
|
|
|
|
}
|
|
|
|
PRBool is_open() const
|
|
|
|
{
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
if (mFile)
|
|
|
|
mFile->GetIsOpen(&result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
PRBool failed() const
|
|
|
|
{
|
|
|
|
return NS_FAILED(mResult);
|
|
|
|
}
|
|
|
|
void seek(PRInt32 offset)
|
|
|
|
{
|
|
|
|
seek(PR_SEEK_SET, offset);
|
|
|
|
}
|
1999-01-27 02:49:33 +03:00
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
void seek(PRSeekWhence whence, PRInt32 offset)
|
|
|
|
{
|
|
|
|
if (mFile)
|
|
|
|
mResult = mFile->Seek(whence, offset);
|
|
|
|
}
|
|
|
|
PRIntn tell()
|
|
|
|
{
|
|
|
|
PRIntn result = -1;
|
|
|
|
if (mFile)
|
|
|
|
mResult = mFile->Tell(&result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// DATA
|
1999-01-27 02:49:33 +03:00
|
|
|
protected:
|
1999-02-25 23:49:47 +03:00
|
|
|
nsCOMPtr<nsIFile> mFile;
|
|
|
|
PRBool mResult;
|
|
|
|
}; // class nsFileClient
|
1999-01-27 02:49:33 +03:00
|
|
|
|
|
|
|
//========================================================================================
|
|
|
|
class NS_BASE nsInputFileStream
|
1999-02-25 23:49:47 +03:00
|
|
|
// Please read the comments at the top of this file
|
1999-01-27 02:49:33 +03:00
|
|
|
//========================================================================================
|
1999-02-25 23:49:47 +03:00
|
|
|
: public nsInputStream
|
|
|
|
, public nsFileClient
|
1999-01-27 02:49:33 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum { kDefaultMode = PR_RDONLY };
|
1999-02-25 23:49:47 +03:00
|
|
|
nsInputFileStream(nsIInputStream* inStream)
|
|
|
|
: nsInputStream(inStream)
|
|
|
|
, nsFileClient(do_QueryInterface(inStream))
|
|
|
|
, mFileInputStream(do_QueryInterface(inStream))
|
|
|
|
{
|
|
|
|
}
|
1999-01-27 02:49:33 +03:00
|
|
|
nsInputFileStream(
|
1999-02-25 23:49:47 +03:00
|
|
|
const nsFileSpec& inFile,
|
1999-01-27 02:49:33 +03:00
|
|
|
int nsprMode = kDefaultMode,
|
|
|
|
PRIntn accessMode = 00700) // <- OCTAL
|
1999-02-25 23:49:47 +03:00
|
|
|
: nsInputStream(nsnull)
|
|
|
|
{
|
|
|
|
nsISupports* stream;
|
|
|
|
NS_NewIOFileStream(
|
|
|
|
&stream,
|
|
|
|
inFile, nsprMode, accessMode);
|
|
|
|
mFile = nsQueryInterface(stream);
|
|
|
|
mInputStream = nsQueryInterface(stream);
|
|
|
|
mFileInputStream = nsQueryInterface(stream);
|
|
|
|
}
|
1999-01-27 02:49:33 +03:00
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
PRBool readline(char* s, PRInt32 n);
|
|
|
|
// Result always null-terminated.
|
|
|
|
// Check eof() before each call.
|
|
|
|
// CAUTION: false result only indicates line was truncated
|
|
|
|
// to fit buffer, or an error occurred (OTHER THAN eof).
|
|
|
|
|
|
|
|
void Open(
|
|
|
|
const nsFileSpec& inFile,
|
1998-12-19 02:06:54 +03:00
|
|
|
int nsprMode = kDefaultMode,
|
1998-12-29 03:24:32 +03:00
|
|
|
PRIntn accessMode = 00700) // <- OCTAL
|
1998-12-19 02:06:54 +03:00
|
|
|
{
|
1999-02-25 23:49:47 +03:00
|
|
|
if (mFile)
|
|
|
|
mFile->Open(inFile, nsprMode, accessMode);
|
1998-12-19 02:06:54 +03:00
|
|
|
}
|
1998-12-09 01:45:42 +03:00
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
// Input streamers. Unfortunately, they don't inherit!
|
|
|
|
nsInputStream& operator >> (char& ch)
|
|
|
|
{ return nsInputStream::operator >>(ch); }
|
|
|
|
nsInputStream& operator >> (nsInputStream& (*pf)(nsInputStream&))
|
|
|
|
{ return nsInputStream::operator >>(pf); }
|
1998-12-09 01:45:42 +03:00
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
// DATA
|
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIFileInputStream> mFileInputStream;
|
1998-12-19 02:06:54 +03:00
|
|
|
}; // class nsInputFileStream
|
1998-12-08 05:15:50 +03:00
|
|
|
|
|
|
|
//========================================================================================
|
1998-12-19 02:06:54 +03:00
|
|
|
class NS_BASE nsOutputFileStream
|
1999-02-25 23:49:47 +03:00
|
|
|
// Please read the comments at the top of this file
|
1998-12-08 05:15:50 +03:00
|
|
|
//========================================================================================
|
1999-02-25 23:49:47 +03:00
|
|
|
: public nsOutputStream
|
|
|
|
, public nsFileClient
|
1998-12-08 05:15:50 +03:00
|
|
|
{
|
|
|
|
public:
|
1998-12-19 02:06:54 +03:00
|
|
|
enum { kDefaultMode = (PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE) };
|
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
nsOutputFileStream() {}
|
|
|
|
nsOutputFileStream(nsIOutputStream* inStream)
|
|
|
|
: nsOutputStream(inStream)
|
|
|
|
, nsFileClient(do_QueryInterface(inStream))
|
|
|
|
, mFileOutputStream(do_QueryInterface(inStream))
|
|
|
|
{
|
|
|
|
}
|
1998-12-19 02:06:54 +03:00
|
|
|
nsOutputFileStream(
|
1999-02-25 23:49:47 +03:00
|
|
|
const nsFileSpec& inFile,
|
1998-12-19 02:06:54 +03:00
|
|
|
int nsprMode = kDefaultMode,
|
1998-12-29 03:24:32 +03:00
|
|
|
PRIntn accessMode = 00700) // <- OCTAL
|
1999-02-25 23:49:47 +03:00
|
|
|
: nsOutputStream(nsnull)
|
1998-12-19 02:06:54 +03:00
|
|
|
{
|
1999-02-25 23:49:47 +03:00
|
|
|
nsISupports* stream;
|
|
|
|
if (NS_FAILED(NS_NewIOFileStream(
|
|
|
|
&stream,
|
|
|
|
inFile, nsprMode, accessMode)))
|
|
|
|
return;
|
|
|
|
mFile = nsQueryInterface(stream);
|
|
|
|
mOutputStream = nsQueryInterface(stream);
|
|
|
|
mFileOutputStream = nsQueryInterface(stream);
|
1998-12-19 02:06:54 +03:00
|
|
|
}
|
1999-02-25 23:49:47 +03:00
|
|
|
|
|
|
|
virtual void flush();
|
|
|
|
|
|
|
|
// Output streamers. Unfortunately, they don't inherit!
|
|
|
|
nsOutputStream& operator << (const char* buf)
|
|
|
|
{ return nsOutputStream::operator << (buf); }
|
|
|
|
nsOutputStream& operator << (char ch)
|
|
|
|
{ return nsOutputStream::operator << (ch); }
|
|
|
|
nsOutputStream& operator << (short val)
|
|
|
|
{ return nsOutputStream::operator << (val); }
|
|
|
|
nsOutputStream& operator << (unsigned short val)
|
|
|
|
{ return nsOutputStream::operator << (val); }
|
|
|
|
nsOutputStream& operator << (long val)
|
|
|
|
{ return nsOutputStream::operator << (val); }
|
|
|
|
nsOutputStream& operator << (unsigned long val)
|
|
|
|
{ return nsOutputStream::operator << (val); }
|
|
|
|
nsOutputStream& operator << (nsOutputStream& (*pf)(nsOutputStream&))
|
|
|
|
{ return nsOutputStream::operator << (pf); }
|
|
|
|
|
|
|
|
// DATA
|
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIFileOutputStream> mFileOutputStream;
|
1999-01-27 02:49:33 +03:00
|
|
|
}; // class nsOutputFileStream
|
1998-12-08 05:15:50 +03:00
|
|
|
|
1999-02-25 23:49:47 +03:00
|
|
|
//========================================================================================
|
|
|
|
class NS_BASE nsOutputConsoleStream
|
|
|
|
// Please read the comments at the top of this file
|
|
|
|
//========================================================================================
|
|
|
|
: public nsOutputFileStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
nsOutputConsoleStream()
|
|
|
|
{
|
|
|
|
nsISupports* stream;
|
|
|
|
if (NS_FAILED(NS_NewOutputConsoleStream(&stream)))
|
|
|
|
return;
|
|
|
|
mFile = nsQueryInterface(stream);
|
|
|
|
mOutputStream = nsQueryInterface(stream);
|
|
|
|
mFileOutputStream = nsQueryInterface(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Output streamers. Unfortunately, they don't inherit!
|
|
|
|
nsOutputStream& operator << (const char* buf)
|
|
|
|
{ return nsOutputStream::operator << (buf); }
|
|
|
|
nsOutputStream& operator << (char ch)
|
|
|
|
{ return nsOutputStream::operator << (ch); }
|
|
|
|
nsOutputStream& operator << (short val)
|
|
|
|
{ return nsOutputStream::operator << (val); }
|
|
|
|
nsOutputStream& operator << (unsigned short val)
|
|
|
|
{ return nsOutputStream::operator << (val); }
|
|
|
|
nsOutputStream& operator << (long val)
|
|
|
|
{ return nsOutputStream::operator << (val); }
|
|
|
|
nsOutputStream& operator << (unsigned long val)
|
|
|
|
{ return nsOutputStream::operator << (val); }
|
|
|
|
nsOutputStream& operator << (nsOutputStream& (*pf)(nsOutputStream&))
|
|
|
|
{ return nsOutputStream::operator << (pf); }
|
|
|
|
|
|
|
|
}; // class nsOutputConsoleStream
|
|
|
|
|
1999-01-27 02:49:33 +03:00
|
|
|
//========================================================================================
|
|
|
|
class NS_BASE nsIOFileStream
|
1999-02-25 23:49:47 +03:00
|
|
|
// Please read the comments at the top of this file
|
1999-01-27 02:49:33 +03:00
|
|
|
//========================================================================================
|
1999-02-25 23:49:47 +03:00
|
|
|
: public nsInputFileStream
|
|
|
|
, public nsOutputStream
|
1999-01-27 02:49:33 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum { kDefaultMode = (PR_RDWR | PR_CREATE_FILE) };
|
1998-12-29 03:24:32 +03:00
|
|
|
|
1999-01-27 02:49:33 +03:00
|
|
|
nsIOFileStream(
|
1999-02-25 23:49:47 +03:00
|
|
|
nsIInputStream* inInputStream
|
|
|
|
, nsIOutputStream* inOutputStream)
|
|
|
|
: nsInputFileStream(inInputStream)
|
|
|
|
, nsOutputStream(inOutputStream)
|
|
|
|
, mFileOutputStream(do_QueryInterface(inOutputStream))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
nsIOFileStream(
|
|
|
|
const nsFileSpec& inFile,
|
1999-01-27 02:49:33 +03:00
|
|
|
int nsprMode = kDefaultMode,
|
|
|
|
PRIntn accessMode = 00700) // <- OCTAL
|
1999-02-25 23:49:47 +03:00
|
|
|
: nsInputFileStream(nsnull)
|
|
|
|
, nsOutputStream(nsnull)
|
1999-01-27 02:49:33 +03:00
|
|
|
{
|
1999-02-25 23:49:47 +03:00
|
|
|
nsISupports* stream;
|
|
|
|
if (NS_FAILED(NS_NewIOFileStream(
|
|
|
|
&stream,
|
|
|
|
inFile, nsprMode, accessMode)))
|
|
|
|
return;
|
|
|
|
mFile = nsQueryInterface(stream);
|
|
|
|
mInputStream = nsQueryInterface(stream);
|
|
|
|
mOutputStream = nsQueryInterface(stream);
|
|
|
|
mFileInputStream = nsQueryInterface(stream);
|
|
|
|
mFileOutputStream = nsQueryInterface(stream);
|
1999-01-27 02:49:33 +03:00
|
|
|
}
|
1999-02-25 23:49:47 +03:00
|
|
|
|
|
|
|
// Output streamers. Unfortunately, they don't inherit!
|
|
|
|
nsOutputStream& operator << (const char* buf)
|
|
|
|
{ return nsOutputStream::operator << (buf); }
|
|
|
|
nsOutputStream& operator << (char ch)
|
|
|
|
{ return nsOutputStream::operator << (ch); }
|
|
|
|
nsOutputStream& operator << (short val)
|
|
|
|
{ return nsOutputStream::operator << (val); }
|
|
|
|
nsOutputStream& operator << (unsigned short val)
|
|
|
|
{ return nsOutputStream::operator << (val); }
|
|
|
|
nsOutputStream& operator << (long val)
|
|
|
|
{ return nsOutputStream::operator << (val); }
|
|
|
|
nsOutputStream& operator << (unsigned long val)
|
|
|
|
{ return nsOutputStream::operator << (val); }
|
|
|
|
nsOutputStream& operator << (nsOutputStream& (*pf)(nsOutputStream&))
|
|
|
|
{ return nsOutputStream::operator << (pf); }
|
|
|
|
|
|
|
|
// Input streamers. Unfortunately, they don't inherit!
|
|
|
|
nsInputStream& operator >> (char& ch)
|
|
|
|
{ return nsInputStream::operator >>(ch); }
|
|
|
|
nsInputStream& operator >> (nsInputStream& (*pf)(nsInputStream&))
|
|
|
|
{ return nsInputStream::operator >>(pf); }
|
|
|
|
// DATA
|
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIFileOutputStream> mFileOutputStream;
|
1999-01-27 02:49:33 +03:00
|
|
|
}; // class nsIOFileStream
|
1999-02-25 23:49:47 +03:00
|
|
|
|
1998-12-08 05:15:50 +03:00
|
|
|
//========================================================================================
|
1998-12-19 02:06:54 +03:00
|
|
|
// Manipulators
|
1998-12-08 05:15:50 +03:00
|
|
|
//========================================================================================
|
1999-02-25 23:49:47 +03:00
|
|
|
|
|
|
|
NS_BASE nsOutputStream& nsEndl(nsOutputStream& os); // outputs and FLUSHES.
|
|
|
|
|
1998-12-16 01:45:09 +03:00
|
|
|
|
1998-12-09 01:45:42 +03:00
|
|
|
#endif /* _FILESTREAM_H_ */
|