]>
git.saurik.com Git - iphone-api.git/blob - WebCore/SharedBuffer.h
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #ifndef SharedBuffer_h
26 #define SharedBuffer_h
28 #include "PlatformString.h"
29 #include <wtf/Forward.h>
30 #include <wtf/OwnPtr.h>
31 #include <wtf/RefCounted.h>
32 #include <wtf/Vector.h>
35 #include <wtf/RetainPtr.h>
49 class PurgeableBuffer
;
51 class SharedBuffer
: public RefCounted
<SharedBuffer
> {
53 static PassRefPtr
<SharedBuffer
> create() { return adoptRef(new SharedBuffer
); }
54 static PassRefPtr
<SharedBuffer
> create(const char* c
, int i
) { return adoptRef(new SharedBuffer(c
, i
)); }
55 static PassRefPtr
<SharedBuffer
> create(const unsigned char* c
, int i
) { return adoptRef(new SharedBuffer(c
, i
)); }
57 static PassRefPtr
<SharedBuffer
> createWithContentsOfFile(const String
& filePath
);
59 static PassRefPtr
<SharedBuffer
> adoptVector(Vector
<char>& vector
);
61 // The buffer must be in non-purgeable state before adopted to a SharedBuffer.
62 // It will stay that way until released.
63 static PassRefPtr
<SharedBuffer
> adoptPurgeableBuffer(PurgeableBuffer
* buffer
);
68 NSData
*createNSData();
69 static PassRefPtr
<SharedBuffer
> wrapNSData(NSData
*data
);
72 CFDataRef
createCFData();
75 const char* data() const;
76 unsigned size() const;
77 const Vector
<char> &buffer() { return m_buffer
; }
79 bool isEmpty() const { return size() == 0; }
81 void append(const char*, int);
83 const char* platformData() const;
84 unsigned platformDataSize() const;
86 PassRefPtr
<SharedBuffer
> copy() const;
88 bool hasPurgeableBuffer() const { return m_purgeableBuffer
.get(); }
90 // Ensure this buffer has no other clients before calling this.
91 PurgeableBuffer
* releasePurgeableBuffer();
95 SharedBuffer(const char*, int);
96 SharedBuffer(const unsigned char*, int);
98 void clearPlatformData();
99 void maybeTransferPlatformData();
100 bool hasPlatformData() const;
102 Vector
<char> m_buffer
;
103 OwnPtr
<PurgeableBuffer
> m_purgeableBuffer
;
105 SharedBuffer(CFDataRef
);
106 RetainPtr
<CFDataRef
> m_cfData
;