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" |
|
3
by Gustav Hartvigsson
Fixed a few things... |
32 |
#include <limits.h> |
33 |
#include <stdlib.h> |
|
34 |
#include <stdio.h> |
|
35 |
#include <string.h> |
|
36 |
||
22
by Gustav Hartvigsson
* Made code compile |
37 |
BEGIN_DECLS
|
38 |
||
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
39 |
/**
|
62
by Gustav Hartvigsson
* General documentation clean up. |
40 |
* @defgroup SError SError
|
41 |
* @addtogroup SError
|
|
42 |
* @{
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
43 |
* An opaque datastructure that holds the SError's private data.
|
44 |
*/
|
|
39
by Gustav Hartvigsson
* Added "check" target for testing. |
45 |
typedef struct SErrorPrivate SErrorPrivate; |
3
by Gustav Hartvigsson
Fixed a few things... |
46 |
|
94
by Gustav Hartvigsson
* Added discussion on SError and Error Pragagation. |
47 |
|
48 |
typedef void (* SErrorDomainToString)(sint error_id, schar * error_msg); |
|
49 |
||
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
50 |
/**
|
19
by Gustav Hartvigsson
* Woops |
51 |
* An SError is a data structure that inherits from SBaseObjectInstance.
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
52 |
*
|
53 |
* An SError represents an error that can occur.
|
|
54 |
*/
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
55 |
typedef struct |
56 |
SError { |
|
22
by Gustav Hartvigsson
* Made code compile |
57 |
SObject parent; |
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
58 |
SErrorPrivate * priv; /** Pimple pointer to the private data. */ |
3
by Gustav Hartvigsson
Fixed a few things... |
59 |
|
60 |
} SError; |
|
61 |
||
62 |
/**
|
|
63 |
* The error class is not changed, no extra methods are needed.
|
|
64 |
*/
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
65 |
typedef struct |
66 |
SErrorClass { |
|
22
by Gustav Hartvigsson
* Made code compile |
67 |
SObjectClass parent_class; |
3
by Gustav Hartvigsson
Fixed a few things... |
68 |
|
69 |
} SErrorClass; |
|
70 |
||
49
by Gustav Hartvigsson
* started work SBox (Untested). |
71 |
#define S_ERROR(o) (SError *)(o)
|
72 |
#define S_ERROR_CLASS(k) (SErrorClass *)(k)
|
|
73 |
||
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
74 |
/** @brief
|
75 |
* The different error types.
|
|
76 |
*/
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
77 |
typedef enum { |
8
by Gustav Hartvigsson
* Fixed a DoxyGen error documentation error of an enum. |
78 |
S_ERROR_NONE = 0, /**< Not on error */ |
43
by Gustav Hartvigsson
* Code cleanup |
79 |
S_ERROR_INPUT_OUTPUT,/**< An I/O error */ |
80 |
S_ERROR_OVERFLOW, /**< An Overflow error */ |
|
62
by Gustav Hartvigsson
* General documentation clean up. |
81 |
S_ERROR_TYPE_ERROR, /** Some generic type error. */ |
43
by Gustav Hartvigsson
* Code cleanup |
82 |
S_ERROR_UNUSED_0, |
83 |
S_ERROR_UNUSED_1, |
|
84 |
S_ERROR_UNUSED_2, |
|
85 |
S_ERROR_OTHER, /**< Some unknowned error */ |
|
86 |
S_ERROR_NULL /**< An NULL error */ |
|
3
by Gustav Hartvigsson
Fixed a few things... |
87 |
} SErrorType; |
88 |
||
39
by Gustav Hartvigsson
* Added "check" target for testing. |
89 |
/**
|
94
by Gustav Hartvigsson
* Added discussion on SError and Error Pragagation. |
90 |
* @var static char * SErrorTypeName[]
|
62
by Gustav Hartvigsson
* General documentation clean up. |
91 |
* @breif
|
39
by Gustav Hartvigsson
* Added "check" target for testing. |
92 |
* Holds the names of the string version of SErrorType.
|
93 |
*/
|
|
72
by Gustav Hartvigsson
* Added our own types for stability and shit and giggles. |
94 |
static schar * SErrorTypeName[] UNUSED = { |
46
by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray. |
95 |
"NONE", |
96 |
"INPUT/OUTPUT", |
|
97 |
"OVERFLOW", |
|
62
by Gustav Hartvigsson
* General documentation clean up. |
98 |
"TYPE_ERROR", |
49
by Gustav Hartvigsson
* started work SBox (Untested). |
99 |
"UNUSED_0/INVALID", |
100 |
"UNUSED_1/INVALID", |
|
101 |
"UNUSED_2/INVALID", |
|
46
by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray. |
102 |
"OTHER", |
103 |
"NULL", |
|
104 |
0x0, |
|
105 |
0x0 |
|
106 |
};
|
|
39
by Gustav Hartvigsson
* Added "check" target for testing. |
107 |
|
72
by Gustav Hartvigsson
* Added our own types for stability and shit and giggles. |
108 |
|
109 |
||
49
by Gustav Hartvigsson
* started work SBox (Untested). |
110 |
/**
|
111 |
* @brief
|
|
112 |
* Function to get the same of an error.
|
|
113 |
*
|
|
114 |
* For use in bindings.
|
|
115 |
*
|
|
116 |
* @param k The key to look up.
|
|
117 |
*/
|
|
72
by Gustav Hartvigsson
* Added our own types for stability and shit and giggles. |
118 |
schar * |
61
by Gustav Hartvigsson
* Made the code more easy to read. |
119 |
s_error_get_name (SErrorType k); |
3
by Gustav Hartvigsson
Fixed a few things... |
120 |
|
121 |
/**
|
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
122 |
* the constructor for the an SError
|
3
by Gustav Hartvigsson
Fixed a few things... |
123 |
*/
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
124 |
SError * |
72
by Gustav Hartvigsson
* Added our own types for stability and shit and giggles. |
125 |
s_error_new (SErrorType error, schar * message); |
3
by Gustav Hartvigsson
Fixed a few things... |
126 |
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
127 |
/**
|
128 |
* This function calles the deinitize method of the object.
|
|
129 |
*/
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
130 |
void
|
131 |
s_error_free (SError * self); |
|
3
by Gustav Hartvigsson
Fixed a few things... |
132 |
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
133 |
/**
|
134 |
* This function returns the ErrorType of on object.
|
|
135 |
*/
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
136 |
SErrorType
|
137 |
s_error_get_error_type (SError * self); |
|
3
by Gustav Hartvigsson
Fixed a few things... |
138 |
|
5.1.1
by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen. |
139 |
/**
|
140 |
* This function prints the current error to stdout.
|
|
141 |
*/
|
|
61
by Gustav Hartvigsson
* Made the code more easy to read. |
142 |
void
|
143 |
s_error_print_error (SError * self); |
|
3
by Gustav Hartvigsson
Fixed a few things... |
144 |
|
94
by Gustav Hartvigsson
* Added discussion on SError and Error Pragagation. |
145 |
#if 0
|
146 |
TODO
|
|
147 |
##########
|
|
148 |
||
149 |
I have been thinking about Error Propagation in SSTS and GLib.
|
|
150 |
||
151 |
I noticed that errors in GLib does not rely propagate, you can do
|
|
152 |
g_error_propagate () but that assumes that the error that is fed to the function
|
|
153 |
is an array. This assumption can never be made and makes it very complex to deal
|
|
154 |
with different ways of doing things in different parts of a program (GError * vs
|
|
155 |
GError **).
|
|
156 |
||
157 |
So what I am thinking of doing is a little more complex: have explicit
|
|
158 |
registration of error domains (s_error_domain_register (schar * name,
|
|
159 |
FuncPointer to_string), s_error_domain_is_registered (schar *)).
|
|
160 |
||
161 |
The other thing I was thinking is that errors should have implicit propagation.
|
|
162 |
(IE: no s_error_new () only s_error_append ()) and have the propagation
|
|
163 |
information stored in an array. (ID and message).
|
|
164 |
||
165 |
The problem with this is that where do you call s_error_domain_register ()?
|
|
166 |
||
167 |
In the constructor of an SObject would be a great place to put it, if not for
|
|
168 |
the problem that we have to call s_error_domain_is_registered when a new
|
|
169 |
instance of an object is created.
|
|
170 |
||
171 |
In the main function is just tedious, Wrapping the main function in something
|
|
172 |
like an S_MAIN macro could work and have an internal
|
|
173 |
s_library_register_error_domains function somewhere and require the user to
|
|
174 |
implement an s_user_register_error_domains function.
|
|
175 |
||
176 |
This puts even more work on the shoulders of the developers that uses the
|
|
177 |
library.
|
|
178 |
||
179 |
It seems that no matter what I do (A true propagating error system or
|
|
180 |
something like GError from GLib) I put extra work in the lap of the developer
|
|
181 |
that uses the library.
|
|
182 |
||
183 |
Commets?
|
|
184 |
||
185 |
##########
|
|
186 |
||
187 |
void
|
|
188 |
s_error_domain_register (schar * domain, SErrorDomainToString func);
|
|
189 |
||
190 |
sboolean
|
|
191 |
s_error_domain_is_registerd (schar * domain);
|
|
192 |
#endif
|
|
193 |
||
62
by Gustav Hartvigsson
* General documentation clean up. |
194 |
/** @} */
|
195 |
||
22
by Gustav Hartvigsson
* Made code compile |
196 |
END_DECLS
|
197 |
||
3
by Gustav Hartvigsson
Fixed a few things... |
198 |
#endif
|