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