Bug 496271, automation config for Tb2.0.0.22 build1, p=joduinn, r=me
[mozilla-1.9.git] / xpcom / io / nsStorageStream.h
blob0729c01c8f86b4a12709b004344f4372a1b06da9
1 /* -*- Mode: C++; tab-width: 4; 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 Communicator client code, released
16 * March 31, 1998.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998-1999
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
40 * The storage stream provides an internal buffer that can be filled by a
41 * client using a single output stream. One or more independent input streams
42 * can be created to read the data out non-destructively. The implementation
43 * uses a segmented buffer internally to avoid realloc'ing of large buffers,
44 * with the attendant performance loss and heap fragmentation.
47 #ifndef _nsStorageStream_h_
48 #define _nsStorageStream_h_
50 #include "nsIStorageStream.h"
51 #include "nsIOutputStream.h"
52 #include "nsMemory.h"
54 #define NS_STORAGESTREAM_CID \
55 { /* 669a9795-6ff7-4ed4-9150-c34ce2971b63 */ \
56 0x669a9795, \
57 0x6ff7, \
58 0x4ed4, \
59 {0x91, 0x50, 0xc3, 0x4c, 0xe2, 0x97, 0x1b, 0x63} \
62 #define NS_STORAGESTREAM_CONTRACTID "@mozilla.org/storagestream;1"
63 #define NS_STORAGESTREAM_CLASSNAME "Storage Stream"
65 class nsSegmentedBuffer;
67 class nsStorageStream : public nsIStorageStream,
68 public nsIOutputStream
70 public:
71 nsStorageStream();
73 NS_DECL_ISUPPORTS
74 NS_DECL_NSISTORAGESTREAM
75 NS_DECL_NSIOUTPUTSTREAM
77 friend class nsStorageInputStream;
79 private:
80 ~nsStorageStream();
82 nsSegmentedBuffer* mSegmentedBuffer;
83 PRUint32 mSegmentSize; // All segments, except possibly the last, are of this size
84 // Must be power-of-2
85 PRUint32 mSegmentSizeLog2; // log2(mSegmentSize)
86 PRBool mWriteInProgress; // true, if an un-Close'ed output stream exists
87 PRInt32 mLastSegmentNum; // Last segment # in use, -1 initially
88 char* mWriteCursor; // Pointer to next byte to be written
89 char* mSegmentEnd; // Pointer to one byte after end of segment
90 // containing the write cursor
91 PRUint32 mLogicalLength; // Number of bytes written to stream
93 NS_METHOD Seek(PRInt32 aPosition);
94 PRUint32 SegNum(PRUint32 aPosition) {return aPosition >> mSegmentSizeLog2;}
95 PRUint32 SegOffset(PRUint32 aPosition) {return aPosition & (mSegmentSize - 1);}
98 #endif // _nsStorageStream_h_