/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
1
/*
2
*/
3
4
#ifndef __H_DEFS__
5
#define __H_DEFS__
6
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
7
#include <limits.h>
48 by Gustav Hartvigsson
* Finnished SLinkedList.
8
#include <stddef.h>
67 by Gustav Hartvigsson
* Readded s_wstring_to_string function*
9
#include <uchar.h>
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
10
#include <stdint.h>
11
#include <inttypes.h>
12
#include <assert.h>
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
13
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
14
/** @file
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
15
 * @defgroup Definitions Definitions
16
 * @addtogroup Definitions
17
 * @{
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
18
 */
19
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
20
/**
21
 * BEGIN_DECLS
22
 * For interoperabibily with C++ we have to have this.
23
 *
24
 * Put at the beginning and end of headerfiles.
25
 */
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
26
#ifdef __cplusplus
27
#define BEGIN_DECLS extern "C" {
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
28
#define END_DECLS }
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
29
#else
30
#define BEGIN_DECLS
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
31
#define END_DECLS
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
32
#endif /*__cplusplus*/
33
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
34
#if defined(__GNUC__)
35
#define DEPRECATED __attribute__((deprecated))
36
#define UNUSED __attribute__((unused))
83 by Gustav Hartvigsson
* vec.h:
37
#define ALIGNED_8 __attribute__((aligned (8)))
38
#define ALIGNED_16 __attribute__((aligned (16)))
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
39
#elif __MSC_VER
40
#define DEPRECATED __declspec(deprecated)
41
// TODO, check if this rely works in MSVC.
42
#define UNUSED __pragma(warning(suppress:4100))
83 by Gustav Hartvigsson
* vec.h:
43
#define ALIGNED_8 __declspec(align(8))
44
#define ALIGNED_16 __declspec(align(16))
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
45
#else
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
46
#define DEPRECATED
47
#define UNUSED
83 by Gustav Hartvigsson
* vec.h:
48
#define ALIGNED_8
49
#define ALIGNED_16
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
50
#endif
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
51
86 by Gustav Hartvigsson
* added external .h files for dealing with stuff that may or may not be avalible on scertain platforms.
52
#if defined(__STDC_NO_ATOMICS__)
53
#define __S_ATOMIC__ __Atomic
54
#else
55
#define __S_ATOMIC__ volatile
56
#endif
57
58
26 by Gustav Hartvigsson
* Added something to config.h.in, still not sure how it cmake works.
59
BEGIN_DECLS
60
57 by Gustav Hartvigsson
* Tested print_backtrace() macro using MingW and Wine... Still needs testing on a real windows system.
61
#include <stdio.h>
62
#include <stdlib.h>
63
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
64
/**
65
 * FALSE has the absolute value of 0, it is used in as a way to represet a false
66
 * value. A "not" value.
67
 */
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
68
#define FALSE 0
69
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
70
 /**
71
  * TRUE represets a value that is true. A value that is "not false".
72
  */
85 by Gustav Hartvigsson
* Better? Worse? Who knows?
73
#define TRUE !FALSE
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
74
53 by Gustav Hartvigsson
* Finnished up s_map_add () ???
75
#define S_POINTER_TO_HASH_T(p) ((hash_t)(unsigned long) p)
76
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
77
/**
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
78
 * @defgroup Types Type declarations
79
 * @addtogroup Types
80
 * @{
81
 */
82
83
/**
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
84
 * sboolean is the standard definition of a boolean value in SSTS.
85
 *
86
 * @sa TRUE
87
 * @sa FALSE
88
 *
89
 * @note
90
 * This is the way it is done in GLib, so it is done here too.
91
 */
89 by Gustav Hartvigsson
* Started working on Threads
92
typedef int32_t sboolean;
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
93
43 by Gustav Hartvigsson
* Code cleanup
94
/** hash type  */
48 by Gustav Hartvigsson
* Finnished SLinkedList.
95
typedef size_t hash_t;
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
96
43 by Gustav Hartvigsson
* Code cleanup
97
/** spointer is a convinience typedef of void * */
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
98
typedef void* spointer;
99
48 by Gustav Hartvigsson
* Finnished SLinkedList.
100
/** sconstpointer is a convinience typedef of const void * */
101
typedef const void* sconstpointer;
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
102
103
/**
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
104
 * To prevent intercomatability problems we def schar and assert its size.
105
 */
106
typedef char schar;
107
static_assert (sizeof(schar) == sizeof (int8_t),
108
              "schar has the wrong size. Is not 8 bit long.");
109
110
/**
65 by Gustav Hartvigsson
* added uchar to defs.h
111
 * uchar is the representation for use with wide unicode strings and what not.
112
 * 
113
 * The rationell for using char32_t as the unicode wide char instead of
114
 * wchar_t is that wchar_t's size depends on the imprementation, compiler,
115
 * and system.
116
 *
117
 * To make the wide strings actually work as they should, even over network or
118
 * other communication we set this as the standard for the uchar.
89 by Gustav Hartvigsson
* Started working on Threads
119
 *
120
 * @warning This is not an unsigned char. If you need to store such small
121
 * values use #subyte 
65 by Gustav Hartvigsson
* added uchar to defs.h
122
 */
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
123
typedef char32_t suchar;
124
125
/**
126
 * To prevent intercomatability problems we def long as int64_t.
127
 */
128
typedef int64_t slong;
129
130
/**
131
 * To prevent intercomatability problems we def int as int32_t.
132
 */
133
typedef int32_t sint;
134
135
/**
136
 * To prevent intercomatability problems we def short as int16_t.
137
 */
138
typedef int16_t sshort;
139
140
/**
141
 * To prevent intercomatability problems we def byte as int8_t.
142
 */
143
typedef int8_t sbyte;
144
145
/* *************************************
146
   ******* UNSIGNED VERSIONS ***********
147
   ************************************* */
148
149
/**
150
 * To prevent intercomatability problems we def ulong as uint64_t.
151
 */
152
typedef uint64_t sulong;
153
154
/**
155
 * To prevent intercomatability problems we def uint as uint32_t.
156
 */
157
typedef uint32_t suint;
158
159
/**
160
 * To prevent intercomatability problems we def ushort as uint16_t.
161
 */
162
typedef uint16_t sushort;
163
164
/**
165
 * To prevent intercomatability problems we def ubyte as uint8_t.
166
 */
167
typedef uint8_t subyte;
168
169
/* *********** FLOATS **************** */
170
171
typedef float sfloat;
172
static_assert (sizeof (sfloat) == sizeof (int8_t) * 4,
173
              "sfloat has the wrong size. Is not 32 bit.");
174
175
176
typedef double sdouble;
177
static_assert (sizeof (sdouble) == sizeof (int8_t) * 8,
178
              "sdouble has the wrong size. Is not 64 bit.");
179
180
181
typedef __float128 squadruple;
182
static_assert (sizeof (squadruple) == sizeof (int8_t) * 16,
183
              "squadruple has the wrong size. Is not 128 bit.");
184
185
/**
186
 * @}
187
 */
65 by Gustav Hartvigsson
* added uchar to defs.h
188
189
/**
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
190
 * Represents different types of objects.
191
 *
192
 * @se STypeName
193
 */
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
194
typedef enum {
43 by Gustav Hartvigsson
* Code cleanup
195
  S_TYPE_NONE = 0,
196
  S_TYPE_INT,
49 by Gustav Hartvigsson
* started work SBox (Untested).
197
  S_TYPE_LONG,
198
  S_TYPE_SHORT,
43 by Gustav Hartvigsson
* Code cleanup
199
  S_TYPE_CHAR,
49 by Gustav Hartvigsson
* started work SBox (Untested).
200
  S_TYPE_WCHAR,
67 by Gustav Hartvigsson
* Readded s_wstring_to_string function*
201
  S_TYPE_UCHAR, /**< char32_t/uchar */
49 by Gustav Hartvigsson
* started work SBox (Untested).
202
  S_TYPE_UINT,
203
  S_TYPE_ULONG,
204
  S_TYPE_USHORT,
43 by Gustav Hartvigsson
* Code cleanup
205
  S_TYPE_BOOLEAN,
49 by Gustav Hartvigsson
* started work SBox (Untested).
206
  S_TYPE_STRING,
67 by Gustav Hartvigsson
* Readded s_wstring_to_string function*
207
  S_TYPE_WSTRING, /**< Plarform specific wchar_t */
208
  S_TYPE_USTRING, /**< char32_t String.*/
43 by Gustav Hartvigsson
* Code cleanup
209
  S_TYPE_UNUSED_0,
210
  S_TYPE_UNUSED_1,
211
  S_TYPE_UNUSED_2,
49 by Gustav Hartvigsson
* started work SBox (Untested).
212
  S_TYPE_POINTER,
43 by Gustav Hartvigsson
* Code cleanup
213
  S_TYPE_OBJECT,
214
  S_TYPE_INVALID
215
} SType;
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
216
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
217
/** @brief
218
 * The names of the SType's
49 by Gustav Hartvigsson
* started work SBox (Untested).
219
 *
220
 * 
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
221
 */
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
222
static char * STypeName[] UNUSED = {
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
223
  "NONE",
224
  "INT",
49 by Gustav Hartvigsson
* started work SBox (Untested).
225
  "LONG",
226
  "SHORT",
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
227
  "CHAR",
49 by Gustav Hartvigsson
* started work SBox (Untested).
228
  "WCHAR",
67 by Gustav Hartvigsson
* Readded s_wstring_to_string function*
229
  "UCHAR", /*< char32_t */
49 by Gustav Hartvigsson
* started work SBox (Untested).
230
  "UINT",
231
  "ULONG",
232
  "USHORT"
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
233
  "BOOLEAN",
49 by Gustav Hartvigsson
* started work SBox (Untested).
234
  "STRING",
235
  "WSTRING",
67 by Gustav Hartvigsson
* Readded s_wstring_to_string function*
236
  "USTRING",
49 by Gustav Hartvigsson
* started work SBox (Untested).
237
  "UNUSED_0/INVALID",
238
  "UNUSED_1/INVALID",
239
  "UNUSED_2/INVALID",
240
  "POINTER",
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
241
  "OBJECT",
242
  "INVALID",
243
  0x0,
244
  0x0,
43 by Gustav Hartvigsson
* Code cleanup
245
};
26 by Gustav Hartvigsson
* Added something to config.h.in, still not sure how it cmake works.
246
50 by Gustav Hartvigsson
* Added a bindings friendly way of getting the SType name.
247
/**
248
 * @brief Get the name of the SType.
249
 *
250
 * For use in bindings.
251
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
252
char *
253
s_type_get_name (SType k);
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
254
26 by Gustav Hartvigsson
* Added something to config.h.in, still not sure how it cmake works.
255
/* Colour definitions for console prints */
256
#define RESET   "\033[0m"
257
#define BLACK   "\033[30m"      /* Black */
258
#define RED     "\033[31m"      /* Red */
259
#define GREEN   "\033[32m"      /* Green */
260
#define YELLOW  "\033[33m"      /* Yellow */
261
#define BLUE    "\033[34m"      /* Blue */
262
#define MAGENTA "\033[35m"      /* Magenta */
263
#define CYAN    "\033[36m"      /* Cyan */
264
#define WHITE   "\033[37m"      /* White */
265
#define BOLDBLACK   "\033[1m\033[30m"      /* Bold Black */
266
#define BOLDRED     "\033[1m\033[31m"      /* Bold Red */
267
#define BOLDGREEN   "\033[1m\033[32m"      /* Bold Green */
268
#define BOLDYELLOW  "\033[1m\033[33m"      /* Bold Yellow */
269
#define BOLDBLUE    "\033[1m\033[34m"      /* Bold Blue */
270
#define BOLDMAGENTA "\033[1m\033[35m"      /* Bold Magenta */
271
#define BOLDCYAN    "\033[1m\033[36m"      /* Bold Cyan */
272
#define BOLDWHITE   "\033[1m\033[37m"      /* Bold White */
273
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
274
/**
275
 * @}
276
 */
33 by Gustav Hartvigsson
* made test_macros.h a lil' bit more portable
277
26 by Gustav Hartvigsson
* Added something to config.h.in, still not sure how it cmake works.
278
END_DECLS
279
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
280
#endif