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