RavEngine
Loading...
Searching...
No Matches
SnXmlStringToType.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 SN_XML_STRING_TO_TYPE_H
30#define SN_XML_STRING_TO_TYPE_H
31
32#include "common/PxCoreUtilityTypes.h"
33#include "PxFiltering.h"
34
35#include "foundation/PxString.h"
36
37#include <stdio.h>
38#include <ctype.h>
39
40//Remapping function name for gcc-based systems.
41#ifndef _MSC_VER
42#define _strtoui64 strtoull
43#endif
44
45
46namespace physx { namespace Sn {
47
48 template<typename TDataType>
49 struct StrToImpl
50 {
51 bool compile_error;
52 };
53
54 template<> struct StrToImpl<PxU64> {
55 //Id's (void ptrs) are written to file as unsigned
56 //64 bit integers, so this method gets called more
57 //often than one might think.
58 PX_INLINE void strto( PxU64& ioDatatype,const char*& ioData )
59 {
60 ioDatatype = _strtoui64( ioData, const_cast<char **>(&ioData), 10 );
61 }
62 };
63
64 PX_INLINE PxF32 strToFloat(const char *str,const char **nextScan)
65 {
66 PxF32 ret;
67 while ( *str && isspace(static_cast<unsigned char>(*str))) str++; // skip leading whitespace
68 char temp[256] = "";
69 char *dest = temp;
70 char *end = &temp[255];
71 const char *begin = str;
72 while ( *str && !isspace(static_cast<unsigned char>(*str)) && dest < end ) // copy the number up to the first whitespace or eos
73 {
74 *dest++ = *str++;
75 }
76 *dest = 0;
77 ret = PxF32(strtod(temp,&end));
78 if ( nextScan )
79 {
80 *nextScan = begin+(end-temp);
81 }
82 return ret;
83 }
84
85
86 template<> struct StrToImpl<PxU32> {
87 PX_INLINE void strto( PxU32& ioDatatype,const char*& ioData )
88 {
89 ioDatatype = static_cast<PxU32>( strtoul( ioData,const_cast<char **>(&ioData), 10 ) );
90 }
91 };
92
93 template<> struct StrToImpl<PxI32> {
94 PX_INLINE void strto( PxI32& ioDatatype,const char*& ioData )
95 {
96 ioDatatype = static_cast<PxI32>( strtoul( ioData,const_cast<char **>(&ioData), 10 ) );
97 }
98 };
99
100
101 template<> struct StrToImpl<PxU16> {
102 PX_INLINE void strto( PxU16& ioDatatype,const char*& ioData )
103 {
104 ioDatatype = static_cast<PxU16>( strtoul( ioData,const_cast<char **>(&ioData), 10 ) );
105 }
106 };
107
108 PX_INLINE void eatwhite(const char*& ioData )
109 {
110 if ( ioData )
111 {
112 while( isspace( static_cast<unsigned char>(*ioData) ) )
113 ++ioData;
114 }
115 }
116
117 // copy the source data to the dest buffer until the first whitespace is encountered.
118 // Do not overflow the buffer based on the bufferLen provided.
119 // Advance the input 'ioData' pointer so that it sits just at the next whitespace
120 PX_INLINE void nullTerminateWhite(const char*& ioData,char *buffer,PxU32 bufferLen)
121 {
122 if ( ioData )
123 {
124 char *eof = buffer+(bufferLen-1);
125 char *dest = buffer;
126 while( *ioData && !isspace(static_cast<unsigned char>(*ioData)) && dest < eof )
127 {
128 *dest++ = *ioData++;
129 }
130 *dest = 0;
131 }
132 }
133
134 inline void nonNullTerminateWhite(const char*& ioData )
135 {
136 if ( ioData )
137 {
138 while( *ioData && !isspace( static_cast<unsigned char>(*ioData) ) )
139 ++ioData;
140 }
141 }
142
143 template<> struct StrToImpl<PxF32> {
144 inline void strto( PxF32& ioDatatype,const char*& ioData )
145 {
146 ioDatatype = strToFloat(ioData,&ioData);
147 }
148
149 };
150
151
152 template<> struct StrToImpl<void*> {
153 inline void strto( void*& ioDatatype,const char*& ioData )
154 {
155 PxU64 theData;
156 StrToImpl<PxU64>().strto( theData, ioData );
157 ioDatatype = reinterpret_cast<void*>( size_t( theData ) );
158 }
159 };
160
161
162 template<> struct StrToImpl<physx::PxVec3> {
163 inline void strto( physx::PxVec3& ioDatatype,const char*& ioData )
164 {
165 StrToImpl<PxF32>().strto( ioDatatype[0], ioData );
166 StrToImpl<PxF32>().strto( ioDatatype[1], ioData );
167 StrToImpl<PxF32>().strto( ioDatatype[2], ioData );
168 }
169 };
170
171 template<> struct StrToImpl<PxU8*> {
172 inline void strto( PxU8*& /*ioDatatype*/,const char*& /*ioData*/)
173 {
174 }
175 };
176
177 template<> struct StrToImpl<bool> {
178 inline void strto( bool& ioType,const char*& inValue )
179 {
180 ioType = physx::Pxstricmp( inValue, "true" ) == 0 ? true : false;
181 }
182 };
183
184 template<> struct StrToImpl<PxU8> {
185 PX_INLINE void strto( PxU8& ioType,const char* & inValue)
186 {
187 ioType = static_cast<PxU8>( strtoul( inValue,const_cast<char **>(&inValue), 10 ) );
188 }
189 };
190
191 template<> struct StrToImpl<PxFilterData> {
192 PX_INLINE void strto( PxFilterData& ioType,const char*& inValue)
193 {
194 ioType.word0 = static_cast<PxU32>( strtoul( inValue,const_cast<char **>(&inValue), 10 ) );
195 ioType.word1 = static_cast<PxU32>( strtoul( inValue,const_cast<char **>(&inValue), 10 ) );
196 ioType.word2 = static_cast<PxU32>( strtoul( inValue,const_cast<char **>(&inValue), 10 ) );
197 ioType.word3 = static_cast<PxU32>( strtoul( inValue, NULL, 10 ) );
198 }
199 };
200
201
202 template<> struct StrToImpl<PxQuat> {
203 PX_INLINE void strto( PxQuat& ioType,const char*& inValue )
204 {
205 ioType.x = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
206 ioType.y = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
207 ioType.z = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
208 ioType.w = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
209 }
210 };
211
212 template<> struct StrToImpl<PxTransform> {
213 PX_INLINE void strto( PxTransform& ioType,const char*& inValue)
214 {
215 ioType.q.x = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
216 ioType.q.y = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
217 ioType.q.z = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
218 ioType.q.w = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
219
220 ioType.p[0] = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
221 ioType.p[1] = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
222 ioType.p[2] = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
223 }
224 };
225
226 template<> struct StrToImpl<PxBounds3> {
227 PX_INLINE void strto( PxBounds3& ioType,const char*& inValue)
228 {
229 ioType.minimum[0] = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
230 ioType.minimum[1] = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
231 ioType.minimum[2] = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
232
233 ioType.maximum[0] = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
234 ioType.maximum[1] = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
235 ioType.maximum[2] = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
236 }
237 };
238
239 template<> struct StrToImpl<PxMetaDataPlane> {
240 PX_INLINE void strto( PxMetaDataPlane& ioType,const char*& inValue)
241 {
242 ioType.normal.x = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
243 ioType.normal.y = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
244 ioType.normal.z = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
245 ioType.distance = static_cast<PxReal>( strToFloat( inValue, &inValue ) );
246 }
247 };
248
249
250 template<> struct StrToImpl<PxRigidDynamic*> {
251 PX_INLINE void strto( PxRigidDynamic*& /*ioDatatype*/,const char*& /*ioData*/)
252 {
253 }
254 };
255
256 template<typename TDataType>
257 inline void strto( TDataType& ioType,const char*& ioData )
258 {
259 if ( ioData && *ioData ) StrToImpl<TDataType>().strto( ioType, ioData );
260 }
261
262 template<typename TDataType>
263 inline void strtoLong( TDataType& ioType,const char*& ioData )
264 {
265 if ( ioData && *ioData ) StrToImpl<TDataType>().strto( ioType, ioData );
266 }
267
268 template<typename TDataType>
269 inline void stringToType( const char* inValue, TDataType& ioType )
270 {
271 const char* theValue( inValue );
272 return strto( ioType, theValue );
273 }
274
275} }
276
277#endif
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
This is a quaternion class. For more information on quaternion mathematics consult a mathematics sour...
Definition PxQuat.h:50
float x
Definition PxQuat.h:395
PxRigidDynamic represents a dynamic rigid simulation object in the physics SDK.
Definition PxRigidDynamic.h:82
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
3 Element vector class.
Definition PxVec3.h:50
#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
PxFilterData is user-definable data which gets passed into the collision filtering shader and/or call...
Definition PxFiltering.h:365
Definition PxMetaDataObjects.h:638
Definition SnXmlStringToType.h:50