Chromium Code Reviews| Index: Source/core/dom/TypedFlexibleArrayBufferView.h |
| diff --git a/Source/core/dom/TypedFlexibleArrayBufferView.h b/Source/core/dom/TypedFlexibleArrayBufferView.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e1979f4be9ed1b332ec79637aea1a23e84501e89 |
| --- /dev/null |
| +++ b/Source/core/dom/TypedFlexibleArrayBufferView.h |
| @@ -0,0 +1,32 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef TypedFlexibleArrayBufferView_h |
| +#define TypedFlexibleArrayBufferView_h |
| + |
| +#include "core/CoreExport.h" |
| +#include "core/dom/FlexibleArrayBufferView.h" |
| +#include "wtf/Noncopyable.h" |
| + |
| +namespace blink { |
| + |
| +template<typename WTFTypedArray> |
| +class CORE_TEMPLATE_CLASS_EXPORT TypedFlexibleArrayBufferView final : public FlexibleArrayBufferView { |
| + STACK_ALLOCATED(); |
| + WTF_MAKE_NONCOPYABLE(TypedFlexibleArrayBufferView); |
| +public: |
| + using ValueType = typename WTFTypedArray::ValueType; |
| + |
| + TypedFlexibleArrayBufferView() : FlexibleArrayBufferView() {} |
| + |
| + ValueType* dataMaybeOnStack() const { return static_cast<ValueType*>(baseAddressMaybeOnStack()); } |
| + unsigned length() const { return byteLength() / sizeof(ValueType); } |
|
haraken
2015/07/30 20:34:44
Shall we add:
ASSERT(byteLength() % sizeof(Valu
Michael Lippautz
2015/07/31 07:53:38
Good idea, done.
|
| +}; |
| + |
| +using FlexibleInt32ArrayView = TypedFlexibleArrayBufferView<WTF::Int32Array>; |
| +using FlexibleFloat32ArrayView = TypedFlexibleArrayBufferView<WTF::Float32Array>; |
| + |
| +} // namespace blink |
| + |
| +#endif // TypedFlexibleArrayBufferView_h |