/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>
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
9
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
10
/** @file
11
 * 
12
 */
13
14
#ifdef __cplusplus
15
#define BEGIN_DECLS extern "C" {
16
#else
17
#define BEGIN_DECLS
18
#endif /*__cplusplus*/
19
20
21
#ifdef __cplusplus
22
#define END_DECLS }
23
#else
24
#define END_DECLS
25
#endif /* __cplusplus */
26
26 by Gustav Hartvigsson
* Added something to config.h.in, still not sure how it cmake works.
27
BEGIN_DECLS
28
43 by Gustav Hartvigsson
* Code cleanup
29
57 by Gustav Hartvigsson
* Tested print_backtrace() macro using MingW and Wine... Still needs testing on a real windows system.
30
#include <stdio.h>
31
#include <stdlib.h>
32
56 by Gustav Hartvigsson
* Added print_backtrace() macro, UNTESTED.
33
#ifdef  __unix__
34
  #pragma message ("We are a UNIX.")
35
  #include <execinfo.h>
36
  /**
37
   * Get a platform specific traceback.
38
   *
39
   * Works on UNIX's and (undested on) Windows.
40
   */
41
  #define print_backtrace() {\
42
    fprintf (stderr, "[BACKTRACE:]\n");\
43
    void ** _backtrace_data_ = calloc (10, sizeof (void *));\
44
    int _backtrace_len_ = backtrace (_backtrace_data_, 10);\
45
    char ** _backtrace_strs_ = backtrace_symbols (_backtrace_data_, _backtrace_len_);\
46
    if (_backtrace_strs_ == NULL) {\
47
      fprintf (stderr, "Could not get backtrace...\n");\
48
    } else {\
57 by Gustav Hartvigsson
* Tested print_backtrace() macro using MingW and Wine... Still needs testing on a real windows system.
49
      for (int i = 0; i < _backtrace_len_; i++) {\
56 by Gustav Hartvigsson
* Added print_backtrace() macro, UNTESTED.
50
        fprintf (stderr, "%s\n", _backtrace_strs_[i]);\
51
      }\
52
      free (_backtrace_strs_);\
53
    }\
57 by Gustav Hartvigsson
* Tested print_backtrace() macro using MingW and Wine... Still needs testing on a real windows system.
54
    fprintf (stderr, "[END BACKTRACE]\n");\
56 by Gustav Hartvigsson
* Added print_backtrace() macro, UNTESTED.
55
  }
56
#elif __WIN32__
57
  #pragma message ("We are a Windows (why, oh why?)")
57 by Gustav Hartvigsson
* Tested print_backtrace() macro using MingW and Wine... Still needs testing on a real windows system.
58
  #include <windows.h>
59
  #include <dbghelp.h>
60
  #include <winbase.h>
56 by Gustav Hartvigsson
* Added print_backtrace() macro, UNTESTED.
61
  #define print_backtrace() {\
62
    fprintf (stderr, "[BACKTRACE:]\n");\
63
    void * _backtrace_stack[10];\
64
    HANDLE _backtrace_proc = GetCurrentProcess ();\
65
    SymInitialize (_backtrace_proc, NULL, TRUE);\
57 by Gustav Hartvigsson
* Tested print_backtrace() macro using MingW and Wine... Still needs testing on a real windows system.
66
    unsigned short _backtrace_frames = CaptureStackBackTrace ( 0, 10, _backtrace_stack, NULL );\
67
    SYMBOL_INFO * _backtrace_symbol = calloc (1, sizeof (SYMBOL_INFOW) + (sizeof (char) * 256));\
56 by Gustav Hartvigsson
* Added print_backtrace() macro, UNTESTED.
68
    _backtrace_symbol->MaxNameLen = 255;\
69
    _backtrace_symbol->SizeOfStruct = sizeof (SYMBOL_INFO);\
70
    for (int i = 0; i <= _backtrace_frames; i++) {\
57 by Gustav Hartvigsson
* Tested print_backtrace() macro using MingW and Wine... Still needs testing on a real windows system.
71
      SymFromAddr (_backtrace_proc, (DWORD64)(_backtrace_stack[i]), 0, _backtrace_symbol);\
72
      fprintf (stderr, "%i: %s - 0x%0X\n", _backtrace_frames - i, _backtrace_symbol->Name, _backtrace_symbol->Address);\
56 by Gustav Hartvigsson
* Added print_backtrace() macro, UNTESTED.
73
    }\
74
    free (_backtrace_symbol);\
57 by Gustav Hartvigsson
* Tested print_backtrace() macro using MingW and Wine... Still needs testing on a real windows system.
75
    fprintf (stderr, "[END BACKTRACE]\n");\
76
  }
56 by Gustav Hartvigsson
* Added print_backtrace() macro, UNTESTED.
77
#else
78
  #pragma message ("We are not a UNIX")
79
  #define print_backtrace() {\
80
    fprintf(stdout, "[Can not get backtrace]\nCurrent Function:" __func__);\
57 by Gustav Hartvigsson
* Tested print_backtrace() macro using MingW and Wine... Still needs testing on a real windows system.
81
    fprintf (stderr, "[END BACKTRACE]\n");\
56 by Gustav Hartvigsson
* Added print_backtrace() macro, UNTESTED.
82
  }
83
#endif
84
57 by Gustav Hartvigsson
* Tested print_backtrace() macro using MingW and Wine... Still needs testing on a real windows system.
85
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
86
#ifndef FALSE
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
87
/**
88
 * FALSE has the absolute value of 0, it is used in as a way to represet a false
89
 * value. A "not" value.
90
 */
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
91
#define FALSE 0
92
#endif
93
94
#ifndef TRUE
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
95
 /**
96
  * TRUE represets a value that is true. A value that is "not false".
97
  */
98
#define TRUE (!FALSE)
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
99
#endif
100
53 by Gustav Hartvigsson
* Finnished up s_map_add () ???
101
#define S_POINTER_TO_HASH_T(p) ((hash_t)(unsigned long) p)
102
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
103
/**
104
 * sboolean is the standard definition of a boolean value in SSTS.
105
 *
106
 * @sa TRUE
107
 * @sa FALSE
108
 *
109
 * @note
110
 * This is the way it is done in GLib, so it is done here too.
111
 */
112
typedef int sboolean;
113
43 by Gustav Hartvigsson
* Code cleanup
114
/** hash type  */
48 by Gustav Hartvigsson
* Finnished SLinkedList.
115
typedef size_t hash_t;
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
116
43 by Gustav Hartvigsson
* Code cleanup
117
/** spointer is a convinience typedef of void * */
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
118
typedef void* spointer;
119
48 by Gustav Hartvigsson
* Finnished SLinkedList.
120
/** sconstpointer is a convinience typedef of const void * */
121
typedef const void* sconstpointer;
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
122
123
/**
124
 * Represents different types of objects.
125
 *
126
 * @se STypeName
127
 */
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
128
typedef enum {
43 by Gustav Hartvigsson
* Code cleanup
129
  S_TYPE_NONE = 0,
130
  S_TYPE_INT,
49 by Gustav Hartvigsson
* started work SBox (Untested).
131
  S_TYPE_LONG,
132
  S_TYPE_SHORT,
43 by Gustav Hartvigsson
* Code cleanup
133
  S_TYPE_CHAR,
49 by Gustav Hartvigsson
* started work SBox (Untested).
134
  S_TYPE_WCHAR,
135
  S_TYPE_UINT,
136
  S_TYPE_ULONG,
137
  S_TYPE_USHORT,
43 by Gustav Hartvigsson
* Code cleanup
138
  S_TYPE_BOOLEAN,
49 by Gustav Hartvigsson
* started work SBox (Untested).
139
  S_TYPE_STRING,
140
  S_TYPE_WSTRING,
43 by Gustav Hartvigsson
* Code cleanup
141
  S_TYPE_UNUSED_0,
142
  S_TYPE_UNUSED_1,
143
  S_TYPE_UNUSED_2,
49 by Gustav Hartvigsson
* started work SBox (Untested).
144
  S_TYPE_POINTER,
43 by Gustav Hartvigsson
* Code cleanup
145
  S_TYPE_OBJECT,
146
  S_TYPE_INVALID
147
} SType;
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
148
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
149
/** @brief
150
 * The names of the SType's
49 by Gustav Hartvigsson
* started work SBox (Untested).
151
 *
152
 * 
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
153
 */
50 by Gustav Hartvigsson
* Added a bindings friendly way of getting the SType name.
154
static char * STypeName[] __attribute__((unused)) = {
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
155
  "NONE",
156
  "INT",
49 by Gustav Hartvigsson
* started work SBox (Untested).
157
  "LONG",
158
  "SHORT",
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
159
  "CHAR",
49 by Gustav Hartvigsson
* started work SBox (Untested).
160
  "WCHAR",
161
  "UINT",
162
  "ULONG",
163
  "USHORT"
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
164
  "BOOLEAN",
49 by Gustav Hartvigsson
* started work SBox (Untested).
165
  "STRING",
166
  "WSTRING",
167
  "UNUSED_0/INVALID",
168
  "UNUSED_1/INVALID",
169
  "UNUSED_2/INVALID",
170
  "POINTER",
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
171
  "OBJECT",
172
  "INVALID",
173
  0x0,
174
  0x0,
43 by Gustav Hartvigsson
* Code cleanup
175
};
26 by Gustav Hartvigsson
* Added something to config.h.in, still not sure how it cmake works.
176
50 by Gustav Hartvigsson
* Added a bindings friendly way of getting the SType name.
177
/**
178
 * @brief Get the name of the SType.
179
 *
180
 * For use in bindings.
181
 */
182
char * s_type_get_name (SType k);
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
183
26 by Gustav Hartvigsson
* Added something to config.h.in, still not sure how it cmake works.
184
/* Colour definitions for console prints */
185
#define RESET   "\033[0m"
186
#define BLACK   "\033[30m"      /* Black */
187
#define RED     "\033[31m"      /* Red */
188
#define GREEN   "\033[32m"      /* Green */
189
#define YELLOW  "\033[33m"      /* Yellow */
190
#define BLUE    "\033[34m"      /* Blue */
191
#define MAGENTA "\033[35m"      /* Magenta */
192
#define CYAN    "\033[36m"      /* Cyan */
193
#define WHITE   "\033[37m"      /* White */
194
#define BOLDBLACK   "\033[1m\033[30m"      /* Bold Black */
195
#define BOLDRED     "\033[1m\033[31m"      /* Bold Red */
196
#define BOLDGREEN   "\033[1m\033[32m"      /* Bold Green */
197
#define BOLDYELLOW  "\033[1m\033[33m"      /* Bold Yellow */
198
#define BOLDBLUE    "\033[1m\033[34m"      /* Bold Blue */
199
#define BOLDMAGENTA "\033[1m\033[35m"      /* Bold Magenta */
200
#define BOLDCYAN    "\033[1m\033[36m"      /* Bold Cyan */
201
#define BOLDWHITE   "\033[1m\033[37m"      /* Bold White */
202
33 by Gustav Hartvigsson
* made test_macros.h a lil' bit more portable
203
26 by Gustav Hartvigsson
* Added something to config.h.in, still not sure how it cmake works.
204
END_DECLS
205
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
206
#endif