/simpletypesystem/trunk

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