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