1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: ut_ResDeclMacros.h 4 5 Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Revision: 16815 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NW_UT_RESDECLMACROS_H_ 17 #define NW_UT_RESDECLMACROS_H_ 18 19 #include <nw/types.h> 20 #include <nw/ut/ut_ResTypes.h> 21 #include <nw/ut/ut_Iterator.h> 22 #include <nw/ut/ut_ResArray.h> 23 #include <cstring> 24 25 26 #define NW_RES_FIELD_PRIMITIVE_DECL( type, name ) \ 27 type Get##name() const { return static_cast<type>(ref().m_##name); } \ 28 void Set##name(type value) { ref().m_##name = value; } \ 29 30 31 #define NW_RES_FIELD_BOOL_PRIMITIVE_DECL( name ) \ 32 bool Is##name() const { return static_cast<bool>(ref().m_Is##name); } \ 33 void Set##name(bool value) { ref().m_Is##name = value; } \ 34 35 36 #define NW_RES_FIELD_STRING_DECL( name ) \ 37 const char* Get##name() const { return ref().to##name.to_ptr(); } \ 38 39 40 #define NW_RES_FIELD_CLASS_DECL( type, name ) \ 41 type Get##name() { return type( ref().to##name.to_ptr() ); } \ 42 const type Get##name() const { return type( ref().to##name.to_ptr() ); } \ 43 44 #define NW_RES_FIELD_STRUCT_DECL( type, name ) \ 45 type& Get##name() { return ref().m_##name; } \ 46 const type& Get##name() const { return ref().m_##name; } \ 47 void Set##name(const type& value) { ref().m_##name = value; } \ 48 49 #define NW_RES_FIELD_VECTOR2_DECL( type, name ) \ 50 void Set##name( f32 x, f32 y ) { ref().m_##name.Set(x, y); } \ 51 const type& Get##name() const { return ref().m_##name; } \ 52 void Set##name(const type& value) { ref().m_##name = value; } \ 53 54 #define NW_RES_FIELD_VECTOR3_DECL( type, name ) \ 55 void Set##name( f32 x, f32 y, f32 z ) { ref().m_##name.Set(x, y, z); } \ 56 const type& Get##name() const { return ref().m_##name; } \ 57 void Set##name(const type& value) { ref().m_##name = value; } \ 58 59 #define NW_RES_FIELD_RECT_DECL( type, name ) \ 60 void Set##name( f32 l, f32 r, f32 b, f32 t ) { ref().m_##name.Set(l, r, b, t); } \ 61 const type& Get##name() const { return ref().m_##name; } \ 62 void Set##name(const type& value) { ref().m_##name = value; } \ 63 64 #define NW_RES_FIELD_FLOAT_COLOR_DECL( type, name ) \ 65 void Set##name( f32 r, f32 g, f32 b ) { ref().m_##name.Set(r, g, b); } \ 66 void Set##name( f32 r, f32 g, f32 b, f32 a ) { ref().m_##name.Set(r, g, b, a); } \ 67 const type& Get##name() const { return ref().m_##name; } \ 68 void Set##name(const type& value) { ref().m_##name = value; } \ 69 70 #define NW_RES_FIELD_FLOAT_U32_COLOR_DECL( type, name ) \ 71 u32 Get##name##U32() const { return ref().m_##name##U32; } \ 72 void Set##name( f32 r, f32 g, f32 b ) { ref().m_##name.Set(r, g, b); ref().m_##name##U32 = ref().m_##name.ToPicaU32(); } \ 73 void Set##name( f32 r, f32 g, f32 b, f32 a ) { ref().m_##name.Set(r, g, b, a); ref().m_##name##U32 = ref().m_##name.ToPicaU32(); } \ 74 const type& Get##name() const { return ref().m_##name; } \ 75 void Set##name(const type& value) { ref().m_##name = value; ref().m_##name##U32 = ref().m_##name.ToPicaU32(); } \ 76 77 #define NW_RES_FIELD_RESSTRUCT_DECL( type, name ) \ 78 type Get##name() { return type( &(ref().m_##name) ); } \ 79 const type Get##name() const { return type( &(ref().m_##name) ); } \ 80 type##Data& Get##name##Data() { return ref().m_##name; } \ 81 const type##Data& Get##name##Data() const { return ref().m_##name; } \ 82 83 #define NW_RES_FIELD_CONST_RESSTRUCT_DECL( type, name ) \ 84 const type Get##name() const { return type( &(ref().m_##name) ); } \ 85 const type##Data& Get##name##Data() const { return ref().m_##name; } \ 86 87 #define NW_RES_FIELD_PRIMITIVE_FIXED_LIST_DECL( type, name ) \ 88 s32 Get##name##Count() const \ 89 { return sizeof(ref().m_##name) / sizeof(type); } \ 90 type Get##name(int idx) const \ 91 { NW_INDEX_ASSERT( name, idx ); return ref().m_##name[ idx ]; } \ 92 void Set##name(int idx, type value ) \ 93 { NW_INDEX_ASSERT( name, idx ); ref().m_##name[ idx ] = value; } \ 94 nw::ut::internal::ResArray<type, nw::ut::internal::ResArrayPrimitiveTraits> Get##name() \ 95 { return nw::ut::internal::ResArray<type, nw::ut::internal::ResArrayPrimitiveTraits>( &(ref().m_##name[ 0 ]), Get##name##Count() ); } \ 96 const nw::ut::internal::ResArray<const type, nw::ut::internal::ResArrayPrimitiveTraits> Get##name() const \ 97 { return nw::ut::internal::ResArray<const type, nw::ut::internal::ResArrayPrimitiveTraits>( &(ref().m_##name[ 0 ]), Get##name##Count() ); } \ 98 99 100 #define NW_RES_FIELD_STRING_FIXED_LIST_DECL( name ) \ 101 s32 Get##name##Count() const \ 102 { return sizeof(ref().to##name) / sizeof(nw::ut::BinString); } \ 103 const char* Get##name(int idx) const \ 104 { NW_INDEX_ASSERT( name, idx ); return ref().to##name[ idx ].to_ptr(); } \ 105 const nw::ut::internal::ResArray<const nw::ut::BinString, nw::ut::internal::ResArrayPrimitiveTraits> Get##name() const \ 106 { return nw::ut::internal::ResArray<const nw::ut::BinString, nw::ut::internal::ResArrayPrimitiveTraits>( &(ref().to##name[0]), Get##name##Count() ); } \ 107 108 109 #define NW_RES_FIELD_CLASS_FIXED_LIST_DECL( type, name ) \ 110 s32 Get##name##Count() const \ 111 { return sizeof(ref().to##name) / sizeof(nw::ut::Offset); } \ 112 type Get##name(int idx) \ 113 { NW_INDEX_ASSERT( name, idx ); return type( ref().to##name[ idx ].to_ptr() ); } \ 114 const type Get##name(int idx) const \ 115 { return type( ref().to##name[ idx ].to_ptr() ); } \ 116 nw::ut::internal::ResArray<type, nw::ut::internal::ResArrayClassTraits> Get##name() \ 117 { return nw::ut::internal::ResArray<type, nw::ut::internal::ResArrayClassTraits>( &(ref().to##name[ 0 ]), Get##name##Count() ); } \ 118 const nw::ut::internal::ResArray<const type, nw::ut::internal::ResArrayClassTraits> Get##name() const \ 119 { return nw::ut::internal::ResArray<const type, nw::ut::internal::ResArrayClassTraits>( &(ref().to##name[ 0 ]), Get##name##Count() ); } \ 120 121 122 #define NW_RES_FIELD_STRUCT_FIXED_LIST_DECL( type, name ) \ 123 s32 Get##name##Count() const \ 124 { return sizeof(ref().m_##name) / sizeof(type##Data); } \ 125 type Get##name(int idx) \ 126 { NW_INDEX_ASSERT( name, idx ); return type( &(ref().m_##name[ idx ]) ); } \ 127 const type Get##name(int idx) const \ 128 { NW_INDEX_ASSERT( name, idx ); return type( &(ref().m_##name[ idx ]) ); } \ 129 type##Data& Get##name##Data(int idx) \ 130 { NW_INDEX_ASSERT( name, idx ); return ref().m_##name[ idx ]; } \ 131 const type##Data& Get##name##Data(int idx) const \ 132 { NW_INDEX_ASSERT( name, idx ); return ref().m_##name[ idx ]; } \ 133 type##Data* Get##name##Data() { return ref().m_##name; } \ 134 const type##Data* Get##name##Data() const { return ref().m_##name; } \ 135 136 137 #define NW_RES_FIELD_PRIMITIVE_LIST_DECL( type, name ) \ 138 s32 Get##name##Count() const \ 139 { return ref().m_##name##TableCount; } \ 140 type Get##name(int idx) const \ 141 { \ 142 NW_INDEX_ASSERT( name, idx ); \ 143 const type* tbl_ptr = static_cast<const type*>( ref().to##name##Table.to_table_ptr() ); \ 144 return tbl_ptr[ idx ]; \ 145 } \ 146 void Set##name(int idx, type value) \ 147 { \ 148 NW_INDEX_ASSERT( name, idx ); \ 149 type* tbl_ptr = Get##name(); \ 150 tbl_ptr[ idx ] = value; \ 151 } \ 152 type* Get##name() \ 153 { return static_cast<type*>(ref().to##name##Table.to_table_ptr()); } \ 154 const type* Get##name() const \ 155 { return static_cast<const type*>(ref().to##name##Table.to_table_ptr()); } \ 156 157 158 159 #define NW_RES_FIELD_STRING_LIST_DECL( name ) \ 160 s32 Get##name##Count() const \ 161 { return ref().m_##name##TableCount; } \ 162 const char* Get##name(int idx) const \ 163 { \ 164 NW_INDEX_ASSERT( name, idx ); \ 165 const BinString* tbl_ptr = static_cast<const BinString*>( ref().to##name##Table.to_table_ptr() ); \ 166 return tbl_ptr[ idx ].to_ptr(); \ 167 } \ 168 169 170 #define NW_RES_FIELD_CLASS_LIST_DECL( type, name ) \ 171 s32 Get##name##Count() const \ 172 { return ref().m_##name##TableCount; } \ 173 type Get##name(int idx) \ 174 { \ 175 NW_INDEX_ASSERT( name, idx ); \ 176 nw::ut::Offset* tbl_ptr = static_cast<nw::ut::Offset*>( ref().to##name##Table.to_table_ptr() ); \ 177 return type( tbl_ptr[ idx ].to_ptr() ); \ 178 } \ 179 const type Get##name(int idx) const \ 180 { \ 181 NW_INDEX_ASSERT( name, idx ); \ 182 const nw::ut::Offset* tbl_ptr = static_cast<const nw::ut::Offset*>( ref().to##name##Table.to_table_ptr() ); \ 183 return type( tbl_ptr[ idx ].to_ptr() ); \ 184 } \ 185 nw::ut::internal::ResArray<type, nw::ut::internal::ResArrayClassTraits> Get##name() \ 186 { \ 187 return nw::ut::internal::ResArray<type, nw::ut::internal::ResArrayClassTraits>( ref().to##name##Table.to_table_ptr(), Get##name##Count() ); \ 188 } \ 189 const nw::ut::internal::ResArray<const type, nw::ut::internal::ResArrayClassTraits> Get##name() const \ 190 { \ 191 return nw::ut::internal::ResArray<const type, nw::ut::internal::ResArrayClassTraits>( ref().to##name##Table.to_table_ptr(), Get##name##Count() ); \ 192 } \ 193 194 195 #define NW_RES_FIELD_STRUCT_LIST_DECL( type, name ) \ 196 s32 Get##name##Count() const \ 197 { return ref().m_##name##TableCount; } \ 198 type##Data* Get##name##Data() \ 199 { \ 200 return static_cast<type##Data*>( ref().to##name##Table.to_table_ptr() ); \ 201 } \ 202 const type##Data* Get##name##Data() const \ 203 { \ 204 return static_cast<const type##Data*>( ref().to##name##Table.to_table_ptr() ); \ 205 } \ 206 type##Data& Get##name##Data(int idx) \ 207 { \ 208 NW_INDEX_ASSERT( name, idx ); \ 209 type##Data* tbl_ptr = this->Get##name##Data(); \ 210 return tbl_ptr[ idx ]; \ 211 } \ 212 const type##Data& Get##name##Data(int idx) const \ 213 { \ 214 NW_INDEX_ASSERT( name, idx ); \ 215 const type##Data* tbl_ptr = this->Get##name##Data(); \ 216 return tbl_ptr[ idx ]; \ 217 } \ 218 type Get##name(int idx) \ 219 { \ 220 return type( &(this->Get##name##Data(idx)) ); \ 221 } \ 222 const type Get##name(int idx) const \ 223 { \ 224 return type( &(this->Get##name##Data(idx)) ); \ 225 } \ 226 227 228 #define NW_RES_FIELD_CLASS_DIC_DECL( type, name, ResDicType ) \ 229 s32 Get##name##Count() const \ 230 { \ 231 return ref().m_##name##DicCount; \ 232 } \ 233 type Get##name(int idx) \ 234 { \ 235 ResDicType dic = ResDicType( ref().to##name##Dic.to_ptr() ); \ 236 NW_INDEX_ASSERT( name, idx ); \ 237 return type( dic[ idx ] ); \ 238 } \ 239 type Get##name(const char* key) \ 240 { \ 241 ResDicType dic = ResDicType( ref().to##name##Dic.to_ptr() ); \ 242 return type( dic[ key ] ); \ 243 } \ 244 const type Get##name(int idx) const \ 245 { \ 246 NW_INDEX_ASSERT( name, idx ); \ 247 ResDicType dic = ResDicType( ref().to##name##Dic.to_ptr() ); \ 248 return type( dic[ idx ] ); \ 249 } \ 250 const type Get##name(const char* key) const \ 251 { \ 252 ResDicType dic = ResDicType( ref().to##name##Dic.to_ptr() ); \ 253 return type( dic[ key ] ); \ 254 } \ 255 s32 Get##name##Index(const char* key) const \ 256 { \ 257 ResDicType dic = ResDicType( ref().to##name##Dic.to_ptr() ); \ 258 return dic.GetIndex( key ); \ 259 } \ 260 nw::ut::internal::ResArray< type, nw::ut::internal::ResArrayDicTraits<ResDicType##Data>::Traits > Get##name() \ 261 { \ 262 ResDicType dic = ResDicType( ref().to##name##Dic.to_ptr() ); \ 263 return nw::ut::internal::ResArray< \ 264 type, \ 265 nw::ut::internal::ResArrayDicTraits<ResDicType##Data>::Traits \ 266 >( (dic.IsValid()) ? dic.ref().GetBeginNode() : NULL, Get##name##Count() ); \ 267 } \ 268 const nw::ut::internal::ResArray< const type, nw::ut::internal::ResArrayDicTraits<ResDicType##Data>::Traits > Get##name() const \ 269 { \ 270 ResDicType dic = ResDicType( ref().to##name##Dic.to_ptr() ); \ 271 return nw::ut::internal::ResArray< \ 272 const type, \ 273 nw::ut::internal::ResArrayDicTraits<ResDicType##Data>::Traits \ 274 >( (dic.IsValid()) ? dic.ref().GetBeginNode() : NULL, Get##name##Count() ); \ 275 } \ 276 277 278 #define NW_RES_FIELD_PRIMITIVE_LIST_INLINE_DECL( type, name ) \ 279 s32 Get##name##Count() const \ 280 { return ref().m_##name##Count; } \ 281 type Get##name(int idx) const \ 282 { \ 283 NW_INDEX_ASSERT( name, idx ); \ 284 return ref().m_##name##Table[ idx ]; \ 285 } \ 286 void Set##name(int idx, type value) \ 287 { \ 288 NW_INDEX_ASSERT( name, idx ); \ 289 ref().m_##name##Table[ idx ] = value; \ 290 } \ 291 type* Get##name() \ 292 { return static_cast<type*>(ref().m_##name##Table); } \ 293 const type* Get##name() const \ 294 { return static_cast<const type*>(ref().m_##name##Table); } \ 295 296 297 #define NW_RES_FIELD_STRING_LIST_INLINE_DECL( name ) \ 298 s32 Get##name##Count() const \ 299 { return ref().m_##name##Count; } \ 300 const char* Get##name(int idx) const \ 301 { \ 302 NW_INDEX_ASSERT( name, idx ); \ 303 return ref().m_##name##Table[ idx ].to_ptr(); \ 304 } \ 305 306 307 #define NW_RES_FIELD_CLASS_LIST_INLINE_DECL( type, name ) \ 308 s32 Get##name##Count() const \ 309 { return ref().m_##name##Count; } \ 310 type Get##name(int idx) \ 311 { \ 312 NW_INDEX_ASSERT( name, idx ); \ 313 return type( ref().m_##name##Table[ idx ].to_ptr() ); \ 314 } \ 315 const type Get##name(int idx) const \ 316 { \ 317 NW_INDEX_ASSERT( name, idx ); \ 318 return type( ref().m_##name##Table[ idx ].to_ptr() ); \ 319 } \ 320 nw::ut::internal::ResArray<type, nw::ut::internal::ResArrayClassTraits> Get##name() \ 321 { \ 322 return nw::ut::internal::ResArray< \ 323 type, \ 324 nw::ut::internal::ResArrayClassTraits \ 325 >( &(ref().m_##name##Table[0]), Get##name##Count() ); \ 326 } \ 327 const nw::ut::internal::ResArray<const type, nw::ut::internal::ResArrayClassTraits> Get##name() const \ 328 { \ 329 return nw::ut::internal::ResArray< \ 330 const type, \ 331 nw::ut::internal::ResArrayClassTraits \ 332 >( &(ref().m_##name##Table[0]), Get##name##Count() ); \ 333 } \ 334 335 #if defined(NW_USE_COMMAND_CACHE) 336 337 #define NW_RES_FIELD_COMMAND_BUFFER() \ 338 u32* GetCommandBuffer() \ 339 { \ 340 return &ref().m_CommandBuffer[0]; \ 341 } \ 342 const u32* GetCommandBuffer() const \ 343 { \ 344 return &ref().m_CommandBuffer[0]; \ 345 } \ 346 347 #else 348 #define NW_RES_FIELD_COMMAND_BUFFER() 349 #endif 350 351 #endif /* NW_UT_RESUTIL_H_ */ 352