Line data Source code
1 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : * This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef MOZILLA_GFX_ARRAY_VIEW_H_
7 : #define MOZILLA_GFX_ARRAY_VIEW_H_
8 :
9 : #include "nsTArray.h"
10 :
11 : /* This is similar to mfbt/Range.h but has implicit conversion
12 : * from nsTArray and less bounds checking.
13 : * For now, prefer Range over ArrayView */
14 :
15 : namespace mozilla {
16 : namespace gfx {
17 :
18 : template<typename T>
19 : class ArrayView
20 : {
21 : public:
22 1251 : MOZ_IMPLICIT ArrayView(const nsTArray<T>& aData) :
23 1251 : mData(aData.Elements()), mLength(aData.Length())
24 : {
25 1251 : }
26 : ArrayView(const T* aData, const size_t aLength) :
27 : mData(aData), mLength(aLength)
28 : {
29 : }
30 : const T& operator[](const size_t aIdx) const
31 : {
32 : return mData[aIdx];
33 : }
34 1251 : size_t Length() const
35 : {
36 1251 : return mLength;
37 : }
38 1251 : const T* Data() const
39 : {
40 1251 : return mData;
41 : }
42 : private:
43 : const T* mData;
44 : const size_t mLength;
45 : };
46 :
47 : } // namespace gfx
48 : } // namespace mozilla
49 :
50 : #endif /* MOZILLA_GFX_ARRAY_VIEW_H_ */
|