/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
43 by Gustav Hartvigsson
* Code cleanup
1
#include "Box.h"
49 by Gustav Hartvigsson
* started work SBox (Untested).
2
#include <stdlib.h>
3
61 by Gustav Hartvigsson
* Made the code more easy to read.
4
struct
5
SBoxPrivate {
49 by Gustav Hartvigsson
* started work SBox (Untested).
6
  sboolean                      free_data;
7
  SType                         object_type;
8
  SObject *                     m_sobject;
9
  spointer                      m_ptr;
10
  sboolean                      m_sboolean;
11
  int                           m_int;
12
  long                          m_long;
13
  short                         m_short;
14
  char                          m_char;
15
  wchar_t                       m_wchar;
16
  unsigned int                  m_uint;
17
  unsigned long                 m_ulong;
18
  unsigned short                m_ushort;
19
  char *                        m_string;
20
  wchar_t *                     m_wstring;
21
};
22
61 by Gustav Hartvigsson
* Made the code more easy to read.
23
void
24
s_method_box_free (SBox * self);
49 by Gustav Hartvigsson
* started work SBox (Untested).
25
26
/* Private function to allocate and set methods to the SBox.
27
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
28
SBox *
29
internal_s_box_new () {
49 by Gustav Hartvigsson
* started work SBox (Untested).
30
  SBox * self = malloc (sizeof (SBox));
31
  SBoxClass * klass = malloc (sizeof (SBoxClass));
32
  s_object_initialize (S_OBJECT (self), "SBox");
33
  
34
  s_object_set_class (S_OBJECT (self), S_OBJECT_CLASS (klass));
35
  s_object_set_free_method (S_OBJECT (self), FREE_METHOD (s_method_box_free));
36
  
37
  return self;
38
}
39
61 by Gustav Hartvigsson
* Made the code more easy to read.
40
SBox *
41
s_box_new_pointer (spointer object);
42
43
SBox *
44
s_box_new_sobject (SObject * object);
45
46
SBox *
47
s_box_new_int (int i);
48
49
SBox *
50
s_box_new_long (long l);
51
52
SBox *
53
s_box_new_short (short s);
54
55
SBox *
56
s_box_new_char (char c);
57
58
SBox *
59
s_box_new_wchar (wchar_t wc);
60
61
SBox *
62
s_box_new_uint (unsigned int ui);
63
64
SBox *
65
s_box_new_ulong (long l);
66
67
SBox *
68
s_box_new_ushort (short s);
69
70
SBox *
71
s_box_new_string (char * s);
72
73
SBox *
74
s_box_new_wstring (wchar_t * ws);
75
76
void
77
s_box_free (SBox * self) {
49 by Gustav Hartvigsson
* started work SBox (Untested).
78
  s_object_free (S_OBJECT (self));
79
}
80
61 by Gustav Hartvigsson
* Made the code more easy to read.
81
void
82
s_box_set_free_data_on_free (SBox * self, sboolean free_data) {
49 by Gustav Hartvigsson
* started work SBox (Untested).
83
  
84
}
85
61 by Gustav Hartvigsson
* Made the code more easy to read.
86
void
87
s_box_set_free_func (SBox * self, FreeFunc free_func) {
49 by Gustav Hartvigsson
* started work SBox (Untested).
88
  SBoxClass * klass = S_BOX_CLASS (s_object_get_class(S_OBJECT (self)));
89
  klass->free_func = free_func;
90
}
91
61 by Gustav Hartvigsson
* Made the code more easy to read.
92
void
93
s_method_box_free (SBox * self) {
49 by Gustav Hartvigsson
* started work SBox (Untested).
94
  SBoxClass * klass = S_BOX_CLASS (s_object_get_class(S_OBJECT(self)));
95
  
96
  SBoxPrivate * priv = self->priv;
97
  
98
  FreeFunc free_func = klass->free_func;
99
  
100
  if (priv->free_data) {
101
    switch (priv->object_type) {
102
      case S_TYPE_OBJECT:
103
        s_object_free (priv->m_sobject);
104
        break;
105
      case S_TYPE_POINTER:
106
        if (free_func) {
107
          free_func (priv->m_ptr);
108
        } else {
109
          free (priv->m_ptr);
110
        }
111
        break;
112
      case S_TYPE_STRING:
113
        free (priv->m_string);
114
        break;
115
      case S_TYPE_WSTRING:
116
        free (priv->m_wstring);
117
        break;
118
      default:
119
        s_warn_print ("[SBox] free_data was set despite not being an object"
120
                      "that can be freed.");
121
    }
122
  }
123
  
124
  free (self->priv);
125
  free (klass);
126
  
127
}
128
43 by Gustav Hartvigsson
* Code cleanup
129