/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
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
/*
*/

#ifndef __H_DEFS__
#define __H_DEFS__

#include <limits.h>
#include <stddef.h>
#include <uchar.h>
#include <stdint.h>
#include <inttypes.h>
#include <assert.h>

/** @file
 * @defgroup Definitions Definitions
 * @addtogroup Definitions
 * @{
 */

/**
 * BEGIN_DECLS
 * For interoperabibily with C++ we have to have this.
 *
 * Put at the beginning and end of headerfiles.
 */
#ifdef __cplusplus
#define BEGIN_DECLS extern "C" {
#define END_DECLS }
#else
#define BEGIN_DECLS
#define END_DECLS
#endif /*__cplusplus*/

#if defined(__GNUC__)
#define DEPRECATED __attribute__((deprecated))
#define UNUSED __attribute__((unused))
#define ALIGNED_8 __attribute__((aligned (8)))
#define ALIGNED_16 __attribute__((aligned (16)))
#elif __MSC_VER
#define DEPRECATED __declspec(deprecated)
// TODO, check if this rely works in MSVC.
#define UNUSED __pragma(warning(suppress:4100))
#define ALIGNED_8 __declspec(align(8))
#define ALIGNED_16 __declspec(align(16))
#else
#define DEPRECATED
#define UNUSED
#define ALIGNED_8
#define ALIGNED_16
#endif

#if defined(__STDC_NO_ATOMICS__)
#define __S_ATOMIC__ __Atomic
#else
#define __S_ATOMIC__ volatile
#endif


BEGIN_DECLS

#include <stdio.h>
#include <stdlib.h>

/**
 * FALSE has the absolute value of 0, it is used in as a way to represet a false
 * value. A "not" value.
 */
#define FALSE 0

 /**
  * TRUE represets a value that is true. A value that is "not false".
  */
#define TRUE !FALSE

#define S_POINTER_TO_HASH_T(p) ((hash_t)(unsigned long) p)

/**
 * @defgroup Types Type declarations
 * @addtogroup Types
 * @{
 */

/**
 * 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 int32_t 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 intercomatability 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 rationell for using char32_t as the unicode wide char instead of
 * wchar_t is that wchar_t's size depends on the imprementation, 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 intercomatability problems we def long as int64_t.
 */
typedef int64_t slong;

/**
 * To prevent intercomatability problems we def int as int32_t.
 */
typedef int32_t sint;

/**
 * To prevent intercomatability problems we def short as int16_t.
 */
typedef int16_t sshort;

/**
 * To prevent intercomatability problems we def byte as int8_t.
 */
typedef int8_t sbyte;

/* *************************************
   ******* UNSIGNED VERSIONS ***********
   ************************************* */

/**
 * To prevent intercomatability problems we def ulong as uint64_t.
 */
typedef uint64_t sulong;

/**
 * To prevent intercomatability problems we def uint as uint32_t.
 */
typedef uint32_t suint;

/**
 * To prevent intercomatability problems we def ushort as uint16_t.
 */
typedef uint16_t sushort;

/**
 * To prevent intercomatability 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.");

/**
 * @}
 */

/**
 * Represents different types of objects.
 *
 * @se STypeName
 */
typedef enum {
  S_TYPE_NONE = 0,
  S_TYPE_INT,
  S_TYPE_LONG,
  S_TYPE_SHORT,
  S_TYPE_CHAR,
  S_TYPE_WCHAR,
  S_TYPE_UCHAR, /**< char32_t/uchar */
  S_TYPE_UINT,
  S_TYPE_ULONG,
  S_TYPE_USHORT,
  S_TYPE_BOOLEAN,
  S_TYPE_STRING,
  S_TYPE_WSTRING, /**< Plarform specific wchar_t */
  S_TYPE_USTRING, /**< char32_t String.*/
  S_TYPE_UNUSED_0,
  S_TYPE_UNUSED_1,
  S_TYPE_UNUSED_2,
  S_TYPE_POINTER,
  S_TYPE_OBJECT,
  S_TYPE_INVALID
} SType;

/** @brief
 * The names of the SType's
 *
 * 
 */
static char * STypeName[] UNUSED = {
  "NONE",
  "INT",
  "LONG",
  "SHORT",
  "CHAR",
  "WCHAR",
  "UCHAR", /*< char32_t */
  "UINT",
  "ULONG",
  "USHORT"
  "BOOLEAN",
  "STRING",
  "WSTRING",
  "USTRING",
  "UNUSED_0/INVALID",
  "UNUSED_1/INVALID",
  "UNUSED_2/INVALID",
  "POINTER",
  "OBJECT",
  "INVALID",
  0x0,
  0x0,
};

/**
 * @brief Get the name of the SType.
 *
 * For use in bindings.
 */
char *
s_type_get_name (SType k);

/* Colour definitions for console prints */
#define RESET   "\033[0m"
#define BLACK   "\033[30m"      /* Black */
#define RED     "\033[31m"      /* Red */
#define GREEN   "\033[32m"      /* Green */
#define YELLOW  "\033[33m"      /* Yellow */
#define BLUE    "\033[34m"      /* Blue */
#define MAGENTA "\033[35m"      /* Magenta */
#define CYAN    "\033[36m"      /* Cyan */
#define WHITE   "\033[37m"      /* White */
#define BOLDBLACK   "\033[1m\033[30m"      /* Bold Black */
#define BOLDRED     "\033[1m\033[31m"      /* Bold Red */
#define BOLDGREEN   "\033[1m\033[32m"      /* Bold Green */
#define BOLDYELLOW  "\033[1m\033[33m"      /* Bold Yellow */
#define BOLDBLUE    "\033[1m\033[34m"      /* Bold Blue */
#define BOLDMAGENTA "\033[1m\033[35m"      /* Bold Magenta */
#define BOLDCYAN    "\033[1m\033[36m"      /* Bold Cyan */
#define BOLDWHITE   "\033[1m\033[37m"      /* Bold White */

/**
 * @}
 */

END_DECLS

#endif