/src/mozilla-central/layout/style/nsStyleAutoArray.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef nsStyleAutoArray_h_ |
8 | | #define nsStyleAutoArray_h_ |
9 | | |
10 | | #include "nsTArray.h" |
11 | | #include "mozilla/Assertions.h" |
12 | | |
13 | | /** |
14 | | * An array of objects, similar to AutoTArray<T,1> but which is memmovable. It |
15 | | * always has length >= 1. |
16 | | */ |
17 | | template<typename T> |
18 | | class nsStyleAutoArray |
19 | | { |
20 | | public: |
21 | | // This constructor places a single element in mFirstElement. |
22 | | enum WithSingleInitialElement { WITH_SINGLE_INITIAL_ELEMENT }; |
23 | 0 | explicit nsStyleAutoArray(WithSingleInitialElement) {} Unexecuted instantiation: nsStyleAutoArray<nsStyleImageLayers::Layer>::nsStyleAutoArray(nsStyleAutoArray<nsStyleImageLayers::Layer>::WithSingleInitialElement) Unexecuted instantiation: nsStyleAutoArray<mozilla::StyleTransition>::nsStyleAutoArray(nsStyleAutoArray<mozilla::StyleTransition>::WithSingleInitialElement) Unexecuted instantiation: nsStyleAutoArray<mozilla::StyleAnimation>::nsStyleAutoArray(nsStyleAutoArray<mozilla::StyleAnimation>::WithSingleInitialElement) |
24 | 0 | nsStyleAutoArray(const nsStyleAutoArray& aOther) { *this = aOther; } Unexecuted instantiation: nsStyleAutoArray<nsStyleImageLayers::Layer>::nsStyleAutoArray(nsStyleAutoArray<nsStyleImageLayers::Layer> const&) Unexecuted instantiation: nsStyleAutoArray<mozilla::StyleTransition>::nsStyleAutoArray(nsStyleAutoArray<mozilla::StyleTransition> const&) Unexecuted instantiation: nsStyleAutoArray<mozilla::StyleAnimation>::nsStyleAutoArray(nsStyleAutoArray<mozilla::StyleAnimation> const&) |
25 | 0 | nsStyleAutoArray& operator=(const nsStyleAutoArray& aOther) { |
26 | 0 | mFirstElement = aOther.mFirstElement; |
27 | 0 | mOtherElements = aOther.mOtherElements; |
28 | 0 | return *this; |
29 | 0 | } Unexecuted instantiation: nsStyleAutoArray<nsStyleImageLayers::Layer>::operator=(nsStyleAutoArray<nsStyleImageLayers::Layer> const&) Unexecuted instantiation: nsStyleAutoArray<mozilla::StyleTransition>::operator=(nsStyleAutoArray<mozilla::StyleTransition> const&) Unexecuted instantiation: nsStyleAutoArray<mozilla::StyleAnimation>::operator=(nsStyleAutoArray<mozilla::StyleAnimation> const&) |
30 | | |
31 | 0 | bool operator==(const nsStyleAutoArray& aOther) const { |
32 | 0 | return Length() == aOther.Length() && |
33 | 0 | mFirstElement == aOther.mFirstElement && |
34 | 0 | mOtherElements == aOther.mOtherElements; |
35 | 0 | } Unexecuted instantiation: nsStyleAutoArray<mozilla::StyleAnimation>::operator==(nsStyleAutoArray<mozilla::StyleAnimation> const&) const Unexecuted instantiation: nsStyleAutoArray<mozilla::StyleTransition>::operator==(nsStyleAutoArray<mozilla::StyleTransition> const&) const |
36 | 0 | bool operator!=(const nsStyleAutoArray& aOther) const { |
37 | 0 | return !(*this == aOther); |
38 | 0 | } Unexecuted instantiation: nsStyleAutoArray<mozilla::StyleTransition>::operator!=(nsStyleAutoArray<mozilla::StyleTransition> const&) const Unexecuted instantiation: nsStyleAutoArray<mozilla::StyleAnimation>::operator!=(nsStyleAutoArray<mozilla::StyleAnimation> const&) const |
39 | | |
40 | 0 | nsStyleAutoArray& operator=(nsStyleAutoArray&& aOther) { |
41 | 0 | mFirstElement = aOther.mFirstElement; |
42 | 0 | mOtherElements.SwapElements(aOther.mOtherElements); |
43 | 0 |
|
44 | 0 | return *this; |
45 | 0 | } |
46 | | |
47 | 0 | size_t Length() const { |
48 | 0 | return mOtherElements.Length() + 1; |
49 | 0 | } Unexecuted instantiation: nsStyleAutoArray<nsStyleImageLayers::Layer>::Length() const Unexecuted instantiation: nsStyleAutoArray<mozilla::StyleAnimation>::Length() const Unexecuted instantiation: nsStyleAutoArray<mozilla::StyleTransition>::Length() const |
50 | 0 | const T& operator[](size_t aIndex) const { |
51 | 0 | return aIndex == 0 ? mFirstElement : mOtherElements[aIndex - 1]; |
52 | 0 | } Unexecuted instantiation: nsStyleAutoArray<nsStyleImageLayers::Layer>::operator[](unsigned long) const Unexecuted instantiation: nsStyleAutoArray<mozilla::StyleTransition>::operator[](unsigned long) const Unexecuted instantiation: nsStyleAutoArray<mozilla::StyleAnimation>::operator[](unsigned long) const |
53 | 0 | T& operator[](size_t aIndex) { |
54 | 0 | return aIndex == 0 ? mFirstElement : mOtherElements[aIndex - 1]; |
55 | 0 | } Unexecuted instantiation: nsStyleAutoArray<nsStyleImageLayers::Layer>::operator[](unsigned long) Unexecuted instantiation: nsStyleAutoArray<mozilla::StyleAnimation>::operator[](unsigned long) Unexecuted instantiation: nsStyleAutoArray<mozilla::StyleTransition>::operator[](unsigned long) |
56 | | |
57 | 0 | void EnsureLengthAtLeast(size_t aMinLen) { |
58 | 0 | if (aMinLen > 0) { |
59 | 0 | mOtherElements.EnsureLengthAtLeast(aMinLen - 1); |
60 | 0 | } |
61 | 0 | } Unexecuted instantiation: nsStyleAutoArray<mozilla::StyleAnimation>::EnsureLengthAtLeast(unsigned long) Unexecuted instantiation: nsStyleAutoArray<nsStyleImageLayers::Layer>::EnsureLengthAtLeast(unsigned long) Unexecuted instantiation: nsStyleAutoArray<mozilla::StyleTransition>::EnsureLengthAtLeast(unsigned long) |
62 | | |
63 | | void SetLengthNonZero(size_t aNewLen) { |
64 | | MOZ_ASSERT(aNewLen > 0); |
65 | | mOtherElements.SetLength(aNewLen - 1); |
66 | | } |
67 | | |
68 | 0 | void TruncateLengthNonZero(size_t aNewLen) { |
69 | 0 | MOZ_ASSERT(aNewLen > 0); |
70 | 0 | MOZ_ASSERT(aNewLen <= Length()); |
71 | 0 | mOtherElements.TruncateLength(aNewLen - 1); |
72 | 0 | } |
73 | | |
74 | | private: |
75 | | T mFirstElement; |
76 | | nsTArray<T> mOtherElements; |
77 | | }; |
78 | | |
79 | | #endif /* nsStyleAutoArray_h_ */ |