3
Copyright (c) 2013-2015 Gustav Hartvigsson
5
Permission is hereby granted, free of charge, to any person obtaining a copy
6
of this software and associated documentation files (the "Software"), to deal
7
in the Software without restriction, including without limitation the rights
8
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
copies of the Software, and to permit persons to whom the Software is
10
furnished to do so, subject to the following conditions:
12
The above copyright notice and this permission notice shall be included in
13
all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30
* @addtogroup Definitions
32
* @defgroup Types Type declarations
35
* @brief The typedefs that make up the types that are used in libssts.
41
* sboolean is the standard definition of a boolean value in SSTS.
47
* This is the way it is done in GLib, so it is done here too.
49
typedef int32_t sboolean;
52
typedef size_t hash_t;
54
/** spointer is a convinience typedef of void * */
55
typedef void* spointer;
57
/** sconstpointer is a convinience typedef of const void * */
58
typedef const void* sconstpointer;
61
* To prevent intercomparability problems we def schar and assert its size.
64
static_assert (sizeof(schar) == sizeof (int8_t),
65
"schar has the wrong size. Is not 8 bit long.");
68
* uchar is the representation for use with wide unicode strings and what not.
70
* The rationale for using char32_t as the unicode wide char instead of
71
* wchar_t is that wchar_t's size depends on the implementation, compiler,
74
* To make the wide strings actually work as they should, even over network or
75
* other communication we set this as the standard for the uchar.
77
* @warning This is not an unsigned char. If you need to store such small
80
typedef char32_t suchar;
83
* To prevent interchangeability problems we def long as int64_t.
85
typedef int64_t slong;
88
* To prevent interchangeability problems we def int as int32_t.
93
* To prevent interchangeability problems we def short as int16_t.
95
typedef int16_t sshort;
98
* To prevent interchangeability problems we def byte as int8_t.
100
typedef int8_t sbyte;
102
/* *************************************
103
******* UNSIGNED VERSIONS ***********
104
************************************* */
107
* To prevent interchangeability problems we def ulong as uint64_t.
109
typedef uint64_t sulong;
112
* To prevent interchangeability problems we def uint as uint32_t.
114
typedef uint32_t suint;
117
* To prevent interchangeability problems we def ushort as uint16_t.
119
typedef uint16_t sushort;
122
* To prevent interchangeability problems we def ubyte as uint8_t.
124
typedef uint8_t subyte;
126
/* *********** FLOATS **************** */
128
typedef float sfloat;
129
static_assert (sizeof (sfloat) == sizeof (int8_t) * 4,
130
"sfloat has the wrong size. Is not 32 bit.");
133
typedef double sdouble;
134
static_assert (sizeof (sdouble) == sizeof (int8_t) * 8,
135
"sdouble has the wrong size. Is not 64 bit.");
138
typedef __float128 squadruple;
139
static_assert (sizeof (squadruple) == sizeof (int8_t) * 16,
140
"squadruple has the wrong size. Is not 128 bit.");
149
* @defgroup Typesystem Type System
150
* @addtogroup Typesystem
152
* @brief libssts's very primative type system.
156
* The maximum amount of types.
158
* @note Subject to change.
161
#define S_TYPE_MAX SPrimeListGood[5] // 499
164
typedef struct STypeSystem STypeSystem;
168
* The type that represents the type id.
171
* @see s_type_get_name
176
* Predefined types of objects.
180
* @see s_type_get_name
182
typedef enum STypeEnum {
183
S_TYPE_NONE = 0, /**< Not a type. */
184
S_TYPE_INT, /**< @ref sint */
185
S_TYPE_LONG, /**< @ref slong */
186
S_TYPE_SHORT, /**< @ref sshort */
187
S_TYPE_CHAR, /**< @ref schar */
188
S_TYPE_WCHAR, /**< @deprecated wide char (wchar_t) */
189
S_TYPE_UCHAR, /**< @ref suchar */
190
S_TYPE_UINT, /**< @ref suint */
191
S_TYPE_ULONG, /**< @ref sulong */
192
S_TYPE_USHORT, /**< @ref sushort */
193
S_TYPE_BOOLEAN, /**< @ref sboolean */
194
S_TYPE_STRING, /**< a string of @ref schar s */
195
S_TYPE_WSTRING, /**< @deprecated Platform specific wchar_t string */
196
S_TYPE_USTRING, /**< a string of @ref suchar s */
197
S_TYPE_UNUSED_0, /**< */
198
S_TYPE_UNUSED_1, /**< */
199
S_TYPE_UNUSED_2, /**< */
200
S_TYPE_POINTER, /**< @ref spointer */
201
S_TYPE_OBJECT, /**< @ref SObject */
202
S_TYPE_INVALID, /** Invalid type. */
203
S_TYPE_UNUSED_3, /**< */
204
S_TYPE_UNUSED_4, /**< */
205
S_TYPE_LAST_PREDEFINED, /**< One-over-end item in the predefined
210
* The names of STypeEnum's items.
214
* @see s_type_get_name
217
static char * STypeName[] = {
224
"UCHAR", /*< char32_t */
244
* Provides type information, includeing what parent an object has. Note that
245
* this iformation should be constant and accessable.
247
typedef struct STypeInfo {
248
SType id; /**< The id of the type. This is set by the system on registration.
250
SType parent; /**< The parent type's type id. Can be @ref S_TYPE_NONE (0) if
251
* you are not deriving from any type. */
252
schar * name; /**< The name string. This is used when identifing types in
253
* debugging but can and will be used in other places. */
257
* Free allocaded STypeInfo.
259
* @param ti The type information to be freed.
263
s_type_info_free (STypeInfo * ti);
270
s_type_register_return_type_info (schar * name, SType parent);
277
s_type_register (schar * name, SType parent);
280
* @brief Get the name of the SType.
282
* @return the name of the type
283
* @return NULL on invalid id's.
285
* @note must be freed my caller.
289
s_type_get_name (SType k);
292
* get type id from name.
294
* @return the SType of the name.
295
* @return #S_TYPE_NONE on unregisterd name.
299
s_type_get_type (schar * name);
302
* Get the parent type of a type.
306
s_type_get_parent (SType type);
309
* Get a NULL terminated array of all parents of a type.
311
* @param type The type to check.
312
* @param out_size Where the size of the returned array is stored.
316
s_type_get_array_of_parents (SType type, size_t * out_size);
319
* Checks if a type is derived from an other type or not.
321
* @param child_type The type you want to check.
322
* @param parent_type The type you want to check if child_type is a child to.
326
s_type_is_type (SType child_type, SType parent_type);
330
* Teardown the typesystem.
332
* This is the last thing that should be run in any
333
* applications. Calling this before may cause undefined behaviour.
335
* @warning Do not call this directly. Use @ref s_teardown() instead.
339
s_type_system_teardown ();