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 |
||
|
22
by Gustav Hartvigsson
* Made code compile |
38 |
BEGIN_DECLS
|
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 |
*/
|
|
103
by Gustav Hartvigsson
* General cleanup/make it pritty. |
95 |
static schar * SDefaultErrorTypeName[] 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 |
|
|
72
by Gustav Hartvigsson
* Added our own types for stability and shit and giggles. |
109 |
|
|
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 |
*/
|
|
|
72
by Gustav Hartvigsson
* Added our own types for stability and shit and giggles. |
128 |
schar * |
|
103
by Gustav Hartvigsson
* General cleanup/make it pritty. |
129 |
s_default_error_get_name (SDefaultErrorType k); |
130 |
||
131 |
/**
|
|
132 |
* the constructor for the an SError.
|
|
133 |
*
|
|
134 |
* This can be chained so that each level in a program can add information
|
|
135 |
* on what functions has been called, what module it comes from and/or what
|
|
136 |
* other information may be relevent.
|
|
137 |
*/
|
|
138 |
void
|
|
139 |
s_error_new (SError * self ,sint error, const schar * message, SErrorDomain error_domain); |
|
140 |
||
141 |
/**
|
|
142 |
* Returns an array with the error strings.
|
|
143 |
* Must be freed by caller.
|
|
144 |
*/
|
|
145 |
SDynamicArray * |
|
146 |
s_error_to_string_array (SError * self); |
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
147 |
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
148 |
/**
|
149 |
* This function calles the deinitize method of the object.
|
|
150 |
*/
|
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
151 |
void
|
152 |
s_error_free (SError * self); |
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
153 |
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
154 |
/**
|
|
103
by Gustav Hartvigsson
* General cleanup/make it pritty. |
155 |
* This function should be run at the end of each program.
|
156 |
* 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. |
157 |
*/
|
|
103
by Gustav Hartvigsson
* General cleanup/make it pritty. |
158 |
void
|
159 |
s_error_teardown (void); |
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
160 |
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
161 |
/**
|
162 |
* This function prints the current error to stdout.
|
|
163 |
*/
|
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
164 |
void
|
165 |
s_error_print_error (SError * self); |
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
166 |
|
|
103
by Gustav Hartvigsson
* General cleanup/make it pritty. |
167 |
|
168 |
/**
|
|
169 |
* This function registers an error domain if it has not allready been registered,
|
|
170 |
* and if it has been registered it returns the SErrorDomain handle associated
|
|
171 |
* with the error domain.
|
|
172 |
*
|
|
173 |
* @param name
|
|
174 |
*
|
|
175 |
* @param to_string_func the
|
|
176 |
*
|
|
177 |
* @returns an SErrorDomain handle.
|
|
178 |
*
|
|
179 |
* @returns < 0 an error
|
|
180 |
* has ocured. Most likely a missmatch between the provided to_string_func
|
|
181 |
* and a to_string_func that allready has been registered.
|
|
182 |
*
|
|
183 |
* To make this lees tedious to work with it is recomended to make a macro
|
|
184 |
* to call this function.
|
|
185 |
@code {.c}
|
|
186 |
#define MY_MODULE_ERROR_DOMAIN\
|
|
187 |
s_error_get_domain ("MyModule"\
|
|
188 |
my_module_error_to_string_func)
|
|
189 |
@endcode
|
|
190 |
*/
|
|
191 |
SErrorDomain
|
|
192 |
s_error_get_domain (const schar * name, |
|
193 |
SErrorDomainToString to_string_func); |
|
194 |
||
195 |
||
|
94
by Gustav Hartvigsson
* Added discussion on SError and Error Pragagation. |
196 |
|
|
62
by Gustav Hartvigsson
* General documentation clean up. |
197 |
/** @} */
|
198 |
||
|
22
by Gustav Hartvigsson
* Made code compile |
199 |
END_DECLS
|
200 |
||
|
3
by Gustav Hartvigsson
Fixed a few things... |
201 |
#endif
|