bzr branch
http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
|
5.2.7
by Gustav Hartvigsson
* Switched licence to a more permisive one. |
1 |
/*
|
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.
|
|
21 |
*/
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
22 |
|
23 |
#include "Error.h" |
|
24 |
#include "SimpleTypeSystem.h" |
|
25 |
#include <stdlib.h> |
|
26 |
#include <string.h> |
|
27 |
#include <stdio.h> |
|
28 |
||
29 |
struct _SErrorPrivate { |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
30 |
SErrorType error_type; |
|
3
by Gustav Hartvigsson
Fixed a few things... |
31 |
char * message; |
32 |
};
|
|
33 |
||
34 |
char * error_to_string_method (SError * self); |
|
35 |
void error_deinit_method (SError * self); |
|
36 |
||
37 |
SError * s_error_new (SErrorType error, char * message) { |
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
38 |
SError * self = malloc (sizeof (SError)); |
39 |
SErrorClass * klass = malloc (sizeof (SErrorClass)); |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
40 |
self->priv = malloc (sizeof (SErrorPrivate)); |
41 |
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
42 |
s_base_object_set_class ((SBaseObjectInstance *) self, (SBaseObjectClass *) klass); |
43 |
s_base_object_initize ((SBaseObjectInstance *) self); |
|
44 |
s_base_object_set_to_string_method ((SBaseObjectInstance *) self, error_to_string_method); |
|
45 |
s_base_object_set_deinit_method ((SBaseObjectInstance *) self, error_deinit_method); |
|
46 |
self->priv->message = s_string_new (message); |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
47 |
self->priv->error_type = error; |
|
3
by Gustav Hartvigsson
Fixed a few things... |
48 |
return self; |
49 |
}
|
|
50 |
||
51 |
void s_error_free (SError * self) { |
|
52 |
s_base_object_free ((SBaseObjectInstance *) self); |
|
53 |
}
|
|
54 |
||
55 |
char * error_to_string_method (SError * self) { |
|
56 |
char * ret_val = malloc (sizeof(char) * 32); |
|
57 |
char * error_type_str = NULL; |
|
58 |
switch (self->priv->error_type) { |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
59 |
case S_ERROR_NONE: |
|
3
by Gustav Hartvigsson
Fixed a few things... |
60 |
error_type_str = s_string_new ("NONE"); |
61 |
break; |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
62 |
case S_ERROR_INPUT_OUTPUT: |
|
3
by Gustav Hartvigsson
Fixed a few things... |
63 |
error_type_str = s_string_new ("INPUT/OUTPUT"); |
64 |
break; |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
65 |
case S_ERROR_OVERFLOW: |
|
3
by Gustav Hartvigsson
Fixed a few things... |
66 |
error_type_str = s_string_new ("OVERFLOW"); |
67 |
break; |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
68 |
case S_ERROR_OTHER: |
|
3
by Gustav Hartvigsson
Fixed a few things... |
69 |
error_type_str = s_string_new ("OTHER"); |
70 |
break; |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
71 |
case S_ERROR_NULL: |
|
3
by Gustav Hartvigsson
Fixed a few things... |
72 |
error_type_str = s_string_new ("NULL"); |
73 |
break; |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
74 |
default: |
75 |
error_type_str = s_string_new ("(null)"); |
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
76 |
} |
77 |
sprintf (ret_val, "Error: %s, Message: %s", error_type_str, self->priv->message); |
|
78 |
free (error_type_str); |
|
79 |
return ret_val; |
|
80 |
}
|
|
81 |
||
82 |
void error_deinit_method (SError * self) { |
|
83 |
free (self->priv->message); |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
84 |
free (self->priv); |
85 |
SBaseObjectInstance * base = (SBaseObjectInstance *) self; |
|
86 |
SErrorClass * klass = (SErrorClass *) base->base_class; |
|
87 |
free (klass); |
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
88 |
free (self); |
89 |
}
|
|
90 |