/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: 2017-01-24 20:55:19 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20170124205519-gtr18o3dwbunrrnx
* Fixed the tests in the CMake file
* Made doxygen output static declarations.
* Started work on SApplication
* Played with BaseN.c
  * Now it is a lil' bit better
* Spilt defs.h
  * Added types.h
    * Started work on the full typesystem.
      (Still needs testing)
  * Added primes.[c,h]
    * Contains some static array with primes.
      ("Good" primes, and all primes up to 5 000.
    * And helper functions related to Primes (Needs Tests).
* fixed s_dynamic_array_dump_array.
  (The old version did not make much sense)
* removed some functions from DymanicArray.c
* fixed compiler warnings in Mainloop.c
* removed s_map_(de)serialize_json functions.
* Made s_thread_status_get_name be less prone to error
  (This due to the C11 standard not specifing what these
   values should be)
* fixed s_thread_run
* fixed s_threa_stop

  TODO:
* Write tests for the s_prime_* functions
* Write tests for the s_type_* functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <stdint.h>
31
31
#include <inttypes.h>
32
32
#include <assert.h>
 
33
#include <math.h>
33
34
 
34
35
#include "config.h"
35
36
 
181
182
 */
182
183
#define S_POINTER_TO_HASH_T(p) ((hash_t)(unsigned long) p)
183
184
 
184
 
/**
185
 
 * @defgroup Types Type declarations
186
 
 * @addtogroup Types
187
 
 * @{
188
 
 * @brief The typedefs that make up the types that are used in libssts.
189
 
 * 
190
 
 */
191
 
 
192
 
/**
193
 
 * sboolean is the standard definition of a boolean value in SSTS.
194
 
 *
195
 
 * @sa TRUE
196
 
 * @sa FALSE
197
 
 *
198
 
 * @note
199
 
 * This is the way it is done in GLib, so it is done here too.
200
 
 */
201
 
typedef int32_t sboolean;
202
 
 
203
 
/** hash type  */
204
 
typedef size_t hash_t;
205
 
 
206
 
/** spointer is a convinience typedef of void * */
207
 
typedef void* spointer;
208
 
 
209
 
/** sconstpointer is a convinience typedef of const void * */
210
 
typedef const void* sconstpointer;
211
 
 
212
 
/**
213
 
 * To prevent intercomparability problems we def schar and assert its size.
214
 
 */
215
 
typedef char schar;
216
 
static_assert (sizeof(schar) == sizeof (int8_t),
217
 
              "schar has the wrong size. Is not 8 bit long.");
218
 
 
219
 
/**
220
 
 * uchar is the representation for use with wide unicode strings and what not.
221
 
 *
222
 
 * The rationale for using char32_t as the unicode wide char instead of
223
 
 * wchar_t is that wchar_t's size depends on the implementation, compiler,
224
 
 * and system.
225
 
 *
226
 
 * To make the wide strings actually work as they should, even over network or
227
 
 * other communication we set this as the standard for the uchar.
228
 
 *
229
 
 * @warning This is not an unsigned char. If you need to store such small
230
 
 * values use #subyte
231
 
 */
232
 
typedef char32_t suchar;
233
 
 
234
 
/**
235
 
 * To prevent interchangeability problems we def long as int64_t.
236
 
 */
237
 
typedef int64_t slong;
238
 
 
239
 
/**
240
 
 * To prevent interchangeability problems we def int as int32_t.
241
 
 */
242
 
typedef int32_t sint;
243
 
 
244
 
/**
245
 
 * To prevent interchangeability problems we def short as int16_t.
246
 
 */
247
 
typedef int16_t sshort;
248
 
 
249
 
/**
250
 
 * To prevent interchangeability problems we def byte as int8_t.
251
 
 */
252
 
typedef int8_t sbyte;
253
 
 
254
 
/* *************************************
255
 
   ******* UNSIGNED VERSIONS ***********
256
 
   ************************************* */
257
 
 
258
 
/**
259
 
 * To prevent interchangeability problems we def ulong as uint64_t.
260
 
 */
261
 
typedef uint64_t sulong;
262
 
 
263
 
/**
264
 
 * To prevent interchangeability problems we def uint as uint32_t.
265
 
 */
266
 
typedef uint32_t suint;
267
 
 
268
 
/**
269
 
 * To prevent interchangeability problems we def ushort as uint16_t.
270
 
 */
271
 
typedef uint16_t sushort;
272
 
 
273
 
/**
274
 
 * To prevent interchangeability problems we def ubyte as uint8_t.
275
 
 */
276
 
typedef uint8_t subyte;
277
 
 
278
 
/* *********** FLOATS **************** */
279
 
 
280
 
typedef float sfloat;
281
 
static_assert (sizeof (sfloat) == sizeof (int8_t) * 4,
282
 
              "sfloat has the wrong size. Is not 32 bit.");
283
 
 
284
 
 
285
 
typedef double sdouble;
286
 
static_assert (sizeof (sdouble) == sizeof (int8_t) * 8,
287
 
              "sdouble has the wrong size. Is not 64 bit.");
288
 
 
289
 
 
290
 
typedef __float128 squadruple;
291
 
static_assert (sizeof (squadruple) == sizeof (int8_t) * 16,
292
 
              "squadruple has the wrong size. Is not 128 bit.");
293
 
 
294
 
/**
295
 
 * @}
296
 
 */
297
 
 
298
 
/**
299
 
 * Represents different types of objects.
300
 
 *
301
 
 * @se STypeName
302
 
 */
303
 
typedef enum {
304
 
  S_TYPE_NONE = 0, /**< Not a type. */
305
 
  S_TYPE_INT, /**< @ref sint */
306
 
  S_TYPE_LONG, /**< @ref slong */
307
 
  S_TYPE_SHORT, /**< @ref sshort */
308
 
  S_TYPE_CHAR, /**< @ref schar */
309
 
  S_TYPE_WCHAR, /**< @deprecated wide char (wchar_t) */
310
 
  S_TYPE_UCHAR, /**< @ref suchar */
311
 
  S_TYPE_UINT, /**< @ref suint */
312
 
  S_TYPE_ULONG, /**< @ref sulong */
313
 
  S_TYPE_USHORT, /**< @ref sushort */
314
 
  S_TYPE_BOOLEAN, /**< @ref sboolean */
315
 
  S_TYPE_STRING, /**< a string of @ref schar s */
316
 
  S_TYPE_WSTRING, /**< @deprecated  Platform specific wchar_t string */
317
 
  S_TYPE_USTRING, /**< a string of @ref suchar s */
318
 
  S_TYPE_UNUSED_0, /**< */
319
 
  S_TYPE_UNUSED_1, /**< */
320
 
  S_TYPE_UNUSED_2, /**< */
321
 
  S_TYPE_POINTER, /**< @ref spointer */
322
 
  S_TYPE_OBJECT, /**< @ref SObject */
323
 
  S_TYPE_INVALID /** Invalid type. */
324
 
} SType;
325
 
 
326
 
/** @brief
327
 
 * The names of the SType's
328
 
 *
329
 
 *
330
 
 */
331
 
static char * STypeName[] S_UNUSED = {
332
 
  "NONE",
333
 
  "INT",
334
 
  "LONG",
335
 
  "SHORT",
336
 
  "CHAR",
337
 
  "WCHAR",
338
 
  "UCHAR", /*< char32_t */
339
 
  "UINT",
340
 
  "ULONG",
341
 
  "USHORT"
342
 
  "BOOLEAN",
343
 
  "STRING",
344
 
  "WSTRING",
345
 
  "USTRING",
346
 
  "UNUSED_0/INVALID",
347
 
  "UNUSED_1/INVALID",
348
 
  "UNUSED_2/INVALID",
349
 
  "POINTER",
350
 
  "OBJECT",
351
 
  "INVALID",
352
 
  0x0,
353
 
  0x0,
354
 
};
355
 
 
356
 
/**
357
 
 * @brief Get the name of the SType.
358
 
 *
359
 
 * For use in bindings.
360
 
 */
361
 
char *
362
 
s_type_get_name (SType k);
 
185
 
 
186
/* ************************************************************************** *
 
187
 * Colours
 
188
 * ************************************************************************** */
363
189
 
364
190
/**
365
191
 * @defgroup Colours Colours
366
192
 * @addtogroup Colours
367
 
 * @{
 
193
 *   @{
368
194
 * @brief Printing colours for terminal/console printing.
369
 
 * 
 
195
 *
370
196
 * Here is a list of macros for use when printing to the console.
371
197
 * @ref S_COLOR_RESET is used to reset the colours back to their original
372
198
 *      colour.
373
 
 * 
 
199
 *
374
200
 * An example on how to use them can be found in utils.h:
375
201
 * @code{.c}
376
202
#define s_err_print(p, ...)\
377
203
  fprintf (stderr, S_COLOR_RED "[ERR] " p S_COLOR_RESET "\n", ##__VA_ARGS__)
378
204
 * @endcode
379
205
 */
380
 
 
 
206
 
381
207
#define S_COLOR_RESET   "\033[0m"       /**< Reset */
382
208
#define S_COLOR_BLACK   "\033[30m"      /**< Black */
383
209
#define S_COLOR_RED     "\033[31m"      /**< Red */
396
222
#define S_COLOR_BOLDCYAN    "\033[1m\033[36m"      /**< Bold Cyan */
397
223
#define S_COLOR_BOLDWHITE   "\033[1m\033[37m"      /**< Bold White */
398
224
 
 
225
/**   @} */
 
226
 
399
227
/** @} */
400
228
 
401
 
/**
402
 
 * @}
403
 
 */
404
 
 
405
 
/* We include this last so it does not create any problems.
406
 
 * We want people only to have to include defs.h and not mm.h anyway.
 
229
/* We include these last so it does not create any problems.
 
230
 * We want people only to have to include defs.h and not mm.h and types.h
 
231
 * anyway.
407
232
 *
408
233
 * It should be considered a continuation of defs.h.
409
234
 */
 
235
 
 
236
#include "types.h"
 
237
 
 
238
#include "primes.h" /* This is already included in types.h... */
 
239
 
410
240
#include "mm.h"
411
241
 
 
242
 
412
243
S_END_DECLS