~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/xpcom/io/nsStorageStream.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
2
 * The contents of this file are subject to the Netscape Public
 
3
 * License Version 1.1 (the "License"); you may not use this file
 
4
 * except in compliance with the License. You may obtain a copy of
 
5
 * the License at http://www.mozilla.org/NPL/
 
6
 *  
 
7
 * Software distributed under the License is distributed on an "AS
 
8
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
9
 * implied. See the License for the specific language governing
 
10
 * rights and limitations under the License.
 
11
 *  
 
12
 * The Original Code is Mozilla Communicator client code, released
 
13
 * March 31, 1998.
 
14
 * 
 
15
 * The Initial Developer of the Original Code is Netscape
 
16
 * Communications Corporation. Portions created by Netscape are
 
17
 * Copyright (C) 1998-1999 Netscape Communications Corporation. All
 
18
 * Rights Reserved.
 
19
 *
 
20
 */
 
21
 
 
22
/*
 
23
 * The storage stream provides an internal buffer that can be filled by a
 
24
 * client using a single output stream.  One or more independent input streams
 
25
 * can be created to read the data out non-destructively.  The implementation
 
26
 * uses a segmented buffer internally to avoid realloc'ing of large buffers,
 
27
 * with the attendant performance loss and heap fragmentation.
 
28
 */
 
29
 
 
30
#ifndef _nsStorageStream_h_
 
31
#define _nsStorageStream_h_
 
32
 
 
33
#include "nsIStorageStream.h"
 
34
#include "nsIOutputStream.h"
 
35
#include "nsMemory.h"
 
36
 
 
37
#define NS_STORAGESTREAM_CID                       \
 
38
{ /* 669a9795-6ff7-4ed4-9150-c34ce2971b63 */       \
 
39
  0x669a9795,                                      \
 
40
  0x6ff7,                                          \
 
41
  0x4ed4,                                          \
 
42
  {0x91, 0x50, 0xc3, 0x4c, 0xe2, 0x97, 0x1b, 0x63} \
 
43
}
 
44
 
 
45
#define NS_STORAGESTREAM_CONTRACTID "@mozilla.org/storagestream;1"
 
46
#define NS_STORAGESTREAM_CLASSNAME "Storage Stream"
 
47
 
 
48
class nsSegmentedBuffer;
 
49
 
 
50
class nsStorageStream : public nsIStorageStream,
 
51
                        public nsIOutputStream
 
52
{
 
53
public:
 
54
    nsStorageStream();
 
55
    
 
56
    NS_METHOD Init(PRUint32 segmentSize, PRUint32 maxSize, nsIMemory *segmentAllocator = 0);
 
57
 
 
58
    NS_DECL_ISUPPORTS
 
59
    NS_DECL_NSISTORAGESTREAM
 
60
    NS_DECL_NSIOUTPUTSTREAM
 
61
 
 
62
    friend class nsStorageInputStream;
 
63
 
 
64
private:
 
65
    ~nsStorageStream();
 
66
 
 
67
    nsSegmentedBuffer* mSegmentedBuffer;
 
68
    PRUint32           mSegmentSize;       // All segments, except possibly the last, are of this size
 
69
                                           //   Must be power-of-2
 
70
    PRUint32           mSegmentSizeLog2;   // log2(mSegmentSize)
 
71
    PRBool             mWriteInProgress;   // true, if an un-Close'ed output stream exists
 
72
    PRInt32            mLastSegmentNum;    // Last segment # in use, -1 initially
 
73
    char*              mWriteCursor;       // Pointer to next byte to be written
 
74
    char*              mSegmentEnd;        // Pointer to one byte after end of segment
 
75
                                           //   containing the write cursor
 
76
    PRUint32           mLogicalLength;     // Number of bytes written to stream
 
77
 
 
78
    NS_METHOD Seek(PRInt32 aPosition);
 
79
    PRUint32 SegNum(PRUint32 aPosition)    {return aPosition >> mSegmentSizeLog2;}
 
80
    PRUint32 SegOffset(PRUint32 aPosition) {return aPosition & (mSegmentSize - 1);}
 
81
};
 
82
 
 
83
#endif //  _nsStorageStream_h_