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 <stdlib.h> |
|
25 |
#include <string.h> |
|
26 |
#include <stdio.h> |
|
|
22
by Gustav Hartvigsson
* Made code compile |
27 |
#include <assert.h> |
|
39
by Gustav Hartvigsson
* Added "check" target for testing. |
28 |
#include "utils.h" |
29 |
||
30 |
||
31 |
struct SErrorPrivate { |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
32 |
SErrorType error_type; |
|
3
by Gustav Hartvigsson
Fixed a few things... |
33 |
char * message; |
34 |
};
|
|
35 |
||
|
22
by Gustav Hartvigsson
* Made code compile |
36 |
char * error_to_string_method (SObject * self); |
37 |
void error_free_method (SError * self); |
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
38 |
|
39 |
SError * s_error_new (SErrorType error, char * message) { |
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
40 |
SError * self = malloc (sizeof (SError)); |
41 |
SErrorClass * klass = malloc (sizeof (SErrorClass)); |
|
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
42 |
self->priv = malloc (sizeof (SErrorPrivate)); |
43 |
|
|
|
48
by Gustav Hartvigsson
* Finnished SLinkedList. |
44 |
s_object_set_class (S_OBJECT (self), S_OBJECT_CLASS (klass)); |
45 |
s_object_initialize (S_OBJECT (self), "Error"); |
|
46 |
s_object_set_to_string_method (S_OBJECT (self), error_to_string_method); |
|
47 |
s_object_set_free_method (S_OBJECT (self), METHOD(error_free_method)); |
|
48 |
|
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
49 |
self->priv->message = s_string_new (message); |
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
50 |
self->priv->error_type = error; |
|
3
by Gustav Hartvigsson
Fixed a few things... |
51 |
return self; |
52 |
}
|
|
53 |
||
54 |
void s_error_free (SError * self) { |
|
|
48
by Gustav Hartvigsson
* Finnished SLinkedList. |
55 |
s_object_free (S_OBJECT (self)); |
|
3
by Gustav Hartvigsson
Fixed a few things... |
56 |
}
|
57 |
||
|
22
by Gustav Hartvigsson
* Made code compile |
58 |
char * error_to_string_method (SObject * obj) { |
|
49
by Gustav Hartvigsson
* started work SBox (Untested). |
59 |
SError * self = S_ERROR (obj); |
|
39
by Gustav Hartvigsson
* Added "check" target for testing. |
60 |
char * ret_val = NULL; |
|
3
by Gustav Hartvigsson
Fixed a few things... |
61 |
char * error_type_str = NULL; |
|
39
by Gustav Hartvigsson
* Added "check" target for testing. |
62 |
error_type_str = s_string_new (SErrorTypeName[self->priv->error_type]); |
63 |
|
|
64 |
ret_val = s_string_new_fmt ("Error: %s, Message: %s", error_type_str, self->priv->message); |
|
|
3
by Gustav Hartvigsson
Fixed a few things... |
65 |
free (error_type_str); |
66 |
return ret_val; |
|
67 |
}
|
|
68 |
||
|
22
by Gustav Hartvigsson
* Made code compile |
69 |
void error_free_method (SError * self) { |
|
3
by Gustav Hartvigsson
Fixed a few things... |
70 |
free (self->priv->message); |
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
71 |
free (self->priv); |
|
49
by Gustav Hartvigsson
* started work SBox (Untested). |
72 |
SErrorClass * klass = S_ERROR_CLASS (s_object_get_class (S_OBJECT (self))); |
|
5.2.2
by Gustav Hartvigsson
Made sure -- using valgrind -- that the SBaseObjectInstance and |
73 |
free (klass); |
|
3
by Gustav Hartvigsson
Fixed a few things... |
74 |
free (self); |
75 |
}
|
|
76 |
||
|
49
by Gustav Hartvigsson
* started work SBox (Untested). |
77 |
char * s_error_get_name (SErrorType k) { |
78 |
return SErrorTypeName[k]; |
|
79 |
}
|
|
80 |