/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: 2015-04-08 18:25:07 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20150408182507-094jw13yhmi3bhfu
* Added "check" target for testing.
* Changed SRC to SSTS_SRC for future proofing.
* Removed a few "_" from before some struct names. It is not needed.
* Re-wrote how s_object_to_string () works on SError's. Should be faster now, but less safe...
  * To make this work I added SErrorTypeName string array. (Need to surpress the errer it creats).
* Re-orderd SErrorType enum.
* Use s_string_new_fmt () the default method for s_object_to_string ().
* Changed to strdup in some functions in utils.c.
* Added s_current_time () function to get an ISO time string.
* Added some more documentation to utils.h
* !DEBUG -> DEBUG in utils.h
* Added more tests to the test suite.
* Re-Wrote test_macros.h to display time, making it a lil' bit nicer to look at.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <string.h>
26
26
#include <stdio.h>
27
27
#include <assert.h>
28
 
 
29
 
struct _SErrorPrivate {
 
28
#include "utils.h"
 
29
 
 
30
 
 
31
struct SErrorPrivate {
30
32
  SErrorType error_type;
31
33
  char * message;
32
34
};
35
37
void error_free_method (SError * self);
36
38
 
37
39
SError * s_error_new (SErrorType error, char * message) {
38
 
  assert (message != NULL);
39
 
  
40
40
  SError * self = malloc (sizeof (SError));
41
41
  SErrorClass * klass = malloc (sizeof (SErrorClass));
42
42
  self->priv = malloc (sizeof (SErrorPrivate));
45
45
  s_object_initialize ((SObject *) self);
46
46
  s_object_set_to_string_method ((SObject *) self, error_to_string_method);
47
47
  s_object_set_free_method ((SObject *) self, METHOD(error_free_method));
 
48
 
48
49
  self->priv->message = s_string_new (message);
49
50
  self->priv->error_type = error;
50
51
  return self;
56
57
 
57
58
char * error_to_string_method (SObject * obj) {
58
59
  SError * self = (SError *) obj;
59
 
  char * ret_val = malloc (sizeof(char) * 32);
 
60
  char * ret_val = NULL;
60
61
  char * error_type_str = NULL;
61
 
  switch (self->priv->error_type) {
62
 
    case S_ERROR_NONE:
63
 
      error_type_str = s_string_new ("NONE");
64
 
      break;
65
 
    case S_ERROR_INPUT_OUTPUT:
66
 
      error_type_str = s_string_new ("INPUT/OUTPUT");
67
 
      break;
68
 
    case S_ERROR_OVERFLOW:
69
 
      error_type_str = s_string_new ("OVERFLOW");
70
 
      break;
71
 
    case S_ERROR_OTHER:
72
 
      error_type_str = s_string_new ("OTHER");
73
 
      break;
74
 
    case S_ERROR_NULL:
75
 
      error_type_str = s_string_new ("NULL");
76
 
      break;
77
 
    default:
78
 
      error_type_str = s_string_new ("(null)");
79
 
  }
80
 
  sprintf (ret_val, "Error: %s, Message: %s", error_type_str, self->priv->message);
 
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);
81
65
  free (error_type_str);
82
66
  return ret_val;
83
67
}