PxMetaData.h
Go to the documentation of this file.
1 //
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions
4 // are met:
5 // * Redistributions of source code must retain the above copyright
6 // notice, this list of conditions and the following disclaimer.
7 // * Redistributions in binary form must reproduce the above copyright
8 // notice, this list of conditions and the following disclaimer in the
9 // documentation and/or other materials provided with the distribution.
10 // * Neither the name of NVIDIA CORPORATION nor the names of its
11 // contributors may be used to endorse or promote products derived
12 // from this software without specific prior written permission.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
15 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 //
26 // Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
27 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
28 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
29 
30 
31 #ifndef PX_PHYSICS_METADATA_H
32 #define PX_PHYSICS_METADATA_H
33 
37 #include "foundation/Px.h"
38 #include "foundation/PxIO.h"
39 #include "PxMetaDataFlags.h"
40 
41 
42 #if !PX_DOXYGEN
43 namespace physx
44 {
45 #endif
46 
53  {
54  const char* type;
55  const char* name;
62  };
63 
64  #define PX_STORE_METADATA(stream, metaData) stream.write(&metaData, sizeof(PxMetaDataEntry))
65 
66  #define PX_SIZE_OF(Class, Member) sizeof((reinterpret_cast<Class*>(0))->Member)
67 
71  #define PX_DEF_BIN_METADATA_ITEM(stream, Class, type, name, flags) \
72  { \
73  PxMetaDataEntry tmp = { #type, #name, PxU32(PX_OFFSET_OF_RT(Class, name)), PX_SIZE_OF(Class, name), \
74  1, 0, flags, 0}; \
75  PX_STORE_METADATA(stream, tmp); \
76  }
77 
82  #define PX_DEF_BIN_METADATA_ITEMS(stream, Class, type, name, flags, count) \
83  { \
84  PxMetaDataEntry tmp = { #type, #name, PxU32(PX_OFFSET_OF_RT(Class, name)), PX_SIZE_OF(Class, name), \
85  count, 0, flags, 0}; \
86  PX_STORE_METADATA(stream, tmp); \
87  }
88 
94  #define PX_DEF_BIN_METADATA_ITEMS_AUTO(stream, Class, type, name, flags) \
95  { \
96  PxMetaDataEntry tmp = { #type, #name, PxU32(PX_OFFSET_OF_RT(Class, name)), PX_SIZE_OF(Class, name), \
97  sizeof((reinterpret_cast<Class*>(0))->name)/sizeof(type), 0, flags, 0}; \
98  PX_STORE_METADATA(stream, tmp); \
99  }
100 
104  #define PX_DEF_BIN_METADATA_CLASS(stream, Class) \
105  { \
106  PxMetaDataEntry tmp = { #Class, 0, 0, sizeof(Class), 0, 0, PxMetaDataFlag::eCLASS, 0 }; \
107  PX_STORE_METADATA(stream, tmp); \
108  }
109 
113  #define PX_DEF_BIN_METADATA_VCLASS(stream, Class) \
114  { \
115  PxMetaDataEntry tmp = { #Class, 0, 0, sizeof(Class), 0, 0, PxMetaDataFlag::eCLASS|PxMetaDataFlag::eVIRTUAL, 0}; \
116  PX_STORE_METADATA(stream, tmp); \
117  }
118 
122  #define PX_DEF_BIN_METADATA_TYPEDEF(stream, newType, oldType) \
123  { \
124  PxMetaDataEntry tmp = { #newType, #oldType, 0, 0, 0, 0, PxMetaDataFlag::eTYPEDEF, 0 }; \
125  PX_STORE_METADATA(stream, tmp); \
126  }
127 
131  #define PX_DEF_BIN_METADATA_BASE_CLASS(stream, Class, BaseClass) \
132  { \
133  Class* myClass = reinterpret_cast<Class*>(42); \
134  BaseClass* s = static_cast<BaseClass*>(myClass); \
135  const PxU32 offset = PxU32(size_t(s) - size_t(myClass)); \
136  PxMetaDataEntry tmp = { #Class, #BaseClass, offset, sizeof(Class), 0, 0, PxMetaDataFlag::eCLASS, 0 }; \
137  PX_STORE_METADATA(stream, tmp); \
138  }
139 
143  #define PX_DEF_BIN_METADATA_UNION(stream, Class, name) \
144  { \
145  PxMetaDataEntry tmp = { #Class, 0, PxU32(PX_OFFSET_OF_RT(Class, name)), PX_SIZE_OF(Class, name), \
146  1, 0, PxMetaDataFlag::eUNION, 0 }; \
147  PX_STORE_METADATA(stream, tmp); \
148  }
149 
153  #define PX_DEF_BIN_METADATA_UNION_TYPE(stream, Class, type, enumValue) \
154  { \
155  PxMetaDataEntry tmp = { #Class, #type, enumValue, 0, 0, 0, PxMetaDataFlag::eUNION, 0 }; \
156  PX_STORE_METADATA(stream, tmp); \
157  }
158 
162  #define PX_DEF_BIN_METADATA_EXTRA_ITEM(stream, Class, type, control, align) \
163  { \
164  PxMetaDataEntry tmp = { #type, 0, PxU32(PX_OFFSET_OF_RT(Class, control)), sizeof(type), 0, PxU32(PX_SIZE_OF(Class, control)), \
165  PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_ITEM, align }; \
166  PX_STORE_METADATA(stream, tmp); \
167  }
168 
172  #define PX_DEF_BIN_METADATA_EXTRA_ITEMS(stream, Class, type, control, count, flags, align) \
173  { \
174  PxMetaDataEntry tmp = { #type, 0, PxU32(PX_OFFSET_OF_RT(Class, control)), PxU32(PX_SIZE_OF(Class, control)), \
175  PxU32(PX_OFFSET_OF_RT(Class, count)), PxU32(PX_SIZE_OF(Class, count)), \
176  PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_ITEMS|flags, align }; \
177  PX_STORE_METADATA(stream, tmp); \
178  }
179 
185  #define PX_DEF_BIN_METADATA_EXTRA_ITEMS_MASKED_CONTROL(stream, Class, type, control, controlMask ,count, flags, align) \
186  { \
187  PxMetaDataEntry tmp = { #type, 0, PxU32(PX_OFFSET_OF_RT(Class, control)), PxU32(PX_SIZE_OF(Class, control)), \
188  PxU32(PX_OFFSET_OF_RT(Class, count)), PxU32(PX_SIZE_OF(Class, count)), \
189  PxMetaDataFlag::eCONTROL_MASK|PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_ITEMS|flags|(controlMask & PxMetaDataFlag::eCONTROL_MASK_RANGE) << 16, \
190  align}; \
191  PX_STORE_METADATA(stream, tmp); \
192  }
193 
198  #define PX_DEF_BIN_METADATA_EXTRA_ARRAY(stream, Class, type, dyn_count, align, flags) \
199  { \
200  PxMetaDataEntry tmp = { #type, 0, PxU32(PX_OFFSET_OF_RT(Class, dyn_count)), PX_SIZE_OF(Class, dyn_count), align, 0, \
201  PxMetaDataFlag::eEXTRA_DATA|flags, align }; \
202  PX_STORE_METADATA(stream, tmp); \
203  }
204 
208  #define PX_DEF_BIN_METADATA_EXTRA_NAME(stream, Class, control, align) \
209  { \
210  PxMetaDataEntry tmp = { "char", "string", 0, 0, 0, 0, PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_NAME, align }; \
211  PX_STORE_METADATA(stream, tmp); \
212  }
213 
217  #define PX_DEF_BIN_METADATA_EXTRA_ALIGN(stream, Class, align) \
218  { \
219  PxMetaDataEntry tmp = { "PxU8", "Alignment", 0, 0, 0, 0, PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eALIGNMENT, align}; \
220  PX_STORE_METADATA(stream, tmp); \
221  }
222 
223 #if !PX_DOXYGEN
224 } // namespace physx
225 #endif
226 
228 #endif
Definition: GuContactBuffer.h:37
PxU32 count
Number of items of type Type (0 for dynamic sizes)
Definition: PxMetaData.h:58
PxU32 alignment
Explicit alignment.
Definition: PxMetaData.h:61
PxU32 offset
Offset from the start of the class (ie from "this", field is located at "this"+Offset) ...
Definition: PxMetaData.h:56
const char * type
Field type (bool, byte, quaternion, etc)
Definition: PxMetaData.h:54
PxU32 flags
Field parameters.
Definition: PxMetaData.h:60
const char * name
Field name (appears exactly as in the source file)
Definition: PxMetaData.h:55
uint32_t PxU32
Definition: Px.h:48
Struct to store meta data definitions.
Definition: PxMetaData.h:52
PxU32 offsetSize
Offset of dynamic size param, for dynamic arrays.
Definition: PxMetaData.h:59
PxU32 size
sizeof(Type)
Definition: PxMetaData.h:57