/simpletypesystem/trunk

To get this branch, use:
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
  char * message;
9
  SErrorType error_type;
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
  s_base_object_set_class ((SBaseObjectInstance *) self, (SBaseObjectClass *) klass);
3 by Gustav Hartvigsson
Fixed a few things...
19
  s_base_object_initize ((SBaseObjectInstance *) self);
20
  s_base_object_set_to_string_method ((SBaseObjectInstance *) self, error_to_string_method);
21
  s_base_object_set_deinit_method ((SBaseObjectInstance *) self, error_deinit_method);
22
  self->priv->message = s_string_new (message);
23
  return self;
24
}
25
26
void s_error_free (SError * self) {
27
  s_base_object_free ((SBaseObjectInstance *) self);
28
}
29
30
char * error_to_string_method (SError * self) {
31
  char * ret_val = malloc (sizeof(char) * 32);
32
  char * error_type_str = NULL;
33
  switch (self->priv->error_type) {
34
    case (S_ERROR_NONE):
35
      error_type_str = s_string_new ("NONE");
36
      break;
37
    case (S_ERROR_INPUT_OUTPUT):
38
      error_type_str = s_string_new ("INPUT/OUTPUT");
39
      break;
40
    case (S_ERROR_OVERFLOW):
41
      error_type_str = s_string_new ("OVERFLOW");
42
      break;
43
    case (S_ERROR_OTHER):
44
      error_type_str = s_string_new ("OTHER");
45
      break;
46
    case (S_ERROR_NULL):
47
      error_type_str = s_string_new ("NULL");
48
      break;
49
  }
50
  sprintf (ret_val, "Error: %s, Message: %s", error_type_str, self->priv->message);
51
  
52
  free (error_type_str);
53
  return ret_val;
54
}
55
56
void error_deinit_method (SError * self) {
57
  free (self->priv->message);
58
  free ((SErrorClass *) s_base_object_get_class ((SBaseObjectInstance *) self));
59
  free (self);
60
}
61
62