/work/obj-fuzz/dist/include/mozilla/IntegerRange.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 | | /* Iterator over ranges of integers */ |
8 | | |
9 | | #ifndef mozilla_IntegerRange_h |
10 | | #define mozilla_IntegerRange_h |
11 | | |
12 | | #include "mozilla/Assertions.h" |
13 | | #include "mozilla/ReverseIterator.h" |
14 | | #include "mozilla/TypeTraits.h" |
15 | | |
16 | | namespace mozilla { |
17 | | |
18 | | namespace detail { |
19 | | |
20 | | template<typename IntTypeT> |
21 | | class IntegerIterator |
22 | | { |
23 | | public: |
24 | | template<typename IntType> |
25 | | explicit IntegerIterator(IntType aCurrent) |
26 | 9.27k | : mCurrent(aCurrent) { } mozilla::detail::IntegerIterator<unsigned int>::IntegerIterator<unsigned int>(unsigned int) Line | Count | Source | 26 | 80 | : mCurrent(aCurrent) { } |
mozilla::detail::IntegerIterator<unsigned long>::IntegerIterator<unsigned long>(unsigned long) Line | Count | Source | 26 | 9.19k | : mCurrent(aCurrent) { } |
Unexecuted instantiation: mozilla::detail::IntegerIterator<int>::IntegerIterator<int>(int) |
27 | | |
28 | | template<typename IntType> |
29 | | explicit IntegerIterator(const IntegerIterator<IntType>& aOther) |
30 | | : mCurrent(aOther.mCurrent) { } |
31 | | |
32 | 9.62k | IntTypeT operator*() const { return mCurrent; } Unexecuted instantiation: mozilla::detail::IntegerIterator<unsigned int>::operator*() const mozilla::detail::IntegerIterator<unsigned long>::operator*() const Line | Count | Source | 32 | 9.62k | IntTypeT operator*() const { return mCurrent; } |
Unexecuted instantiation: mozilla::detail::IntegerIterator<int>::operator*() const |
33 | | |
34 | | /* Increment and decrement operators */ |
35 | | |
36 | 9.62k | IntegerIterator& operator++() { ++mCurrent; return *this; } Unexecuted instantiation: mozilla::detail::IntegerIterator<unsigned int>::operator++() mozilla::detail::IntegerIterator<unsigned long>::operator++() Line | Count | Source | 36 | 9.62k | IntegerIterator& operator++() { ++mCurrent; return *this; } |
Unexecuted instantiation: mozilla::detail::IntegerIterator<int>::operator++() |
37 | 0 | IntegerIterator& operator--() { --mCurrent; return *this; } |
38 | | IntegerIterator operator++(int) { auto ret = *this; ++mCurrent; return ret; } |
39 | | IntegerIterator operator--(int) { auto ret = *this; --mCurrent; return ret; } |
40 | | |
41 | | /* Comparison operators */ |
42 | | |
43 | | template<typename IntType1, typename IntType2> |
44 | | friend bool operator==(const IntegerIterator<IntType1>& aIter1, |
45 | | const IntegerIterator<IntType2>& aIter2); |
46 | | template<typename IntType1, typename IntType2> |
47 | | friend bool operator!=(const IntegerIterator<IntType1>& aIter1, |
48 | | const IntegerIterator<IntType2>& aIter2); |
49 | | template<typename IntType1, typename IntType2> |
50 | | friend bool operator<(const IntegerIterator<IntType1>& aIter1, |
51 | | const IntegerIterator<IntType2>& aIter2); |
52 | | template<typename IntType1, typename IntType2> |
53 | | friend bool operator<=(const IntegerIterator<IntType1>& aIter1, |
54 | | const IntegerIterator<IntType2>& aIter2); |
55 | | template<typename IntType1, typename IntType2> |
56 | | friend bool operator>(const IntegerIterator<IntType1>& aIter1, |
57 | | const IntegerIterator<IntType2>& aIter2); |
58 | | template<typename IntType1, typename IntType2> |
59 | | friend bool operator>=(const IntegerIterator<IntType1>& aIter1, |
60 | | const IntegerIterator<IntType2>& aIter2); |
61 | | |
62 | | private: |
63 | | IntTypeT mCurrent; |
64 | | }; |
65 | | |
66 | | template<typename IntType1, typename IntType2> |
67 | | bool operator==(const IntegerIterator<IntType1>& aIter1, |
68 | | const IntegerIterator<IntType2>& aIter2) |
69 | | { |
70 | | return aIter1.mCurrent == aIter2.mCurrent; |
71 | | } |
72 | | |
73 | | template<typename IntType1, typename IntType2> |
74 | | bool operator!=(const IntegerIterator<IntType1>& aIter1, |
75 | | const IntegerIterator<IntType2>& aIter2) |
76 | 14.2k | { |
77 | 14.2k | return aIter1.mCurrent != aIter2.mCurrent; |
78 | 14.2k | } bool mozilla::detail::operator!=<unsigned int, unsigned int>(mozilla::detail::IntegerIterator<unsigned int> const&, mozilla::detail::IntegerIterator<unsigned int> const&) Line | Count | Source | 76 | 40 | { | 77 | 40 | return aIter1.mCurrent != aIter2.mCurrent; | 78 | 40 | } |
bool mozilla::detail::operator!=<unsigned long, unsigned long>(mozilla::detail::IntegerIterator<unsigned long> const&, mozilla::detail::IntegerIterator<unsigned long> const&) Line | Count | Source | 76 | 14.2k | { | 77 | 14.2k | return aIter1.mCurrent != aIter2.mCurrent; | 78 | 14.2k | } |
Unexecuted instantiation: bool mozilla::detail::operator!=<int, int>(mozilla::detail::IntegerIterator<int> const&, mozilla::detail::IntegerIterator<int> const&) |
79 | | |
80 | | template<typename IntType1, typename IntType2> |
81 | | bool operator<(const IntegerIterator<IntType1>& aIter1, |
82 | | const IntegerIterator<IntType2>& aIter2) |
83 | | { |
84 | | return aIter1.mCurrent < aIter2.mCurrent; |
85 | | } |
86 | | |
87 | | template<typename IntType1, typename IntType2> |
88 | | bool operator<=(const IntegerIterator<IntType1>& aIter1, |
89 | | const IntegerIterator<IntType2>& aIter2) |
90 | | { |
91 | | return aIter1.mCurrent <= aIter2.mCurrent; |
92 | | } |
93 | | |
94 | | template<typename IntType1, typename IntType2> |
95 | | bool operator>(const IntegerIterator<IntType1>& aIter1, |
96 | | const IntegerIterator<IntType2>& aIter2) |
97 | | { |
98 | | return aIter1.mCurrent > aIter2.mCurrent; |
99 | | } |
100 | | |
101 | | template<typename IntType1, typename IntType2> |
102 | | bool operator>=(const IntegerIterator<IntType1>& aIter1, |
103 | | const IntegerIterator<IntType2>& aIter2) |
104 | | { |
105 | | return aIter1.mCurrent >= aIter2.mCurrent; |
106 | | } |
107 | | |
108 | | template<typename IntTypeT> |
109 | | class IntegerRange |
110 | | { |
111 | | public: |
112 | | typedef IntegerIterator<IntTypeT> iterator; |
113 | | typedef IntegerIterator<IntTypeT> const_iterator; |
114 | | typedef ReverseIterator<IntegerIterator<IntTypeT>> reverse_iterator; |
115 | | typedef ReverseIterator<IntegerIterator<IntTypeT>> const_reverse_iterator; |
116 | | |
117 | | template<typename IntType> |
118 | | explicit IntegerRange(IntType aEnd) |
119 | 4.63k | : mBegin(0), mEnd(aEnd) { } mozilla::detail::IntegerRange<unsigned int>::IntegerRange<unsigned int>(unsigned int) Line | Count | Source | 119 | 40 | : mBegin(0), mEnd(aEnd) { } |
mozilla::detail::IntegerRange<unsigned long>::IntegerRange<unsigned long>(unsigned long) Line | Count | Source | 119 | 4.59k | : mBegin(0), mEnd(aEnd) { } |
Unexecuted instantiation: mozilla::detail::IntegerRange<int>::IntegerRange<int>(int) |
120 | | |
121 | | template<typename IntType1, typename IntType2> |
122 | | IntegerRange(IntType1 aBegin, IntType2 aEnd) |
123 | 0 | : mBegin(aBegin), mEnd(aEnd) { } |
124 | | |
125 | 4.63k | iterator begin() const { return iterator(mBegin); } mozilla::detail::IntegerRange<unsigned int>::begin() const Line | Count | Source | 125 | 40 | iterator begin() const { return iterator(mBegin); } |
mozilla::detail::IntegerRange<unsigned long>::begin() const Line | Count | Source | 125 | 4.59k | iterator begin() const { return iterator(mBegin); } |
Unexecuted instantiation: mozilla::detail::IntegerRange<int>::begin() const |
126 | | const_iterator cbegin() const { return begin(); } |
127 | 4.63k | iterator end() const { return iterator(mEnd); } mozilla::detail::IntegerRange<unsigned int>::end() const Line | Count | Source | 127 | 40 | iterator end() const { return iterator(mEnd); } |
mozilla::detail::IntegerRange<unsigned long>::end() const Line | Count | Source | 127 | 4.59k | iterator end() const { return iterator(mEnd); } |
Unexecuted instantiation: mozilla::detail::IntegerRange<int>::end() const |
128 | | const_iterator cend() const { return end(); } |
129 | 0 | reverse_iterator rbegin() const { return reverse_iterator(mEnd); } |
130 | | const_reverse_iterator crbegin() const { return rbegin(); } |
131 | 0 | reverse_iterator rend() const { return reverse_iterator(mBegin); } |
132 | | const_reverse_iterator crend() const { return rend(); } |
133 | | |
134 | | private: |
135 | | IntTypeT mBegin; |
136 | | IntTypeT mEnd; |
137 | | }; |
138 | | |
139 | | template<typename T, bool = IsUnsigned<T>::value> |
140 | | struct GeqZero |
141 | | { |
142 | | static bool check(T t) { |
143 | | return t >= 0; |
144 | | } |
145 | | }; |
146 | | |
147 | | template<typename T> |
148 | | struct GeqZero<T, true> |
149 | | { |
150 | | static bool check(T t) { |
151 | | return true; |
152 | | } |
153 | | }; |
154 | | |
155 | | } // namespace detail |
156 | | |
157 | | template<typename IntType> |
158 | | detail::IntegerRange<IntType> |
159 | | IntegerRange(IntType aEnd) |
160 | 4.63k | { |
161 | 4.63k | static_assert(IsIntegral<IntType>::value, "value must be integral"); |
162 | 4.63k | MOZ_ASSERT(detail::GeqZero<IntType>::check(aEnd), |
163 | 4.63k | "Should never have negative value here"); |
164 | 4.63k | return detail::IntegerRange<IntType>(aEnd); |
165 | 4.63k | } mozilla::detail::IntegerRange<unsigned int> mozilla::IntegerRange<unsigned int>(unsigned int) Line | Count | Source | 160 | 40 | { | 161 | 40 | static_assert(IsIntegral<IntType>::value, "value must be integral"); | 162 | 40 | MOZ_ASSERT(detail::GeqZero<IntType>::check(aEnd), | 163 | 40 | "Should never have negative value here"); | 164 | 40 | return detail::IntegerRange<IntType>(aEnd); | 165 | 40 | } |
mozilla::detail::IntegerRange<unsigned long> mozilla::IntegerRange<unsigned long>(unsigned long) Line | Count | Source | 160 | 4.59k | { | 161 | 4.59k | static_assert(IsIntegral<IntType>::value, "value must be integral"); | 162 | 4.59k | MOZ_ASSERT(detail::GeqZero<IntType>::check(aEnd), | 163 | 4.59k | "Should never have negative value here"); | 164 | 4.59k | return detail::IntegerRange<IntType>(aEnd); | 165 | 4.59k | } |
Unexecuted instantiation: mozilla::detail::IntegerRange<int> mozilla::IntegerRange<int>(int) |
166 | | |
167 | | template<typename IntType1, typename IntType2> |
168 | | detail::IntegerRange<IntType2> |
169 | | IntegerRange(IntType1 aBegin, IntType2 aEnd) |
170 | 0 | { |
171 | 0 | static_assert(IsIntegral<IntType1>::value && IsIntegral<IntType2>::value, |
172 | 0 | "values must both be integral"); |
173 | 0 | static_assert(IsSigned<IntType1>::value == IsSigned<IntType2>::value, |
174 | 0 | "signed/unsigned mismatch"); |
175 | 0 | MOZ_ASSERT(aEnd >= aBegin, "End value should be larger than begin value"); |
176 | 0 | return detail::IntegerRange<IntType2>(aBegin, aEnd); |
177 | 0 | } |
178 | | |
179 | | } // namespace mozilla |
180 | | |
181 | | #endif // mozilla_IntegerRange_h |