OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_MEMORY_REF_COUNTED_MEMORY_H_ | 5 #ifndef BASE_MEMORY_REF_COUNTED_MEMORY_H_ |
6 #define BASE_MEMORY_REF_COUNTED_MEMORY_H_ | 6 #define BASE_MEMORY_REF_COUNTED_MEMORY_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... | |
23 // Retrieves a pointer to the beginning of the data we point to. If the data | 23 // Retrieves a pointer to the beginning of the data we point to. If the data |
24 // is empty, this will return NULL. | 24 // is empty, this will return NULL. |
25 virtual const unsigned char* front() const = 0; | 25 virtual const unsigned char* front() const = 0; |
26 | 26 |
27 // Size of the memory pointed to. | 27 // Size of the memory pointed to. |
28 virtual size_t size() const = 0; | 28 virtual size_t size() const = 0; |
29 | 29 |
30 // Returns true if |other| is byte for byte equal. | 30 // Returns true if |other| is byte for byte equal. |
31 bool Equals(const scoped_refptr<RefCountedMemory>& other) const; | 31 bool Equals(const scoped_refptr<RefCountedMemory>& other) const; |
32 | 32 |
33 // Handy method to simplify calling front() with a reinterpret_cast. | |
34 template<typename T> const T* front_as() const | |
brettw
2014/01/26 06:50:06
Comment about {} placement and wrapping here still
| |
35 { return reinterpret_cast<const T*>(front()); } | |
36 | |
33 protected: | 37 protected: |
34 friend class base::RefCountedThreadSafe<RefCountedMemory>; | 38 friend class base::RefCountedThreadSafe<RefCountedMemory>; |
35 RefCountedMemory(); | 39 RefCountedMemory(); |
36 virtual ~RefCountedMemory(); | 40 virtual ~RefCountedMemory(); |
37 }; | 41 }; |
38 | 42 |
39 // An implementation of RefCountedMemory, where the ref counting does not | 43 // An implementation of RefCountedMemory, where the ref counting does not |
40 // matter. | 44 // matter. |
41 class BASE_EXPORT RefCountedStaticMemory : public RefCountedMemory { | 45 class BASE_EXPORT RefCountedStaticMemory : public RefCountedMemory { |
42 public: | 46 public: |
43 RefCountedStaticMemory() | 47 RefCountedStaticMemory() |
44 : data_(NULL), length_(0) {} | 48 : data_(NULL), length_(0) {} |
45 RefCountedStaticMemory(const unsigned char* data, size_t length) | 49 RefCountedStaticMemory(const void* data, size_t length) |
46 : data_(length ? data : NULL), length_(length) {} | 50 : data_(static_cast<const unsigned char*>(length ? data : NULL)), |
51 length_(length) {} | |
47 | 52 |
48 // Overridden from RefCountedMemory: | 53 // Overridden from RefCountedMemory: |
49 virtual const unsigned char* front() const OVERRIDE; | 54 virtual const unsigned char* front() const OVERRIDE; |
50 virtual size_t size() const OVERRIDE; | 55 virtual size_t size() const OVERRIDE; |
51 | 56 |
52 private: | 57 private: |
53 virtual ~RefCountedStaticMemory(); | 58 virtual ~RefCountedStaticMemory(); |
54 | 59 |
55 const unsigned char* data_; | 60 const unsigned char* data_; |
56 size_t length_; | 61 size_t length_; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 | 134 |
130 unsigned char* data_; | 135 unsigned char* data_; |
131 size_t length_; | 136 size_t length_; |
132 | 137 |
133 DISALLOW_COPY_AND_ASSIGN(RefCountedMallocedMemory); | 138 DISALLOW_COPY_AND_ASSIGN(RefCountedMallocedMemory); |
134 }; | 139 }; |
135 | 140 |
136 } // namespace base | 141 } // namespace base |
137 | 142 |
138 #endif // BASE_MEMORY_REF_COUNTED_MEMORY_H_ | 143 #endif // BASE_MEMORY_REF_COUNTED_MEMORY_H_ |
OLD | NEW |