NW4F G3d
Loading...
Searching...
No Matches
g3d_ResDefs.h
Go to the documentation of this file.
1#ifndef NW_G3D_RES_DEFS_H_
2#define NW_G3D_RES_DEFS_H_
3
4#include <nw/g3d/g3d_config.h>
5
6#define NW_G3D_RES_ASSERT_INDEX(name, idx) NW_G3D_ASSERT_INDEX_BOUNDS(idx, Get##name##Count())
7
8#define NW_G3D_RES_DIC(offset) ResDicType::ResCast(offset.to_ptr<ResDicType::DataType>())
9
10#define NW_G3D_RES_FIELD_DIC_LOOKUP_IDX_DECL(name)
11 int Get##name##Index(const char* str) const
12 {
13 return NW_G3D_RES_DIC(ref().ofs##name##Dic)->FindIndex(str);
14 }
15 int Get##name##Index(const ResName* str) const
16 {
17 return NW_G3D_RES_DIC(ref().ofs##name##Dic)->FindIndex(str);
18 }
19 const char* Get##name##Name(int elemIndex) const
20 {
21 NW_G3D_RES_ASSERT_INDEX(name, elemIndex);
22 return NW_G3D_RES_DIC(ref().ofs##name##Dic)->GetName(elemIndex);
23 }
24
25
26#define NW_G3D_RES_FIELD_DIC_LOOKUP_DECL(type, name)
27 int Get##name##Count() const { return ref().num##name; }
28 type* Get##name(const char* str)
29 {
30 void* ptr = NW_G3D_RES_DIC(ref().ofs##name##Dic)->Find(str);
31 return type::ResCast(static_cast<type##Data*>(ptr));
32 }
33 type* Get##name(const ResName* str)
34 {
35 void* ptr = NW_G3D_RES_DIC(ref().ofs##name##Dic)->Find(str);
36 return type::ResCast(static_cast<type##Data*>(ptr));
37 }
38 const type* Get##name(const char* str) const
39 {
40 void* ptr = NW_G3D_RES_DIC(ref().ofs##name##Dic)->Find(str);
41 return type::ResCast(static_cast<type##Data*>(ptr));
42 }
43 const type* Get##name(const ResName* str) const
44 {
45 void* ptr = NW_G3D_RES_DIC(ref().ofs##name##Dic)->Find(str);
46 return type::ResCast(static_cast<type##Data*>(ptr));
47 }
49
50
51#define NW_G3D_RES_FIELD_DIC_DECL(type, name)
53 type* Get##name(int elemIndex)
54 {
55 NW_G3D_RES_ASSERT_INDEX(name, elemIndex);
56 void* ptr = NW_G3D_RES_DIC(ref().ofs##name##Dic)->Get(elemIndex);
57 return type::ResCast(static_cast<type##Data*>(ptr));
58 }
59 const type* Get##name(int elemIndex) const
60 {
61 NW_G3D_RES_ASSERT_INDEX(name, elemIndex);
62 void* ptr = NW_G3D_RES_DIC(ref().ofs##name##Dic)->Get(elemIndex);
63 return type::ResCast(static_cast<type##Data*>(ptr));
64 }
65
66
67#define NW_G3D_RES_FIELD_STR_DIC_DECL(name)
69 int Get##name##Count() const { return ref().num##name; }
70 const char* Get##name(const char* str) const
71 {
72 return static_cast<const char*>(NW_G3D_RES_DIC(ref().ofs##name##Dic)->Find(str));
73 }
74 const char* Get##name(const ResName* str) const
75 {
76 return static_cast<const char*>(NW_G3D_RES_DIC(ref().ofs##name##Dic)->Find(str));
77 }
78 const char* Get##name(int elemIndex) const
79 {
80 NW_G3D_RES_ASSERT_INDEX(name, elemIndex);
81 return static_cast<const char*>(NW_G3D_RES_DIC(ref().ofs##name##Dic)->Get(elemIndex));
82 }
83
84
85#define NW_G3D_RES_FIELD_EMPTY_DIC_DECL(name)
87 int Get##name##Count() const { return ref().num##name; }
88
89
90// 配列から指定されたインデックスの type を返す
91// 範囲外のインデックスを指定された場合はアサートする
92#define NW_G3D_RES_FIELD_CLASS_ARRAY_DECL(type, name)
93 int Get##name##Count() const { return ref().num##name; }
94 type* Get##name(int elemIndex)
95 {
96 NW_G3D_RES_ASSERT_INDEX(name, elemIndex);
97 type##Data* pArray = ref().ofs##name##Array.to_ptr<type##Data>();
98 return type::ResCast(&pArray[elemIndex]);
99 }
100 const type* Get##name(int elemIndex) const
101 {
102 NW_G3D_RES_ASSERT_INDEX(name, elemIndex);
103 const type##Data* pArray = ref().ofs##name##Array.to_ptr<type##Data>();
104 return type::ResCast(const_cast<type##Data*>(&pArray[elemIndex]));
105 }
106
107
108#define NW_G3D_RES_FIELD_CLASS_NAMED_ARRAY_DECL(type, name)
110 type* Get##name(int elemIndex)
111 {
112 NW_G3D_RES_ASSERT_INDEX(name, elemIndex);
113 type##Data* pArray = ref().ofs##name##Array.to_ptr<type##Data>();
114 return type::ResCast(&pArray[elemIndex]);
115 }
116 const type* Get##name(int elemIndex) const
117 {
118 NW_G3D_RES_ASSERT_INDEX(name, elemIndex);
119 const type##Data* pArray = ref().ofs##name##Array.to_ptr<type##Data>();
120 return type::ResCast(const_cast<type##Data*>(&pArray[elemIndex]));
121 }
122
123
124#define NW_G3D_RES_FIELD_CLASS_DECL(type, name)
125 type* Get##name() { return type::ResCast(ref().ofs##name.to_ptr<type##Data>()); }
126 const type* Get##name() const { return type::ResCast(ref().ofs##name.to_ptr<type##Data>()); }
127
128
129#define NW_G3D_RES_FIELD_DEREFERENCE_DECL(type)
130 Res##type* Get() { return Res##type::ResCast(ref().ofsRefData.to_ptr<Res##type##Data>()); }
131 const Res##type* Get() const
132 {
133 return Res##type::ResCast(ref().ofsRefData.to_ptr<Res##type##Data>());
134 }
135
136
137#define NW_G3D_RES_FIELD_STRING_DECL(name)
138 const char* Get##name() const { return ref().ofs##name.to_ptr(); }
139
140
141#endif // NW_G3D_RES_DEFS_H_
#define NW_G3D_RES_FIELD_DIC_LOOKUP_IDX_DECL(name)
Definition g3d_ResDefs.h:10
#define NW_G3D_RES_FIELD_DIC_LOOKUP_DECL(type, name)
Definition g3d_ResDefs.h:26
#define NW_G3D_RES_ASSERT_INDEX(name, idx)
Definition g3d_ResDefs.h:6
#define NW_G3D_RES_DIC(offset)
Definition g3d_ResDefs.h:8
#define NW_G3D_ASSERT_INDEX_BOUNDS(index, size)
Definition g3d_assert.h:23