RavEngine
Loading...
Searching...
No Matches
PxBasicTemplates.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef PX_BASIC_TEMPLATES_H
30#define PX_BASIC_TEMPLATES_H
31
32#include "foundation/PxPreprocessor.h"
33
34#if !PX_DOXYGEN
35namespace physx
36{
37#endif
38 template <typename A>
39 struct PxEqual
40 {
41 bool operator()(const A& a, const A& b) const
42 {
43 return a == b;
44 }
45 };
46
47 template <typename A>
48 struct PxLess
49 {
50 bool operator()(const A& a, const A& b) const
51 {
52 return a < b;
53 }
54 };
55
56 template <typename A>
57 struct PxGreater
58 {
59 bool operator()(const A& a, const A& b) const
60 {
61 return a > b;
62 }
63 };
64
65 template <class F, class S>
66 class PxPair
67 {
68 public:
69 F first;
70 S second;
71 PX_CUDA_CALLABLE PxPair() : first(F()), second(S())
72 {
73 }
74 PX_CUDA_CALLABLE PxPair(const F& f, const S& s) : first(f), second(s)
75 {
76 }
77 PX_CUDA_CALLABLE PxPair(const PxPair& p) : first(p.first), second(p.second)
78 {
79 }
80 // CN - fix for /.../PxBasicTemplates.h(61) : warning C4512: 'physx::PxPair<F,S>' : assignment operator could
81 // not be generated
82 PX_CUDA_CALLABLE PxPair& operator=(const PxPair& p)
83 {
84 first = p.first;
85 second = p.second;
86 return *this;
87 }
88 PX_CUDA_CALLABLE bool operator==(const PxPair& p) const
89 {
90 return first == p.first && second == p.second;
91 }
92 PX_CUDA_CALLABLE bool operator<(const PxPair& p) const
93 {
94 if (first < p.first)
95 return true;
96 else
97 return !(p.first < first) && (second < p.second);
98 }
99 };
100
101 template <unsigned int A>
102 struct PxLogTwo
103 {
104 static const unsigned int value = PxLogTwo<(A >> 1)>::value + 1;
105 };
106 template <>
107 struct PxLogTwo<1>
108 {
109 static const unsigned int value = 0;
110 };
111
112 template <typename T>
114 {
115 typedef T Type;
116 };
117 template <typename T>
118 struct PxUnConst<const T>
119 {
120 typedef T Type;
121 };
122
123 template <typename T>
124 T PxPointerOffset(void* p, ptrdiff_t offset)
125 {
126 return reinterpret_cast<T>(reinterpret_cast<char*>(p) + offset);
127 }
128 template <typename T>
129 T PxPointerOffset(const void* p, ptrdiff_t offset)
130 {
131 return reinterpret_cast<T>(reinterpret_cast<const char*>(p) + offset);
132 }
133
134 template <class T>
135 PX_CUDA_CALLABLE PX_INLINE void PxSwap(T& x, T& y)
136 {
137 const T tmp = x;
138 x = y;
139 y = tmp;
140 }
141
142#if !PX_DOXYGEN
143} // namespace physx
144#endif
145
146#endif
147
Definition PxBasicTemplates.h:67
#define PX_INLINE
Definition PxPreprocessor.h:320
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition PxBasicTemplates.h:40
Definition PxBasicTemplates.h:58
Definition PxBasicTemplates.h:49
Definition PxBasicTemplates.h:103
Definition PxBasicTemplates.h:114