OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef FlexibleArrayBufferView_h |
| 6 #define FlexibleArrayBufferView_h |
| 7 |
| 8 #include "core/CoreExport.h" |
| 9 #include "core/dom/DOMArrayBufferView.h" |
| 10 #include "platform/heap/Handle.h" |
| 11 #include "wtf/Noncopyable.h" |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 // WARNING: The pointer returned by baseAddress() may point to temporary storage |
| 16 // that is only valid during the life-time of the FlexibleArrayBufferView object
. |
| 17 |
| 18 class CORE_EXPORT FlexibleArrayBufferView { |
| 19 DISALLOW_ALLOCATION(); |
| 20 WTF_MAKE_NONCOPYABLE(FlexibleArrayBufferView); |
| 21 public: |
| 22 FlexibleArrayBufferView() |
| 23 : m_smallData(nullptr), m_smallLength(0) |
| 24 { |
| 25 } |
| 26 |
| 27 void setFull(DOMArrayBufferView* full) { m_full = full; } |
| 28 void setSmall(void* data, size_t length) { m_smallData = data; m_smallLength
= length; } |
| 29 |
| 30 bool isEmpty() const { return !m_full && !m_smallData; } |
| 31 |
| 32 bool isFull() const { return m_full; } |
| 33 DOMArrayBufferView* full() const { ASSERT(isFull()); return m_full.get(); } |
| 34 |
| 35 void* baseAddress() const { ASSERT(!isEmpty()); return isFull() ? m_full->ba
seAddress() : m_smallData; } |
| 36 unsigned byteOffset() const { ASSERT(!isEmpty()); return isFull() ? m_full->
byteOffset() : 0; } |
| 37 unsigned byteLength() const { ASSERT(!isEmpty()); return isFull() ? m_full->
byteLength() : m_smallLength; } |
| 38 |
| 39 operator bool() const { return !isEmpty(); } |
| 40 void operator= (nullptr_t) { m_full = nullptr; m_smallData = nullptr; } |
| 41 |
| 42 private: |
| 43 RefPtr<DOMArrayBufferView> m_full; |
| 44 |
| 45 void* m_smallData; |
| 46 size_t m_smallLength; |
| 47 }; |
| 48 |
| 49 } // namespace blink |
| 50 |
| 51 #endif // FlexibleArrayBufferView_h |
OLD | NEW |