Files
cocos2d-x
build
cocos
extensions
external
android
ios
include
freetype
jpeg
openssl
png
spidermonkey
js
mozilla
Alignment.h
AllocPolicy.h
AlreadyAddRefed.h
Array.h
ArrayUtils.h
Assertions.h
Atomics.h
Attributes.h
BinarySearch.h
BloomFilter.h
BufferList.h
Casting.h
ChaosMode.h
Char16.h
CheckedInt.h
Compiler.h
Compression.h
DebugOnly.h
Decimal.h
EndianUtils.h
EnumSet.h
EnumTypeTraits.h
EnumeratedArray.h
EnumeratedRange.h
FastBernoulliTrial.h
FloatingPoint.h
Function.h
GuardObjects.h
HashFunctions.h
IndexSequence.h
IntegerPrintfMacros.h
IntegerRange.h
IntegerTypeTraits.h
JSONWriter.h
Likely.h
LinkedList.h
MacroArgs.h
MacroForEach.h
MathAlgorithms.h
Maybe.h
MaybeOneOf.h
MemoryChecking.h
MemoryReporting.h
Move.h
NotNull.h
NullPtr.h
Opaque.h
OperatorNewExtensions.h
Pair.h
PodOperations.h
Poison.h
Range.h
RangedArray.h
RangedPtr.h
ReentrancyGuard.h
RefCountType.h
RefCounted.h
RefPtr.h
ReverseIterator.h
RollingMean.h
SHA1.h
Saturate.h
ScopeExit.h
Scoped.h
SegmentedVector.h
SizePrintfMacros.h
SplayTree.h
Sprintf.h
StackWalk.h
StaticAnalysisFunctions.h
TaggedAnonymousMemory.h
TemplateLib.h
ThreadLocal.h
TimeStamp.h
ToString.h
Tuple.h
TypeTraits.h
TypedEnumBits.h
Types.h
UniquePtr.h
UniquePtrExtensions.h
Unused.h
Variant.h
Vector.h
WeakPtr.h
XorShift128PlusRNG.h
double-conversion.h
fallible.h
mozalloc.h
mozalloc_abort.h
mozalloc_oom.h
utils.h
fdlibm.h
jemalloc_types.h
js-config-32.h
js-config-64.h
js-config.h
js.msg
jsalloc.h
jsapi.h
jsbytecode.h
jsclist.h
jscpucfg.h
jsfriendapi.h
jsperf.h
jsprf.h
jsprototypes.h
jspubtd.h
jstypes.h
jsversion.h
jswrapper.h
mozmemory.h
mozmemory_wrap.h
tiff
uv
v8
webp
websockets
libs
mac
sources
win32
.gitignore
config.json
versions.txt
licenses
simulator
templates
tools
utils
.gitignore
.gitmodules
.travis.yml
README.md
VERSION.md
auto-build-src.bat
auto-build.bat
download-deps.py
gulpfile.js
package.json
setup.py
engine
jsb-adapter
.gitignore
README.md
creator-sp.d.ts
2022-06-25 11:52:00 +08:00

59 lines
1.7 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_Range_h
#define mozilla_Range_h
#include "mozilla/RangedPtr.h"
#include "mozilla/TypeTraits.h"
#include <stddef.h>
namespace mozilla {
// Range<T> is a tuple containing a pointer and a length.
template <typename T>
class Range
{
const RangedPtr<T> mStart;
const RangedPtr<T> mEnd;
public:
Range() : mStart(nullptr, 0), mEnd(nullptr, 0) {}
Range(T* aPtr, size_t aLength)
: mStart(aPtr, aPtr, aPtr + aLength),
mEnd(aPtr + aLength, aPtr, aPtr + aLength)
{}
Range(const RangedPtr<T>& aStart, const RangedPtr<T>& aEnd)
: mStart(aStart.get(), aStart.get(), aEnd.get()),
mEnd(aEnd.get(), aStart.get(), aEnd.get())
{
// Only accept two RangedPtrs within the same range.
aStart.checkIdenticalRange(aEnd);
MOZ_ASSERT(aStart <= aEnd);
}
template<typename U,
class = typename EnableIf<IsConvertible<U (*)[], T (*)[]>::value,
int>::Type>
MOZ_IMPLICIT Range(const Range<U>& aOther)
: mStart(aOther.mStart),
mEnd(aOther.mEnd)
{}
RangedPtr<T> begin() const { return mStart; }
RangedPtr<T> end() const { return mEnd; }
size_t length() const { return mEnd - mStart; }
T& operator[](size_t aOffset) const { return mStart[aOffset]; }
explicit operator bool() const { return mStart != nullptr; }
};
} // namespace mozilla
#endif /* mozilla_Range_h */