/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "Box.h"
#include <stdlib.h>

struct SBoxPrivate {
  sboolean                      free_data;
  SType                         object_type;
  SObject *                     m_sobject;
  spointer                      m_ptr;
  sboolean                      m_sboolean;
  int                           m_int;
  long                          m_long;
  short                         m_short;
  char                          m_char;
  wchar_t                       m_wchar;
  unsigned int                  m_uint;
  unsigned long                 m_ulong;
  unsigned short                m_ushort;
  char *                        m_string;
  wchar_t *                     m_wstring;
};

void s_method_box_free (SBox * self);

/* Private function to allocate and set methods to the SBox.
 */
SBox * s_box_new () {
  SBox * self = malloc (sizeof (SBox));
  SBoxClass * klass = malloc (sizeof (SBoxClass));
  s_object_initialize (S_OBJECT (self), "SBox");
  
  s_object_set_class (S_OBJECT (self), S_OBJECT_CLASS (klass));
  s_object_set_free_method (S_OBJECT (self), FREE_METHOD (s_method_box_free));
  
  return self;
}

SBox * s_box_new_pointer (spointer object);

SBox * s_box_new_sobject (SObject * object);

SBox * s_box_new_int (int i);

SBox * s_box_new_long (long l);

SBox * s_box_new_short (short s);

SBox * s_box_new_char (char c);

SBox * s_box_new_wchar (wchar_t wc);

SBox * s_box_new_uint (unsigned int ui);

SBox * s_box_new_ulong (long l);

SBox * s_box_new_ushort (short s);

SBox * s_box_new_string (char * s);

SBox * s_box_new_wstring (wchar_t * ws);

void s_box_free (SBox * self) {
  s_object_free (S_OBJECT (self));
}

void s_box_set_free_data_on_free (SBox * self, sboolean free_data) {
  
}

void s_box_set_free_func (SBox * self, FreeFunc free_func) {
  SBoxClass * klass = S_BOX_CLASS (s_object_get_class(S_OBJECT (self)));
  klass->free_func = free_func;
}

void s_method_box_free (SBox * self) {
  SBoxClass * klass = S_BOX_CLASS (s_object_get_class(S_OBJECT(self)));
  
  SBoxPrivate * priv = self->priv;
  
  FreeFunc free_func = klass->free_func;
  
  if (priv->free_data) {
    switch (priv->object_type) {
      case S_TYPE_OBJECT:
        s_object_free (priv->m_sobject);
        break;
      case S_TYPE_POINTER:
        if (free_func) {
          free_func (priv->m_ptr);
        } else {
          free (priv->m_ptr);
        }
        break;
      case S_TYPE_STRING:
        free (priv->m_string);
        break;
      case S_TYPE_WSTRING:
        free (priv->m_wstring);
        break;
      default:
        s_warn_print ("[SBox] free_data was set despite not being an object"
                      "that can be freed.");
    }
  }
  
  free (self->priv);
  free (klass);
  
}