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