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