/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
130.1.4 by Gustav Hartvigsson
* Inpremented the manual mark and sweep thingys.
1
#pragma once
2
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
3
/*
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
4
Copyright (c) 2013-2014 Gustav Hartvigsson
5
6
Permission is hereby granted, free of charge, to any person obtaining a copy
7
of this software and associated documentation files (the "Software"), to deal
8
in the Software without restriction, including without limitation the rights
9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
copies of the Software, and to permit persons to whom the Software is
11
furnished to do so, subject to the following conditions:
12
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
15
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
THE SOFTWARE.
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
23
*/
24
3 by Gustav Hartvigsson
Fixed a few things...
25
#include "baseobject.h"
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
26
#include "defs.h"
22 by Gustav Hartvigsson
* Made code compile
27
#include "utils.h"
28
#include "Func.h"
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
29
#include "DynamicArray.h"
3 by Gustav Hartvigsson
Fixed a few things...
30
#include <limits.h>
31
#include <stdlib.h>
32
#include <stdio.h>
33
#include <string.h>
34
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
35
S_BEGIN_DECLS
22 by Gustav Hartvigsson
* Made code compile
36
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
37
/**
130.1.4 by Gustav Hartvigsson
* Inpremented the manual mark and sweep thingys.
38
 * @file
62 by Gustav Hartvigsson
* General documentation clean up.
39
 * @defgroup SError SError
40
 * @addtogroup SError
41
 * @{
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
42
 *
43
 * Error that can be added to and passed down to the caller.
44
 *
45
 * @section Theory
46
 *
47
 * The Theory behind how SError works is a complex story in where there are
48
 * dragons.
49
 *
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
50
 */
3 by Gustav Hartvigsson
Fixed a few things...
51
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
52
#define S_ERROR_DOMAIN_RANGE_MAX 128
53
54
typedef schar * (* SErrorDomainToString)(sint error_id, schar * error_msg);
55
56
#define S_ERROR_DOMAIN_TO_STRING_FUNC(k) ((SErrorDomainToString)(k))
94 by Gustav Hartvigsson
* Added discussion on SError and Error Pragagation.
57
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
58
/**
19 by Gustav Hartvigsson
* Woops
59
 * An SError is a data structure that inherits from SBaseObjectInstance.
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
60
 *
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
61
 * An SError represents an error that can occur.
62
 */
100 by Gustav Hartvigsson
* Fixed README.
63
typedef struct SError SError;
3 by Gustav Hartvigsson
Fixed a few things...
64
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
65
typedef sint SErrorDomain;
66
67
49 by Gustav Hartvigsson
* started work SBox (Untested).
68
#define S_ERROR(o) (SError *)(o)
69
#define S_ERROR_CLASS(k) (SErrorClass *)(k)
70
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
71
/** @brief
72
 * The different error types.
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
73
 *
74
 * These are the erros that are in the default error domain.
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
75
 */
3 by Gustav Hartvigsson
Fixed a few things...
76
typedef enum {
8 by Gustav Hartvigsson
* Fixed a DoxyGen error documentation error of an enum.
77
  S_ERROR_NONE = 0, /**< Not on error */
43 by Gustav Hartvigsson
* Code cleanup
78
  S_ERROR_INPUT_OUTPUT,/**< An I/O error */
79
  S_ERROR_OVERFLOW, /**< An Overflow error */
62 by Gustav Hartvigsson
* General documentation clean up.
80
  S_ERROR_TYPE_ERROR, /** Some generic type error. */
43 by Gustav Hartvigsson
* Code cleanup
81
  S_ERROR_UNUSED_0,
82
  S_ERROR_UNUSED_1,
83
  S_ERROR_UNUSED_2,
84
  S_ERROR_OTHER, /**< Some unknowned error */
85
  S_ERROR_NULL /**< An NULL error */
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
86
} SDefaultErrorType;
3 by Gustav Hartvigsson
Fixed a few things...
87
39 by Gustav Hartvigsson
* Added "check" target for testing.
88
/**
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
89
 * @var static char * SDefaultErrorTypeName[]
62 by Gustav Hartvigsson
* General documentation clean up.
90
 * @breif
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
91
 * Holds the names of the string version of SDefaultErrorType.
39 by Gustav Hartvigsson
* Added "check" target for testing.
92
 */
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
93
static schar * SDefaultErrorTypeName[] S_UNUSED = {
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
94
  "NONE",
95
  "INPUT/OUTPUT",
96
  "OVERFLOW",
62 by Gustav Hartvigsson
* General documentation clean up.
97
  "TYPE_ERROR",
49 by Gustav Hartvigsson
* started work SBox (Untested).
98
  "UNUSED_0/INVALID",
99
  "UNUSED_1/INVALID",
100
  "UNUSED_2/INVALID",
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
101
  "OTHER",
102
  "NULL",
103
  0x0,
104
  0x0
105
};
39 by Gustav Hartvigsson
* Added "check" target for testing.
106
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
107
S_EXPORTED
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
108
schar *
109
s_default_error_domain_to_string (sint error_id, schar * msg);
110
111
/**
112
 * The Default Error Domain.
113
 */
114
#define S_ERROR_GET_DEFAULT_DOMAIN\
115
  s_error_get_domain ("default",\
116
                      S_ERROR_DOMAIN_TO_STRING_FUNC (s_default_error_domain_to_string))
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
117
49 by Gustav Hartvigsson
* started work SBox (Untested).
118
/**
119
 * @brief
120
 * Function to get the same of an error.
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
121
 *
49 by Gustav Hartvigsson
* started work SBox (Untested).
122
 * For use in bindings.
123
 *
124
 * @param k The key to look up.
125
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
126
S_EXPORTED
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
127
schar *
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
128
s_default_error_get_name (SDefaultErrorType k);
129
130
/**
131
 * the constructor for the an SError.
132
 *
133
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
134
S_EXPORTED
104 by Gustav Hartvigsson
* Passing arguments can not be initialised from within a function...
135
SError *
136
s_error_new (void);
137
108 by Gustav Hartvigsson
libssts:
138
/**
139
 * This function calles the deinitize method of the object.
140
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
141
S_EXPORTED
108 by Gustav Hartvigsson
libssts:
142
void
143
s_error_free (SError * self);
144
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
145
S_EXPORTED
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
146
void
104 by Gustav Hartvigsson
* Passing arguments can not be initialised from within a function...
147
s_error_append (SError * self ,sint error, const schar * message, SErrorDomain error_domain);
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
148
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
149
S_EXPORTED
108 by Gustav Hartvigsson
libssts:
150
sboolean
151
s_error_has_error (SError * self);
152
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
153
/**
154
 * Returns an array with the error strings.
155
 * Must be freed by caller.
156
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
157
S_EXPORTED
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
158
SDynamicArray *
159
s_error_to_string_array (SError * self);
3 by Gustav Hartvigsson
Fixed a few things...
160
161
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
162
/**
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
163
 * This function should be run at the end of each program.
164
 * It frees any resorses that has been allocated in the running of the program.
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
165
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
166
S_EXPORTED
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
167
void
168
s_error_teardown (void);
3 by Gustav Hartvigsson
Fixed a few things...
169
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
170
/**
171
 * This function prints the current error to stdout.
172
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
173
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
174
void
175
s_error_print_error (SError * self);
3 by Gustav Hartvigsson
Fixed a few things...
176
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
177
178
/**
179
 * This function registers an error domain if it has not allready been registered,
180
 * and if it has been registered it returns the SErrorDomain handle associated
181
 * with the error domain.
182
 *
183
 * @param name
184
 *
185
 * @param to_string_func the
186
 *
187
 * @returns an SErrorDomain handle.
188
 *
189
 * @returns < 0 an error
190
 * has ocured. Most likely a missmatch between the provided to_string_func
191
 * and a to_string_func that allready has been registered.
192
 *
193
 * To make this lees tedious to work with it is recomended to make a macro
194
 * to call this function.
195
 @code {.c}
196
#define MY_MODULE_ERROR_DOMAIN\
197
  s_error_get_domain ("MyModule"\
198
                      my_module_error_to_string_func)
199
 @endcode
200
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
201
S_EXPORTED
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
202
SErrorDomain
203
s_error_get_domain (const schar * name,
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
204
                    SErrorDomainToString to_string_func);
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
205
206
94 by Gustav Hartvigsson
* Added discussion on SError and Error Pragagation.
207
62 by Gustav Hartvigsson
* General documentation clean up.
208
/** @} */
209
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
210
S_END_DECLS