KHTML
SharedBuffer.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef SharedBuffer_h
00026 #define SharedBuffer_h
00027
00028 #include "PlatformString.h"
00029 #include <wtf/RefCounted.h>
00030 #include <wtf/Forward.h>
00031 #include <wtf/Vector.h>
00032
00033 #if PLATFORM(CF)
00034 #include <wtf/RetainPtr.h>
00035 #endif
00036
00037 #if PLATFORM(MAC)
00038 #ifdef __OBJC__
00039 @class NSData;
00040 #else
00041 class NSData;
00042 #endif
00043
00044 #endif
00045
00046 namespace WebCore {
00047
00048 class SharedBuffer : public RefCounted<SharedBuffer> {
00049 public:
00050 static PassRefPtr<SharedBuffer> create() { return adoptRef(new SharedBuffer); }
00051 static PassRefPtr<SharedBuffer> create(const char* c, int i) { return adoptRef(new SharedBuffer(c, i)); }
00052 static PassRefPtr<SharedBuffer> create(const unsigned char* c, int i) { return adoptRef(new SharedBuffer(c, i)); }
00053
00054 static PassRefPtr<SharedBuffer> createWithContentsOfFile(const String& filePath);
00055
00056 static PassRefPtr<SharedBuffer> adoptVector(Vector<char>& vector);
00057
00058 #if PLATFORM(MAC)
00059 NSData *createNSData();
00060 static PassRefPtr<SharedBuffer> wrapNSData(NSData *data);
00061 #endif
00062 #if PLATFORM(CF)
00063 CFDataRef createCFData();
00064 #endif
00065
00066 const char* data() const;
00067 unsigned size() const;
00068 const Vector<char> &buffer() { return m_buffer; }
00069
00070 bool isEmpty() const { return size() == 0; }
00071
00072 void append(const char*, int);
00073 void clear();
00074 const char* platformData() const;
00075 unsigned platformDataSize() const;
00076
00077 PassRefPtr<SharedBuffer> copy() const;
00078
00079 private:
00080 SharedBuffer();
00081 SharedBuffer(const char*, int);
00082 SharedBuffer(const unsigned char*, int);
00083
00084 void clearPlatformData();
00085 void maybeTransferPlatformData();
00086 bool hasPlatformData() const;
00087
00088 Vector<char> m_buffer;
00089 #if PLATFORM(CF)
00090 SharedBuffer(CFDataRef);
00091 RetainPtr<CFDataRef> m_cfData;
00092 #endif
00093 };
00094
00095 }
00096
00097 #endif