bzr branch
http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
|
3
by Gustav Hartvigsson
Fixed a few things... |
1 |
#include "Error.h" |
2 |
#include "SimpleTypeSystem.h" |
|
3 |
#include <stdlib.h> |
|
4 |
#include <string.h> |
|
5 |
#include <stdio.h> |
|
6 |
||
7 |
struct _SErrorPrivate { |
|
8 |
SErrorType error_type; |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
9 |
char * message; |
|
3
by Gustav Hartvigsson
Fixed a few things... |
10 |
};
|
11 |
||
12 |
char * error_to_string_method (SError * self); |
|
13 |
void error_deinit_method (SError * self); |
|
14 |
||
15 |
SError * s_error_new (SErrorType error, char * message) { |
|
16 |
SError * self = malloc (sizeof (SError)); |
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
17 |
SErrorClass * klass = malloc (sizeof (SErrorClass)); |
18 |
self->priv = malloc (sizeof (SErrorPrivate)); |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
19 |
|
20 |
s_base_object_set_class ((SBaseObjectInstance *) self, (SBaseObjectClass *) klass); |
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
21 |
s_base_object_initize ((SBaseObjectInstance *) self); |
22 |
s_base_object_set_to_string_method ((SBaseObjectInstance *) self, error_to_string_method); |
|
23 |
s_base_object_set_deinit_method ((SBaseObjectInstance *) self, error_deinit_method); |
|
24 |
self->priv->message = s_string_new (message); |
|
25 |
self->priv->error_type = error; |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
26 |
return self; |
|
3
by Gustav Hartvigsson
Fixed a few things... |
27 |
}
|
28 |
||
29 |
void s_error_free (SError * self) { |
|
30 |
s_base_object_free ((SBaseObjectInstance *) self); |
|
31 |
}
|
|
32 |
||
33 |
char * error_to_string_method (SError * self) { |
|
34 |
char * ret_val = malloc (sizeof(char) * 32); |
|
35 |
char * error_type_str = NULL; |
|
36 |
switch (self->priv->error_type) { |
|
37 |
case S_ERROR_NONE: |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
38 |
error_type_str = s_string_new ("NONE"); |
|
3
by Gustav Hartvigsson
Fixed a few things... |
39 |
break; |
40 |
case S_ERROR_INPUT_OUTPUT: |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
41 |
error_type_str = s_string_new ("INPUT/OUTPUT"); |
|
3
by Gustav Hartvigsson
Fixed a few things... |
42 |
break; |
43 |
case S_ERROR_OVERFLOW: |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
44 |
error_type_str = s_string_new ("OVERFLOW"); |
|
3
by Gustav Hartvigsson
Fixed a few things... |
45 |
break; |
46 |
case S_ERROR_OTHER: |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
47 |
error_type_str = s_string_new ("OTHER"); |
|
3
by Gustav Hartvigsson
Fixed a few things... |
48 |
break; |
49 |
case S_ERROR_NULL: |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
50 |
error_type_str = s_string_new ("NULL"); |
|
3
by Gustav Hartvigsson
Fixed a few things... |
51 |
break; |
52 |
default: |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
53 |
error_type_str = s_string_new ("(null)"); |
54 |
} |
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
55 |
sprintf (ret_val, "Error: %s, Message: %s", error_type_str, self->priv->message); |
56 |
free (error_type_str); |
|
57 |
return ret_val; |
|
58 |
}
|
|
59 |
||
60 |
void error_deinit_method (SError * self) { |
|
61 |
free (self->priv->message); |
|
62 |
free (self->priv); |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
63 |
SBaseObjectInstance * base = (SBaseObjectInstance *) self; |
64 |
SErrorClass * klass = (SErrorClass *) base->base_class; |
|
65 |
free (klass); |
|
66 |
free (self); |
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
67 |
}
|
68 |
||
69 |