/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk

« back to all changes in this revision

Viewing changes to libssts/defs.h

  • Committer: Gustav Hartvigsson
  • Date: 2016-02-01 14:29:35 UTC
  • mfrom: (121.1.4 simpletypesystem_gc)
  • Revision ID: gustav.hartvigsson@gmail.com-20160201142935-tz7ef63id2g3yfof
* Merged GC branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#ifndef __H_DEFS__
5
5
#define __H_DEFS__
6
6
 
 
7
#include <stdio.h>
 
8
#include <stdlib.h>
7
9
#include <limits.h>
8
10
#include <stddef.h>
9
11
#include <uchar.h>
11
13
#include <inttypes.h>
12
14
#include <assert.h>
13
15
 
 
16
#include "config.h"
 
17
 
14
18
/** @file
15
19
 * @defgroup Definitions Definitions
16
20
 * @addtogroup Definitions
17
21
 * @{
18
 
 */
19
 
 
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
 
 */
 
22
 * @brief Declarations of the types and macros that are used extensively
 
23
 * throughout libssts.
 
24
 */
 
25
 
 
26
/**
 
27
 * @def S_BEGIN_DECLS
 
28
 * For interoperability with C++ we have to have this.
 
29
 *
 
30
 * Put at the beginning of header files.
 
31
 * @see S_END_DECLS
 
32
 */
 
33
 
 
34
/**
 
35
 * @def S_END_DECLS
 
36
 *
 
37
 * Put at end of header files.
 
38
 * @see S_BEGIN_DECLS
 
39
 */
 
40
 
26
41
#ifdef __cplusplus
27
42
#define S_BEGIN_DECLS extern "C" {
28
43
#define S_END_DECLS }
31
46
#define S_END_DECLS
32
47
#endif /*__cplusplus*/
33
48
 
 
49
S_BEGIN_DECLS
 
50
 
 
51
/* ***************************** GENERIC MACROS ***************************** */
 
52
 
 
53
/** @def
 
54
 */
 
55
 
 
56
/**
 
57
 * @def S_DEPRECATED
 
58
 * Mark function as deprecated.
 
59
 */
 
60
/**
 
61
 * @def S_UNUSED
 
62
 * Supress compiler warning that variable is unused.
 
63
 */
 
64
/**
 
65
 * @def S_ALIGNED_8
 
66
 * Macro to align memory to 8 bit.
 
67
 */
 
68
/**
 
69
 * @def S_ALIGNED_16
 
70
 * Macro to align memory to 16 bit.
 
71
 */
34
72
#if defined(__GNUC__)
35
73
#define S_DEPRECATED __attribute__((deprecated))
36
74
#define S_UNUSED __attribute__((unused))
49
87
#define S_ALIGNED_16
50
88
#endif
51
89
 
 
90
/**
 
91
 * @def __S_ATOMIC__
 
92
 * The stupid atomic value.
 
93
 */
52
94
#if __STDC_NO_ATOMICS__
53
95
#define __S_ATOMIC__ volatile
54
96
#else
55
97
#define __S_ATOMIC__ __Atomic
56
98
#endif
57
99
 
 
100
/**
 
101
 * @def S_EXPORTED
 
102
 * Mark function as exported. This makes the function available from outside a
 
103
 * library on some platforms.
 
104
 *
 
105
 * @see S_HIDDEN
 
106
 */
 
107
/**
 
108
 * @def S_HIDDEN
 
109
 * Mark function as hidden. This hides a function so it is not exposed to the
 
110
 * outside of the library.
 
111
 *
 
112
 * @see S_EXPORTED
 
113
 */
 
114
 
58
115
/*
59
116
 * Copied from: https://gcc.gnu.org/wiki/Visibility .. with modifications.
60
117
 */
83
140
  #endif
84
141
#endif
85
142
 
86
 
 
87
 
S_BEGIN_DECLS
88
 
 
89
 
#include <stdio.h>
90
 
#include <stdlib.h>
91
 
 
92
143
/**
93
 
 * FALSE has the absolute value of 0, it is used in as a way to represet a false
94
 
 * value. A "not" value.
 
144
 * FALSE has the absolute value of 0, it is used in as a way to represent a
 
145
 * false value. A "not" value.
 
146
 *
 
147
 * @see sboolean
95
148
 */
96
149
#define FALSE 0
97
150
 
98
151
 /**
99
 
  * TRUE represets a value that is true. A value that is "not false".
 
152
  * TRUE represents a value that is true. A value that is "not false".
 
153
  *
 
154
  * @see sboolean
100
155
  */
101
156
#define TRUE !FALSE
102
157
 
 
158
/**
 
159
 * Stupid macro to create a hash of a pointer.
 
160
 */
103
161
#define S_POINTER_TO_HASH_T(p) ((hash_t)(unsigned long) p)
104
162
 
105
163
/**
106
164
 * @defgroup Types Type declarations
107
165
 * @addtogroup Types
108
166
 * @{
 
167
 * @brief The typedefs that make up the types that are used in libssts.
 
168
 * 
109
169
 */
110
170
 
111
171
/**
129
189
typedef const void* sconstpointer;
130
190
 
131
191
/**
132
 
 * To prevent intercomatability problems we def schar and assert its size.
 
192
 * To prevent intercomparability problems we def schar and assert its size.
133
193
 */
134
194
typedef char schar;
135
195
static_assert (sizeof(schar) == sizeof (int8_t),
138
198
/**
139
199
 * uchar is the representation for use with wide unicode strings and what not.
140
200
 *
141
 
 * The rationell for using char32_t as the unicode wide char instead of
142
 
 * wchar_t is that wchar_t's size depends on the imprementation, compiler,
 
201
 * The rationale for using char32_t as the unicode wide char instead of
 
202
 * wchar_t is that wchar_t's size depends on the implementation, compiler,
143
203
 * and system.
144
204
 *
145
205
 * To make the wide strings actually work as they should, even over network or
151
211
typedef char32_t suchar;
152
212
 
153
213
/**
154
 
 * To prevent intercomatability problems we def long as int64_t.
 
214
 * To prevent interchangeability problems we def long as int64_t.
155
215
 */
156
216
typedef int64_t slong;
157
217
 
158
218
/**
159
 
 * To prevent intercomatability problems we def int as int32_t.
 
219
 * To prevent interchangeability problems we def int as int32_t.
160
220
 */
161
221
typedef int32_t sint;
162
222
 
163
223
/**
164
 
 * To prevent intercomatability problems we def short as int16_t.
 
224
 * To prevent interchangeability problems we def short as int16_t.
165
225
 */
166
226
typedef int16_t sshort;
167
227
 
168
228
/**
169
 
 * To prevent intercomatability problems we def byte as int8_t.
 
229
 * To prevent interchangeability problems we def byte as int8_t.
170
230
 */
171
231
typedef int8_t sbyte;
172
232
 
175
235
   ************************************* */
176
236
 
177
237
/**
178
 
 * To prevent intercomatability problems we def ulong as uint64_t.
 
238
 * To prevent interchangeability problems we def ulong as uint64_t.
179
239
 */
180
240
typedef uint64_t sulong;
181
241
 
182
242
/**
183
 
 * To prevent intercomatability problems we def uint as uint32_t.
 
243
 * To prevent interchangeability problems we def uint as uint32_t.
184
244
 */
185
245
typedef uint32_t suint;
186
246
 
187
247
/**
188
 
 * To prevent intercomatability problems we def ushort as uint16_t.
 
248
 * To prevent interchangeability problems we def ushort as uint16_t.
189
249
 */
190
250
typedef uint16_t sushort;
191
251
 
192
252
/**
193
 
 * To prevent intercomatability problems we def ubyte as uint8_t.
 
253
 * To prevent interchangeability problems we def ubyte as uint8_t.
194
254
 */
195
255
typedef uint8_t subyte;
196
256
 
220
280
 * @se STypeName
221
281
 */
222
282
typedef enum {
223
 
  S_TYPE_NONE = 0,
224
 
  S_TYPE_INT,
225
 
  S_TYPE_LONG,
226
 
  S_TYPE_SHORT,
227
 
  S_TYPE_CHAR,
228
 
  S_TYPE_WCHAR,
229
 
  S_TYPE_UCHAR, /**< char32_t/uchar */
230
 
  S_TYPE_UINT,
231
 
  S_TYPE_ULONG,
232
 
  S_TYPE_USHORT,
233
 
  S_TYPE_BOOLEAN,
234
 
  S_TYPE_STRING,
235
 
  S_TYPE_WSTRING, /**< Plarform specific wchar_t */
236
 
  S_TYPE_USTRING, /**< char32_t String.*/
237
 
  S_TYPE_UNUSED_0,
238
 
  S_TYPE_UNUSED_1,
239
 
  S_TYPE_UNUSED_2,
240
 
  S_TYPE_POINTER,
241
 
  S_TYPE_OBJECT,
242
 
  S_TYPE_INVALID
 
283
  S_TYPE_NONE = 0, /**< Not a type. */
 
284
  S_TYPE_INT, /**< @ref sint */
 
285
  S_TYPE_LONG, /**< @ref slong */
 
286
  S_TYPE_SHORT, /**< @ref sshort */
 
287
  S_TYPE_CHAR, /**< @ref schar */
 
288
  S_TYPE_WCHAR, /**< @deprecated wide char (wchar_t) */
 
289
  S_TYPE_UCHAR, /**< @ref suchar */
 
290
  S_TYPE_UINT, /**< @ref suint */
 
291
  S_TYPE_ULONG, /**< @ref sulong */
 
292
  S_TYPE_USHORT, /**< @ref sushort */
 
293
  S_TYPE_BOOLEAN, /**< @ref sboolean */
 
294
  S_TYPE_STRING, /**< a string of @ref schar s */
 
295
  S_TYPE_WSTRING, /**< @deprecated  Platform specific wchar_t string */
 
296
  S_TYPE_USTRING, /**< a string of @ref suchar s */
 
297
  S_TYPE_UNUSED_0, /**< */
 
298
  S_TYPE_UNUSED_1, /**< */
 
299
  S_TYPE_UNUSED_2, /**< */
 
300
  S_TYPE_POINTER, /**< @ref spointer */
 
301
  S_TYPE_OBJECT, /**< @ref SObject */
 
302
  S_TYPE_INVALID /** Invalid type. */
243
303
} SType;
244
304
 
245
305
/** @brief
280
340
char *
281
341
s_type_get_name (SType k);
282
342
 
283
 
/* Colour definitions for console prints */
284
 
#define RESET   "\033[0m"
285
 
#define BLACK   "\033[30m"      /* Black */
286
 
#define RED     "\033[31m"      /* Red */
287
 
#define GREEN   "\033[32m"      /* Green */
288
 
#define YELLOW  "\033[33m"      /* Yellow */
289
 
#define BLUE    "\033[34m"      /* Blue */
290
 
#define MAGENTA "\033[35m"      /* Magenta */
291
 
#define CYAN    "\033[36m"      /* Cyan */
292
 
#define WHITE   "\033[37m"      /* White */
293
 
#define BOLDBLACK   "\033[1m\033[30m"      /* Bold Black */
294
 
#define BOLDRED     "\033[1m\033[31m"      /* Bold Red */
295
 
#define BOLDGREEN   "\033[1m\033[32m"      /* Bold Green */
296
 
#define BOLDYELLOW  "\033[1m\033[33m"      /* Bold Yellow */
297
 
#define BOLDBLUE    "\033[1m\033[34m"      /* Bold Blue */
298
 
#define BOLDMAGENTA "\033[1m\033[35m"      /* Bold Magenta */
299
 
#define BOLDCYAN    "\033[1m\033[36m"      /* Bold Cyan */
300
 
#define BOLDWHITE   "\033[1m\033[37m"      /* Bold White */
 
343
/**
 
344
 * @defgroup Colours Colours
 
345
 * @addtogroup Colours
 
346
 * @{
 
347
 * @brief Printing colours for terminal/console printing.
 
348
 * 
 
349
 * Here is a list of macros for use when printing to the console.
 
350
 * @ref S_COLOR_RESET is used to reset the colours back to their original
 
351
 *      colour.
 
352
 * 
 
353
 * An example on how to use them can be found in utils.h:
 
354
 * @code{.c}
 
355
#define s_err_print(p, ...)\
 
356
  fprintf (stderr, S_COLOR_RED "[ERR] " p S_COLOR_RESET "\n", ##__VA_ARGS__)
 
357
 * @endcode
 
358
 */
 
359
 
 
360
#define S_COLOR_RESET   "\033[0m"       /**< Reset */
 
361
#define S_COLOR_BLACK   "\033[30m"      /**< Black */
 
362
#define S_COLOR_RED     "\033[31m"      /**< Red */
 
363
#define S_COLOR_GREEN   "\033[32m"      /**< Green */
 
364
#define S_COLOR_YELLOW  "\033[33m"      /**< Yellow */
 
365
#define S_COLOR_BLUE    "\033[34m"      /**< Blue */
 
366
#define S_COLOR_MAGENTA "\033[35m"      /**< Magenta */
 
367
#define S_COLOR_CYAN    "\033[36m"      /**< Cyan */
 
368
#define S_COLOR_WHITE   "\033[37m"      /**< White */
 
369
#define S_COLOR_BOLDBLACK   "\033[1m\033[30m"      /**< Bold Black */
 
370
#define S_COLOR_BOLDRED     "\033[1m\033[31m"      /**< Bold Red */
 
371
#define S_COLOR_BOLDGREEN   "\033[1m\033[32m"      /**< Bold Green */
 
372
#define S_COLOR_BOLDYELLOW  "\033[1m\033[33m"      /**< Bold Yellow */
 
373
#define S_COLOR_BOLDBLUE    "\033[1m\033[34m"      /**< Bold Blue */
 
374
#define S_COLOR_BOLDMAGENTA "\033[1m\033[35m"      /**< Bold Magenta */
 
375
#define S_COLOR_BOLDCYAN    "\033[1m\033[36m"      /**< Bold Cyan */
 
376
#define S_COLOR_BOLDWHITE   "\033[1m\033[37m"      /**< Bold White */
 
377
 
 
378
/** @} */
301
379
 
302
380
/**
303
381
 * @}
304
382
 */
305
383
 
 
384
/* We include this last so it does not create any problems.
 
385
 * We want people only to have to include defs.h and not mm.h anyway.
 
386
 *
 
387
 * It should be considered a continuation of defs.h.
 
388
 */
 
389
#include "mm.h"
 
390
 
306
391
S_END_DECLS
307
392
 
308
393
#endif