Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
StridedPtr.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2024 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
8
12template <class T>
14{
15public:
16 using value_type = T;
17
19 StridedPtr() = default;
20 StridedPtr(const StridedPtr &inRHS) = default;
21 StridedPtr(T *inPtr, int inStride = sizeof(T)) : mPtr(const_cast<uint8 *>(reinterpret_cast<const uint8 *>(inPtr))), mStride(inStride) { }
22
24 inline StridedPtr & operator = (const StridedPtr &inRHS) = default;
25
27 inline StridedPtr & operator ++ () { mPtr += mStride; return *this; }
28 inline StridedPtr & operator -- () { mPtr -= mStride; return *this; }
29 inline StridedPtr operator ++ (int) { StridedPtr old_ptr(*this); mPtr += mStride; return old_ptr; }
30 inline StridedPtr operator -- (int) { StridedPtr old_ptr(*this); mPtr -= mStride; return old_ptr; }
31 inline StridedPtr operator + (int inOffset) const { StridedPtr new_ptr(*this); new_ptr.mPtr += inOffset * mStride; return new_ptr; }
32 inline StridedPtr operator - (int inOffset) const { StridedPtr new_ptr(*this); new_ptr.mPtr -= inOffset * mStride; return new_ptr; }
33 inline void operator += (int inOffset) { mPtr += inOffset * mStride; }
34 inline void operator -= (int inOffset) { mPtr -= inOffset * mStride; }
35
37 inline int operator - (const StridedPtr &inRHS) const { JPH_ASSERT(inRHS.mStride == mStride); return (mPtr - inRHS.mPtr) / mStride; }
38
40 inline bool operator == (const StridedPtr &inRHS) const { return mPtr == inRHS.mPtr; }
41 inline bool operator != (const StridedPtr &inRHS) const { return mPtr != inRHS.mPtr; }
42 inline bool operator <= (const StridedPtr &inRHS) const { return mPtr <= inRHS.mPtr; }
43 inline bool operator >= (const StridedPtr &inRHS) const { return mPtr >= inRHS.mPtr; }
44 inline bool operator < (const StridedPtr &inRHS) const { return mPtr < inRHS.mPtr; }
45 inline bool operator > (const StridedPtr &inRHS) const { return mPtr > inRHS.mPtr; }
46
48 inline T & operator * () const { return *reinterpret_cast<T *>(mPtr); }
49 inline T * operator -> () const { return reinterpret_cast<T *>(mPtr); }
50 inline T & operator [] (int inOffset) const { uint8 *ptr = mPtr + inOffset * mStride; return *reinterpret_cast<T *>(ptr); }
51
53 inline T * GetPtr() const { return reinterpret_cast<T *>(mPtr); }
54
56 inline int GetStride() const { return mStride; }
57
58private:
59 uint8 * mPtr = nullptr;
60 int mStride = 0;
61};
62
std::uint8_t uint8
Definition: Core.h:453
#define JPH_EXPORT
Definition: Core.h:236
#define JPH_NAMESPACE_END
Definition: Core.h:378
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:372
DVec3 operator*(double inV1, DVec3Arg inV2)
Definition: DVec3.inl:451
#define JPH_ASSERT(...)
Definition: IssueReporting.h:33
Definition: StridedPtr.h:14
StridedPtr()=default
Constructors.
T * GetPtr() const
Explicit conversion.
Definition: StridedPtr.h:53
T value_type
Definition: StridedPtr.h:16
StridedPtr(T *inPtr, int inStride=sizeof(T))
Definition: StridedPtr.h:21
StridedPtr(const StridedPtr &inRHS)=default
int GetStride() const
Get stride in bytes.
Definition: StridedPtr.h:56