common.h

changeset 37
c349dca807f9
parent 36
a8838b5f1213
child 41
47e686c96d8f
equal deleted inserted replaced
36:a8838b5f1213 37:c349dca807f9
124 #ifndef __MAIN_CXX__ 124 #ifndef __MAIN_CXX__
125 extern const char** g_Keywords; 125 extern const char** g_Keywords;
126 #endif 126 #endif
127 bool IsKeyword (str s); 127 bool IsKeyword (str s);
128 128
129 // Script mark -- also serves as reference type
130 struct ScriptMark {
131 int type;
132 str name;
133 size_t pos;
134 };
135
136 struct ScriptMarkReference {
137 unsigned int num;
138 size_t pos;
139 };
140
141 // ====================================================================
142 // Finds a byte in the given value.
143 template <class T> unsigned char GetByteIndex (T a, unsigned int b) {
144 if (b >= sizeof (T))
145 error ("CharByte: tried to get byte %u out of a %u-byte %s\n",
146 b, sizeof (T), typeid (T).name());
147
148 unsigned long p1 = pow<unsigned long> (256, b);
149 unsigned long p2 = pow<unsigned long> (256, b+1);
150 unsigned long r = (a % p2) / p1;
151
152 if (r > 256)
153 error ("DataBuffer::CharByte: result %lu too big!", r);
154
155 unsigned char ur = static_cast<unsigned char> (r);
156 return ur;
157 }
158
129 #endif // __COMMON_H__ 159 #endif // __COMMON_H__

mercurial