/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
1 by Gustav Hartvigsson
Initial Code.
1
/*
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
2
Copyright (c) 2013-2014 Gustav Hartvigsson
3
4
Permission is hereby granted, free of charge, to any person obtaining a copy
5
of this software and associated documentation files (the "Software"), to deal
6
in the Software without restriction, including without limitation the rights
7
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
copies of the Software, and to permit persons to whom the Software is
9
furnished to do so, subject to the following conditions:
10
11
The above copyright notice and this permission notice shall be included in
12
all copies or substantial portions of the Software.
13
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
THE SOFTWARE.
1 by Gustav Hartvigsson
Initial Code.
21
*/
22
62 by Gustav Hartvigsson
* General documentation clean up.
23
24
1 by Gustav Hartvigsson
Initial Code.
25
#ifndef __H_BASE_OBJECT__
26
#define __H_BASE_OBJECT__
27
45 by Gustav Hartvigsson
* Fixed indirect dependency in baseobject.h
28
#include "defs.h"
29
#include "utils.h"
47 by Gustav Hartvigsson
* Added a few skeletal functions to Callback.h
30
#include "Map.h"
45 by Gustav Hartvigsson
* Fixed indirect dependency in baseobject.h
31
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
32
S_BEGIN_DECLS
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
33
5.1.4 by Gustav Hartvigsson
* Added a comment to baseoject.h describing what the file does.
34
/** @file
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
35
 * @defgroup SObject SObject
36
 * @addtogroup SObject SObject
37
 * @{
5.2.9 by Gustav Hartvigsson
* Added license to files
38
 * An SObject represents the base of the Super Simple Type System.
107 by Gustav Hartvigsson
* Removed depricaded functions from SObject code.
39
 *
5.1.4 by Gustav Hartvigsson
* Added a comment to baseoject.h describing what the file does.
40
 * Almost all other data structures in this library are children to this object
41
 * type.
42
 *
5.2.9 by Gustav Hartvigsson
* Added license to files
43
 * All objects that inherent from SObject get the ability to have
5.1.4 by Gustav Hartvigsson
* Added a comment to baseoject.h describing what the file does.
44
 * reference counting of objects via built in functions.
62 by Gustav Hartvigsson
* General documentation clean up.
45
 *
46
 * @section Signals/Callbacks
47
 * @par @c notify
48
 *    This signal is envoked when a propertiy is changed in an SObject.
49
 * @endpar
5.1.4 by Gustav Hartvigsson
* Added a comment to baseoject.h describing what the file does.
50
 */
51
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
52
/**
53
 * The class holds all the "virtual" functions, also knows  as methods
54
 * that are to be used with the object.
107 by Gustav Hartvigsson
* Removed depricaded functions from SObject code.
55
 *
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
56
 */
57
typedef struct SObjectClass SObjectClass;
58
59
/**
60
 * The instance holds the data that is associated with the object.
61
 * it also holds a pointer to the class of the object.
107 by Gustav Hartvigsson
* Removed depricaded functions from SObject code.
62
 *
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
63
 */
64
typedef struct SObject SObject;
65
32 by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt
66
/**
67
 *
68
 */
69
typedef void (* FreeMethod)(SObject *);
70
71
/**
72
 *
73
 */
74
typedef char * (* ToStringFunc)(SObject *);
75
76
/**
107 by Gustav Hartvigsson
* Removed depricaded functions from SObject code.
77
 *
32 by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt
78
 */
79
typedef void (* MethodFunc)(SObject *);
80
81
/**
82
 *
83
 */
84
typedef int (* MethodFuncInt)(SObject *);
85
45 by Gustav Hartvigsson
* Fixed indirect dependency in baseobject.h
86
#define FREE_METHOD(k) (FreeMethod)k
87
#define TO_STRING_FUNC(k) (ToStringFunc)k
88
#define METHOD_FUNC(k) (MethodFunc)k
89
#define METHOD_FUNC_INT(k) (MethodFuncInt)k
32 by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt
90
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
91
#define S_OBJECT(k) (SObject *)k
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
92
#define S_OBJECT_CLASS(k) (SObjectClass *)k
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
93
61 by Gustav Hartvigsson
* Made the code more easy to read.
94
struct
95
SObjectClass {
32 by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt
96
  MethodFunc initialize;
97
  MethodFunc deinitialize;
98
  FreeMethod free;
99
  MethodFuncInt ref;
100
  MethodFuncInt unref;
101
  MethodFuncInt get_refcount;
102
  ToStringFunc to_string;
3 by Gustav Hartvigsson
Fixed a few things...
103
};
104
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
105
61 by Gustav Hartvigsson
* Made the code more easy to read.
106
struct
107
SObject {
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
108
  schar * name; /*< The name of the class.*/
48 by Gustav Hartvigsson
* Finnished SLinkedList.
109
  SObjectClass * base_class; /*< holds the reference to the class. */
110
  SMap * callbacks; /*< This is what holds the callbacks. */
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
111
  suint refcount; /*< The reference count. */
3 by Gustav Hartvigsson
Fixed a few things...
112
};
113
1 by Gustav Hartvigsson
Initial Code.
114
115
/* -----------------
116
 * Helper functions...
117
 * -----------------
118
 */
77 by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-)
119
1 by Gustav Hartvigsson
Initial Code.
120
121
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
122
 * This function is used to set the ref method.
107 by Gustav Hartvigsson
* Removed depricaded functions from SObject code.
123
 *
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
124
 * @warning DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
1 by Gustav Hartvigsson
Initial Code.
125
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
126
void
127
s_object_set_ref_method (SObject * self, MethodFuncInt method);
1 by Gustav Hartvigsson
Initial Code.
128
129
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
130
 * This function is used to set the unref method.
107 by Gustav Hartvigsson
* Removed depricaded functions from SObject code.
131
 *
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
132
 * @warning DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
1 by Gustav Hartvigsson
Initial Code.
133
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
134
void
135
s_object_set_unref_method (SObject * self, MethodFuncInt method);
1 by Gustav Hartvigsson
Initial Code.
136
77 by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-)
137
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
138
 * This function is used to set the get_refcount method.
107 by Gustav Hartvigsson
* Removed depricaded functions from SObject code.
139
 *
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
140
 * @warning DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
1 by Gustav Hartvigsson
Initial Code.
141
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
142
void
143
s_object_set_get_refcount_method (SObject * self,  MethodFuncInt method);
1 by Gustav Hartvigsson
Initial Code.
144
77 by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-)
145
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
146
 * This function is used to set the to_string method.
1 by Gustav Hartvigsson
Initial Code.
147
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
148
void
149
s_object_set_to_string_method (SObject * self, ToStringFunc method);
5.2.9 by Gustav Hartvigsson
* Added license to files
150
22 by Gustav Hartvigsson
* Made code compile
151
/**
152
 *
153
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
154
void
155
s_object_set_free_method (SObject * self, MethodFunc method);
22 by Gustav Hartvigsson
* Made code compile
156
5.2.9 by Gustav Hartvigsson
* Added license to files
157
158
/* concrete functions are defined in the C file.
1 by Gustav Hartvigsson
Initial Code.
159
 */
160
161
/* ----------------------
162
 * Base object functions.
163
 * ----------------------
164
 */
165
77 by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-)
166
/**
167
 * @brief
5.2.9 by Gustav Hartvigsson
* Added license to files
168
 * Initializes an SObject
107 by Gustav Hartvigsson
* Removed depricaded functions from SObject code.
169
 *
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
170
 * @param self The object to initialize.
107 by Gustav Hartvigsson
* Removed depricaded functions from SObject code.
171
 *
5.2.9 by Gustav Hartvigsson
* Added license to files
172
 * This function initializes an instance of the SObject, it also sets
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
173
 * the methods to be used with the object and sets the reference count to one.
1 by Gustav Hartvigsson
Initial Code.
174
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
175
void
176
s_object_initialize (SObject * self, const char * name);
1 by Gustav Hartvigsson
Initial Code.
177
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
178
/** @brief
1 by Gustav Hartvigsson
Initial Code.
179
 * This function creates a new base object.
107 by Gustav Hartvigsson
* Removed depricaded functions from SObject code.
180
 *
5.2.9 by Gustav Hartvigsson
* Added license to files
181
 * @return a new SObject
1 by Gustav Hartvigsson
Initial Code.
182
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
183
SObject *
184
s_object_new ();
1 by Gustav Hartvigsson
Initial Code.
185
186
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
187
 * This function desensitizes/frees an object even if it is still referenced.
5.2.9 by Gustav Hartvigsson
* Added license to files
188
 * This is usually a bad idea, use s_object_unref () instead.
1 by Gustav Hartvigsson
Initial Code.
189
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
190
void
191
s_object_free (SObject * self);
1 by Gustav Hartvigsson
Initial Code.
192
193
/**
194
 * This function gets the class (which hold the object methods).
195
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
196
SObjectClass *
197
s_object_get_class (SObject * self);
1 by Gustav Hartvigsson
Initial Code.
198
199
/**
200
 * This function sets the instance class of an object.
201
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
202
void
203
s_object_set_class (SObject * self, SObjectClass * klass);
1 by Gustav Hartvigsson
Initial Code.
204
205
/**
206
 * This function is used to decrese the reference count of an object.
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
207
 * When an object reaches zero, it will deinitialize the object using the
208
 * objects deinitialize method.
107 by Gustav Hartvigsson
* Removed depricaded functions from SObject code.
209
 *
1 by Gustav Hartvigsson
Initial Code.
210
 * It returns the current (after change) reference count.
211
 */
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
212
sint
61 by Gustav Hartvigsson
* Made the code more easy to read.
213
s_object_unref (SObject * self);
1 by Gustav Hartvigsson
Initial Code.
214
215
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
216
 * This function is used to increase the reference count of an object.
1 by Gustav Hartvigsson
Initial Code.
217
 *
218
 * Returns the current (after change) reference count.
219
 */
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
220
sint
61 by Gustav Hartvigsson
* Made the code more easy to read.
221
s_object_ref (SObject * self);
1 by Gustav Hartvigsson
Initial Code.
222
223
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
224
 * This function returns the current reference count without changing it.
1 by Gustav Hartvigsson
Initial Code.
225
 */
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
226
sint
61 by Gustav Hartvigsson
* Made the code more easy to read.
227
s_object_get_refcount (SObject * self);
1 by Gustav Hartvigsson
Initial Code.
228
229
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
230
 * This function returns a textual (string) that represents the object.
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
231
 * The method can be set using s_object_set_to_string_method().
1 by Gustav Hartvigsson
Initial Code.
232
 *
233
 * Note: The string that is returned must be freed.
234
 */
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
235
schar *
61 by Gustav Hartvigsson
* Made the code more easy to read.
236
s_object_to_string (SObject * self);
1 by Gustav Hartvigsson
Initial Code.
237
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
238
/**
239
 * @}
240
 */
241
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
242
S_END_DECLS
1 by Gustav Hartvigsson
Initial Code.
243
244
#endif