/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk

« back to all changes in this revision

Viewing changes to src/Error.c

  • Committer: Gustav Hartvigsson
  • Date: 2014-11-24 17:37:05 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20141124173705-iu97keoxp0qfxlxm
* Made code compile

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
*/
22
22
 
23
23
#include "Error.h"
24
 
#include "SimpleTypeSystem.h"
25
24
#include <stdlib.h>
26
25
#include <string.h>
27
26
#include <stdio.h>
 
27
#include <assert.h>
28
28
 
29
29
struct _SErrorPrivate {
30
30
  SErrorType error_type;
31
31
  char * message;
32
32
};
33
33
 
34
 
char * error_to_string_method (SError * self);
35
 
void error_deinit_method (SError * self);
 
34
char * error_to_string_method (SObject * self);
 
35
void error_free_method (SError * self);
36
36
 
37
37
SError * s_error_new (SErrorType error, char * message) {
 
38
  assert (message != NULL);
 
39
  
38
40
  SError * self = malloc (sizeof (SError));
39
41
  SErrorClass * klass = malloc (sizeof (SErrorClass));
40
42
  self->priv = malloc (sizeof (SErrorPrivate));
41
43
  
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);
 
44
  s_object_set_class ((SObject *) self, (SObjectClass *) klass);
 
45
  s_object_initialize ((SObject *) self);
 
46
  s_object_set_to_string_method ((SObject *) self, error_to_string_method);
 
47
  s_object_set_free_method ((SObject *) self, METHOD(error_free_method));
46
48
  self->priv->message = s_string_new (message);
47
49
  self->priv->error_type = error;
48
50
  return self;
49
51
}
50
52
 
51
53
void s_error_free (SError * self) {
52
 
  s_base_object_free ((SBaseObjectInstance *) self);
 
54
  s_object_free ((SObject *) self);
53
55
}
54
56
 
55
 
char * error_to_string_method (SError * self) {
 
57
char * error_to_string_method (SObject * obj) {
 
58
  SError * self = (SError *) obj;
56
59
  char * ret_val = malloc (sizeof(char) * 32);
57
60
  char * error_type_str = NULL;
58
61
  switch (self->priv->error_type) {
79
82
  return ret_val;
80
83
}
81
84
 
82
 
void error_deinit_method (SError * self) {
 
85
void error_free_method (SError * self) {
83
86
  free (self->priv->message);
84
87
  free (self->priv);
85
 
  SBaseObjectInstance * base = (SBaseObjectInstance *) self;
 
88
  SObject * base = (SObject *) self;
86
89
  SErrorClass * klass = (SErrorClass *) base->base_class;
87
90
  free (klass);
88
91
  free (self);