Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / netwerk / base / src / nsBufferedStreams.h
blob612a777926d3f1245e213b14e147a759739a66be
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsBufferedStreams_h__
39 #define nsBufferedStreams_h__
41 #include "nsIBufferedStreams.h"
42 #include "nsIInputStream.h"
43 #include "nsIOutputStream.h"
44 #include "nsISafeOutputStream.h"
45 #include "nsISeekableStream.h"
46 #include "nsIStreamBufferAccess.h"
47 #include "nsCOMPtr.h"
48 #include "nsInt64.h"
49 ////////////////////////////////////////////////////////////////////////////////
51 class nsBufferedStream : public nsISeekableStream
53 public:
54 NS_DECL_ISUPPORTS
55 NS_DECL_NSISEEKABLESTREAM
57 nsBufferedStream();
58 virtual ~nsBufferedStream();
60 nsresult Close();
62 protected:
63 nsresult Init(nsISupports* stream, PRUint32 bufferSize);
64 NS_IMETHOD Fill() = 0;
65 NS_IMETHOD Flush() = 0;
67 PRUint32 mBufferSize;
68 char* mBuffer;
70 // mBufferStartOffset is the offset relative to the start of mStream.
71 nsInt64 mBufferStartOffset;
73 // mCursor is the read cursor for input streams, or write cursor for
74 // output streams, and is relative to mBufferStartOffset.
75 PRUint32 mCursor;
77 // mFillPoint is the amount available in the buffer for input streams,
78 // or the high watermark of bytes written into the buffer, and therefore
79 // is relative to mBufferStartOffset.
80 PRUint32 mFillPoint;
82 nsISupports* mStream; // cast to appropriate subclass
84 PRPackedBool mBufferDisabled;
85 PRUint8 mGetBufferCount;
88 ////////////////////////////////////////////////////////////////////////////////
90 class nsBufferedInputStream : public nsBufferedStream,
91 public nsIBufferedInputStream,
92 public nsIStreamBufferAccess
94 public:
95 NS_DECL_ISUPPORTS_INHERITED
96 NS_DECL_NSIINPUTSTREAM
97 NS_DECL_NSIBUFFEREDINPUTSTREAM
98 NS_DECL_NSISTREAMBUFFERACCESS
100 nsBufferedInputStream() : nsBufferedStream() {}
101 virtual ~nsBufferedInputStream() {}
103 static NS_METHOD
104 Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
106 nsIInputStream* Source() {
107 return (nsIInputStream*)mStream;
110 protected:
111 NS_IMETHOD Fill();
112 NS_IMETHOD Flush() { return NS_OK; } // no-op for input streams
115 ////////////////////////////////////////////////////////////////////////////////
117 class nsBufferedOutputStream : public nsBufferedStream,
118 public nsISafeOutputStream,
119 public nsIBufferedOutputStream,
120 public nsIStreamBufferAccess
122 public:
123 NS_DECL_ISUPPORTS_INHERITED
124 NS_DECL_NSIOUTPUTSTREAM
125 NS_DECL_NSISAFEOUTPUTSTREAM
126 NS_DECL_NSIBUFFEREDOUTPUTSTREAM
127 NS_DECL_NSISTREAMBUFFERACCESS
129 nsBufferedOutputStream() : nsBufferedStream() {}
130 virtual ~nsBufferedOutputStream() { nsBufferedOutputStream::Close(); }
132 static NS_METHOD
133 Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
135 nsIOutputStream* Sink() {
136 return (nsIOutputStream*)mStream;
139 protected:
140 NS_IMETHOD Fill() { return NS_OK; } // no-op for input streams
142 nsCOMPtr<nsISafeOutputStream> mSafeStream; // QI'd from mStream
145 ////////////////////////////////////////////////////////////////////////////////
147 #endif // nsBufferedStreams_h__