/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
126.1.1 by Gustav Hartvigsson
* Using
25
#pragma once
3 by Gustav Hartvigsson
Fixed a few things...
26
27
#include "baseobject.h"
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
28
#include "defs.h"
22 by Gustav Hartvigsson
* Made code compile
29
#include "utils.h"
30
#include "Func.h"
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
31
#include "DynamicArray.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
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
37
S_BEGIN_DECLS
22 by Gustav Hartvigsson
* Made code compile
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
 * @{
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
43
 *
44
 * Error that can be added to and passed down to the caller.
45
 *
46
 * @section Theory
47
 *
48
 * The Theory behind how SError works is a complex story in where there are
49
 * dragons.
50
 *
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
51
 */
3 by Gustav Hartvigsson
Fixed a few things...
52
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
53
#define S_ERROR_DOMAIN_RANGE_MAX 128
54
55
typedef schar * (* SErrorDomainToString)(sint error_id, schar * error_msg);
56
57
#define S_ERROR_DOMAIN_TO_STRING_FUNC(k) ((SErrorDomainToString)(k))
94 by Gustav Hartvigsson
* Added discussion on SError and Error Pragagation.
58
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
59
/**
19 by Gustav Hartvigsson
* Woops
60
 * An SError is a data structure that inherits from SBaseObjectInstance.
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
61
 *
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
62
 * An SError represents an error that can occur.
63
 */
100 by Gustav Hartvigsson
* Fixed README.
64
typedef struct SError SError;
3 by Gustav Hartvigsson
Fixed a few things...
65
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
66
typedef sint SErrorDomain;
67
68
49 by Gustav Hartvigsson
* started work SBox (Untested).
69
#define S_ERROR(o) (SError *)(o)
70
#define S_ERROR_CLASS(k) (SErrorClass *)(k)
71
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
72
/** @brief
73
 * The different error types.
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
74
 *
75
 * 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.
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 */
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
87
} SDefaultErrorType;
3 by Gustav Hartvigsson
Fixed a few things...
88
39 by Gustav Hartvigsson
* Added "check" target for testing.
89
/**
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
90
 * @var static char * SDefaultErrorTypeName[]
62 by Gustav Hartvigsson
* General documentation clean up.
91
 * @breif
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
92
 * Holds the names of the string version of SDefaultErrorType.
39 by Gustav Hartvigsson
* Added "check" target for testing.
93
 */
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
94
static schar * SDefaultErrorTypeName[] S_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
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
108
S_EXPORTED
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
109
schar *
110
s_default_error_domain_to_string (sint error_id, schar * msg);
111
112
/**
113
 * The Default Error Domain.
114
 */
115
#define S_ERROR_GET_DEFAULT_DOMAIN\
116
  s_error_get_domain ("default",\
117
                      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.
118
49 by Gustav Hartvigsson
* started work SBox (Untested).
119
/**
120
 * @brief
121
 * Function to get the same of an error.
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
122
 *
49 by Gustav Hartvigsson
* started work SBox (Untested).
123
 * For use in bindings.
124
 *
125
 * @param k The key to look up.
126
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
127
S_EXPORTED
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
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
135
S_EXPORTED
104 by Gustav Hartvigsson
* Passing arguments can not be initialised from within a function...
136
SError *
137
s_error_new (void);
138
108 by Gustav Hartvigsson
libssts:
139
/**
140
 * This function calles the deinitize method of the object.
141
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
142
S_EXPORTED
108 by Gustav Hartvigsson
libssts:
143
void
144
s_error_free (SError * self);
145
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
146
S_EXPORTED
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
147
void
104 by Gustav Hartvigsson
* Passing arguments can not be initialised from within a function...
148
s_error_append (SError * self ,sint error, const schar * message, SErrorDomain error_domain);
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
149
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
150
S_EXPORTED
108 by Gustav Hartvigsson
libssts:
151
sboolean
152
s_error_has_error (SError * self);
153
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
154
/**
155
 * Returns an array with the error strings.
156
 * Must be freed by caller.
157
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
158
S_EXPORTED
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
159
SDynamicArray *
160
s_error_to_string_array (SError * self);
3 by Gustav Hartvigsson
Fixed a few things...
161
162
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
163
/**
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
164
 * This function should be run at the end of each program.
165
 * 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.
166
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
167
S_EXPORTED
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
168
void
169
s_error_teardown (void);
3 by Gustav Hartvigsson
Fixed a few things...
170
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
171
/**
172
 * This function prints the current error to stdout.
173
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
174
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
175
void
176
s_error_print_error (SError * self);
3 by Gustav Hartvigsson
Fixed a few things...
177
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
178
179
/**
180
 * This function registers an error domain if it has not allready been registered,
181
 * and if it has been registered it returns the SErrorDomain handle associated
182
 * with the error domain.
183
 *
184
 * @param name
185
 *
186
 * @param to_string_func the
187
 *
188
 * @returns an SErrorDomain handle.
189
 *
190
 * @returns < 0 an error
191
 * has ocured. Most likely a missmatch between the provided to_string_func
192
 * and a to_string_func that allready has been registered.
193
 *
194
 * To make this lees tedious to work with it is recomended to make a macro
195
 * to call this function.
196
 @code {.c}
197
#define MY_MODULE_ERROR_DOMAIN\
198
  s_error_get_domain ("MyModule"\
199
                      my_module_error_to_string_func)
200
 @endcode
201
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
202
S_EXPORTED
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
203
SErrorDomain
204
s_error_get_domain (const schar * name,
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
205
                    SErrorDomainToString to_string_func);
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
206
207
94 by Gustav Hartvigsson
* Added discussion on SError and Error Pragagation.
208
62 by Gustav Hartvigsson
* General documentation clean up.
209
/** @} */
210
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
211
S_END_DECLS