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