1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
#pragma once
/*
Copyright (c) 2013-2015 Gustav Hartvigsson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "defs.h"
S_BEGIN_DECLS
/**
* @file
* @addtogroup Definitions
* @{
* @defgroup Types Type declarations
* @addtogroup Types
* @{
* @brief The typedefs that make up the types that are used in libssts.
*
*/
/**
* sboolean is the standard definition of a boolean value in SSTS.
*
* @sa TRUE
* @sa FALSE
*
* @note
* This is the way it is done in GLib, so it is done here too.
*/
typedef _Bool sboolean;
/** hash type */
typedef size_t hash_t;
/** spointer is a convinience typedef of void * */
typedef void* spointer;
/** sconstpointer is a convinience typedef of const void * */
typedef const void* sconstpointer;
/**
* To prevent intercomparability problems we def schar and assert its size.
*/
typedef char schar;
static_assert (sizeof(schar) == sizeof (int8_t),
"schar has the wrong size. Is not 8 bit long.");
/**
* uchar is the representation for use with wide unicode strings and what not.
*
* The rationale for using char32_t as the unicode wide char instead of
* wchar_t is that wchar_t's size depends on the implementation, compiler,
* and system.
*
* To make the wide strings actually work as they should, even over network or
* other communication we set this as the standard for the uchar.
*
* @warning This is not an unsigned char. If you need to store such small
* values use #subyte
*/
typedef char32_t suchar;
/**
* To prevent interchangeability problems we def long as int64_t.
*/
typedef int64_t slong;
/**
* To prevent interchangeability problems we def int as int32_t.
*/
typedef int32_t sint;
/**
* To prevent interchangeability problems we def short as int16_t.
*/
typedef int16_t sshort;
/**
* To prevent interchangeability problems we def byte as int8_t.
*/
typedef int8_t sbyte;
/* *************************************
******* UNSIGNED VERSIONS ***********
************************************* */
/**
* To prevent interchangeability problems we def ulong as uint64_t.
*/
typedef uint64_t sulong;
/**
* To prevent interchangeability problems we def uint as uint32_t.
*/
typedef uint32_t suint;
/**
* To prevent interchangeability problems we def ushort as uint16_t.
*/
typedef uint16_t sushort;
/**
* To prevent interchangeability problems we def ubyte as uint8_t.
*/
typedef uint8_t subyte;
/* *********** FLOATS **************** */
typedef float sfloat;
static_assert (sizeof (sfloat) == sizeof (int8_t) * 4,
"sfloat has the wrong size. Is not 32 bit.");
typedef double sdouble;
static_assert (sizeof (sdouble) == sizeof (int8_t) * 8,
"sdouble has the wrong size. Is not 64 bit.");
typedef __float128 squadruple;
static_assert (sizeof (squadruple) == sizeof (int8_t) * 16,
"squadruple has the wrong size. Is not 128 bit.");
/**
* @}
*/
#include "primes.h"
/**
* @defgroup Typesystem Type System
* @addtogroup Typesystem
* @{
* @brief libssts's very primative type system.
*/
/**
* The maximum amount of types.
*
* @note Subject to change.
*
*/
#define S_TYPE_MAX SPrimeListGood[5] // 499
typedef struct STypeSystem STypeSystem;
/**
* The type that represents the type id.
* @see STypeEnum
* @see STypeName
* @see s_type_get_name
*/
typedef slong SType;
/**
* Predefined types of objects.
*
* @see STypeName
* @see SType
* @see s_type_get_name
*/
typedef enum STypeEnum {
S_TYPE_NONE = 0, /**< Not a type. */
S_TYPE_INT, /**< @ref sint */
S_TYPE_LONG, /**< @ref slong */
S_TYPE_SHORT, /**< @ref sshort */
S_TYPE_CHAR, /**< @ref schar */
S_TYPE_WCHAR, /**< @deprecated wide char (wchar_t) */
S_TYPE_UCHAR, /**< @ref suchar */
S_TYPE_UINT, /**< @ref suint */
S_TYPE_ULONG, /**< @ref sulong */
S_TYPE_USHORT, /**< @ref sushort */
S_TYPE_BOOLEAN, /**< @ref sboolean */
S_TYPE_STRING, /**< a string of @ref schar s */
#if 0
S_TYPE_WSTRING, /**< @deprecated Platform specific wchar_t string */
#endif
S_TYPE_USTRING, /**< a string of @ref suchar s */
S_TYPE_UNUSED_0, /**< */
S_TYPE_UNUSED_1, /**< */
S_TYPE_UNUSED_2, /**< */
S_TYPE_POINTER, /**< @ref spointer */
S_TYPE_OBJECT, /**< @ref SObject */
S_TYPE_INVALID, /** Invalid type. */
S_TYPE_UNUSED_3, /**< */
S_TYPE_UNUSED_4, /**< */
S_TYPE_LAST_PREDEFINED, /**< One-over-end item in the predefined
* list of types */
} STypeEnum;
/** @brief
* The names of STypeEnum's items.
*
* @see STypeEnum
* @see SType
* @see s_type_get_name
*/
S_UNUSED
static char * STypeName[] = {
"NONE",
"INT",
"LONG",
"SHORT",
"CHAR",
"WCHAR",
"UCHAR", /*< char32_t */
"UINT",
"ULONG",
"USHORT"
"BOOLEAN",
"STRING",
"WSTRING",
"USTRING",
0x0,
0x0,
0x0,
"POINTER",
"OBJECT",
"INVALID",
0x0,
0x0,
};
/**
* Provides type information, includeing what parent an object has. Note that
* this iformation should be constant and accessable.
*/
typedef struct STypeInfo {
SType id; /**< The id of the type. This is set by the system on registration.
*/
SType parent; /**< The parent type's type id. Can be @ref S_TYPE_NONE (0) if
* you are not deriving from any type. */
schar * name; /**< The name string. This is used when identifing types in
* debugging but can and will be used in other places. */
} STypeInfo;
/**
* Free allocaded STypeInfo.
*
* @param ti The type information to be freed.
*/
S_EXPORTED
void
s_type_info_free (STypeInfo * ti);
/**
*
*/
S_EXPORTED
const STypeInfo *
s_type_register_return_type_info (schar * name, SType parent);
/**
*
*/
S_EXPORTED
SType
s_type_register (schar * name, SType parent);
/**
* @brief Get the name of the SType.
*
* @return the name of the type
* @return NULL on invalid id's.
*
* @note must be freed my caller.
*/
S_EXPORTED
schar *
s_type_get_name (SType k);
/**
* get type id from name.
*
* @return the SType of the name.
* @return #S_TYPE_NONE on unregisterd name.
*/
S_EXPORTED
SType
s_type_get_type (schar * name);
/**
* Get the parent type of a type.
*/
S_EXPORTED
SType
s_type_get_parent (SType type);
/**
* Get a NULL terminated array of all parents of a type.
*
* @param type The type to check.
* @param out_size Where the size of the returned array is stored.
*/
S_EXPORTED
SType *
s_type_get_array_of_parents (SType type, size_t * out_size);
/**
* Checks if a type is derived from an other type or not.
*
* @param child_type The type you want to check.
* @param parent_type The type you want to check if child_type is a child to
* parent_type.
*/
S_EXPORTED
sboolean
s_type_is_type (SType child_type, SType parent_type);
/**
* @brief
* Teardown the typesystem.
*
* This is the last thing that should be run in any
* applications. Calling this before may cause undefined behaviour.
*
* @warning Do not call this directly. Use @ref s_teardown() instead.
*/
S_HIDDEN
void
s_type_system_teardown ();
S_END_DECLS
/**
* @}
* @}
*/
|