2008-03-19 Stephanie Lewis <slewis@apple.com>
[WebKit-https.git] / WebCore / platform / SharedBuffer.h
index 625370428e62b602f15bc6e128fb35af37b0ade5..9ce1f129d71385c5214a8b6ef501b927761aac6b 100644 (file)
 #ifndef SharedBuffer_h
 #define SharedBuffer_h
 
-#include "Shared.h"
+#include "PlatformString.h"
+#include <wtf/RefCounted.h>
 #include <wtf/Forward.h>
 #include <wtf/Vector.h>
 
-#if PLATFORM(MAC)
+#if PLATFORM(CF)
 #include <wtf/RetainPtr.h>
+#endif
 
+#if PLATFORM(MAC)
 #ifdef __OBJC__
 @class NSData;
 #else
@@ -42,16 +45,22 @@ class NSData;
 
 namespace WebCore {
 
-class SharedBuffer : public Shared<SharedBuffer> {
+class SharedBuffer : public RefCounted<SharedBuffer> {
 public:
-    SharedBuffer();
-    SharedBuffer(const char*, int);
+    static PassRefPtr<SharedBuffer> create() { return adoptRef(new SharedBuffer); }
+    static PassRefPtr<SharedBuffer> create(const char* c, int i) { return adoptRef(new SharedBuffer(c, i)); }
+    static PassRefPtr<SharedBuffer> create(const unsigned char* c, int i) { return adoptRef(new SharedBuffer(c, i)); }
+
+    static PassRefPtr<SharedBuffer> createWithContentsOfFile(const String& filePath);
+    
 #if PLATFORM(MAC)
     NSData *createNSData();
-    CFDataRef createCFData();
     static PassRefPtr<SharedBuffer> wrapNSData(NSData *data);
 #endif
-        
+#if PLATFORM(CF)
+    CFDataRef createCFData();
+#endif
+
     const char* data() const;
     unsigned size() const;
     const Vector<char> &buffer() { return m_buffer; }
@@ -63,15 +72,21 @@ public:
     const char* platformData() const;
     unsigned platformDataSize() const;
 
+    PassRefPtr<SharedBuffer> copy() const;
+    
 private:
+    SharedBuffer();
+    SharedBuffer(const char*, int);
+    SharedBuffer(const unsigned char*, int);
+    
     void clearPlatformData();
     void maybeTransferPlatformData();
     bool hasPlatformData() const;
     
     Vector<char> m_buffer;
-#if PLATFORM(MAC)
-    SharedBuffer(NSData *nsdata);
-    RetainPtr<NSData> m_nsData;
+#if PLATFORM(CF)
+    SharedBuffer(CFDataRef);
+    RetainPtr<CFDataRef> m_cfData;
 #endif
 };