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/. */
7 #ifndef mozilla_Range_h
8 #define mozilla_Range_h
10 #include "mozilla/NullPtr.h"
11 #include "mozilla/RangedPtr.h"
17 // Range<T> is a tuple containing a pointer and a length.
21 const RangedPtr
<T
> mStart
;
22 const RangedPtr
<T
> mEnd
;
24 typedef void (Range::* ConvertibleToBool
)();
28 Range() : mStart(nullptr, 0), mEnd(nullptr, 0) {}
29 Range(T
* aPtr
, size_t aLength
)
30 : mStart(aPtr
, aPtr
, aPtr
+ aLength
),
31 mEnd(aPtr
+ aLength
, aPtr
, aPtr
+ aLength
)
34 RangedPtr
<T
> start() const { return mStart
; }
35 RangedPtr
<T
> end() const { return mEnd
; }
36 size_t length() const { return mEnd
- mStart
; }
38 T
& operator[](size_t aOffset
) const { return mStart
[aOffset
]; }
40 operator ConvertibleToBool() const { return mStart
? &Range::nonNull
: 0; }
43 } // namespace mozilla
45 #endif /* mozilla_Range_h */