/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: 2013-09-06 15:05:32 UTC
  • mfrom: (5.2.4 simple_type_system_SMap)
  • Revision ID: gustav.hartvigsson@gmail.com-20130906150532-tudew69vmiljy1t6
* Merged the still unfinished SMap impleementation,
* TODO:
       To build a working SMap the system must determin whether or not an
       object is a child to SBaseObjectInstance or not.

       This is a non-trivial thing to do, and req. a lot of base work:
         A lookup table for objects is needed, with appropriet functions
         and probobly a main-loop.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
#include <stdio.h>
7
7
 
8
8
struct _SErrorPrivate {
 
9
  SErrorType error_type;
9
10
  char * message;
10
 
  SErrorType error_type;
11
11
};
12
12
 
13
13
char * error_to_string_method (SError * self);
14
14
void error_deinit_method (SError * self);
15
15
 
16
16
SError * s_error_new (SErrorType error, char * message) {
17
 
  SError * self = malloc (sizeof (SError) + 1);
18
 
  SErrorClass * klass = malloc (sizeof (SErrorClass) + 1);
 
17
  SError * self = malloc (sizeof (SError));
 
18
  SErrorClass * klass = malloc (sizeof (SErrorClass));
 
19
  self->priv = malloc (sizeof (SErrorPrivate));
 
20
  
19
21
  s_base_object_set_class ((SBaseObjectInstance *) self, (SBaseObjectClass *) klass);
20
22
  s_base_object_initize ((SBaseObjectInstance *) self);
21
23
  s_base_object_set_to_string_method ((SBaseObjectInstance *) self, error_to_string_method);
22
24
  s_base_object_set_deinit_method ((SBaseObjectInstance *) self, error_deinit_method);
23
25
  self->priv->message = s_string_new (message);
 
26
  self->priv->error_type = error;
24
27
  return self;
25
28
}
26
29
 
32
35
  char * ret_val = malloc (sizeof(char) * 32);
33
36
  char * error_type_str = NULL;
34
37
  switch (self->priv->error_type) {
35
 
    case (S_ERROR_NONE):
 
38
    case S_ERROR_NONE:
36
39
      error_type_str = s_string_new ("NONE");
37
40
      break;
38
 
    case (S_ERROR_INPUT_OUTPUT):
 
41
    case S_ERROR_INPUT_OUTPUT:
39
42
      error_type_str = s_string_new ("INPUT/OUTPUT");
40
43
      break;
41
 
    case (S_ERROR_OVERFLOW):
 
44
    case S_ERROR_OVERFLOW:
42
45
      error_type_str = s_string_new ("OVERFLOW");
43
46
      break;
44
 
    case (S_ERROR_OTHER):
 
47
    case S_ERROR_OTHER:
45
48
      error_type_str = s_string_new ("OTHER");
46
49
      break;
47
 
    case (S_ERROR_NULL):
 
50
    case S_ERROR_NULL:
48
51
      error_type_str = s_string_new ("NULL");
49
52
      break;
 
53
    default:
 
54
      error_type_str = s_string_new ("(null)");
50
55
  }
51
56
  sprintf (ret_val, "Error: %s, Message: %s", error_type_str, self->priv->message);
52
 
  
53
57
  free (error_type_str);
54
58
  return ret_val;
55
59
}
56
60
 
57
61
void error_deinit_method (SError * self) {
58
62
  free (self->priv->message);
59
 
  free ((SErrorClass *) s_base_object_get_class ((SBaseObjectInstance *) self));
 
63
  free (self->priv);
 
64
  SBaseObjectInstance * base = (SBaseObjectInstance *) self;
 
65
  SErrorClass * klass = (SErrorClass *) base->base_class;
 
66
  free (klass);
60
67
  free (self);
61
68
}
62
69