/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
32
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.
5.1.4 by Gustav Hartvigsson
* Added a comment to baseoject.h describing what the file does.
39
 * 
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
1 by Gustav Hartvigsson
Initial Code.
52
/* ---------------------------------------------------
53
 * This is just a test of creating a small typesystem.
54
 * It will include refrence counting.
55
 * ---------------------------------------------------
56
 */
57
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
58
/**
59
 * The class holds all the "virtual" functions, also knows  as methods
60
 * that are to be used with the object.
61
 * 
62
 */
63
typedef struct SObjectClass SObjectClass;
64
65
/**
66
 * The instance holds the data that is associated with the object.
67
 * it also holds a pointer to the class of the object.
68
 * 
69
 */
70
typedef struct SObject SObject;
71
32 by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt
72
/**
73
 *
74
 */
75
typedef void (* FreeMethod)(SObject *);
76
77
/**
78
 *
79
 */
80
typedef char * (* ToStringFunc)(SObject *);
81
82
/**
83
 * 
84
 */
85
typedef void (* MethodFunc)(SObject *);
86
87
/**
88
 *
89
 */
90
typedef int (* MethodFuncInt)(SObject *);
91
45 by Gustav Hartvigsson
* Fixed indirect dependency in baseobject.h
92
#define FREE_METHOD(k) (FreeMethod)k
93
#define TO_STRING_FUNC(k) (ToStringFunc)k
94
#define METHOD_FUNC(k) (MethodFunc)k
95
#define METHOD_FUNC_INT(k) (MethodFuncInt)k
32 by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt
96
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
97
#define S_OBJECT(k) (SObject *)k
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
98
#define S_OBJECT_CLASS(k) (SObjectClass *)k
23 by Gustav Hartvigsson
* Fixed some of the build warnings.
99
61 by Gustav Hartvigsson
* Made the code more easy to read.
100
struct
101
SObjectClass {
32 by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt
102
  MethodFunc initialize;
103
  MethodFunc deinitialize;
104
  FreeMethod free;
105
  MethodFuncInt ref;
106
  MethodFuncInt unref;
107
  MethodFuncInt get_refcount;
108
  ToStringFunc to_string;
3 by Gustav Hartvigsson
Fixed a few things...
109
};
110
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
111
61 by Gustav Hartvigsson
* Made the code more easy to read.
112
struct
113
SObject {
48 by Gustav Hartvigsson
* Finnished SLinkedList.
114
  char * name; /*< The name of the class.*/
115
  SObjectClass * base_class; /*< holds the reference to the class. */
116
  SMap * callbacks; /*< This is what holds the callbacks. */
117
  unsigned int refcount; /*< The reference count. */
3 by Gustav Hartvigsson
Fixed a few things...
118
};
119
1 by Gustav Hartvigsson
Initial Code.
120
121
/* -----------------
122
 * Helper functions...
123
 * -----------------
124
 */
5.2.9 by Gustav Hartvigsson
* Added license to files
125
/** This function is used to set the method to initialize a new instance of an
1 by Gustav Hartvigsson
Initial Code.
126
 * object.
32 by Gustav Hartvigsson
* Added some compile options to the root CMakeLists.txt
127
 * 
128
 * 
1 by Gustav Hartvigsson
Initial Code.
129
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
130
void
131
s_object_set_initialize_method (SObject * self, MethodFunc method);
1 by Gustav Hartvigsson
Initial Code.
132
133
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
134
 * This function is used to set the method to deinitialize an object.
1 by Gustav Hartvigsson
Initial Code.
135
 * 
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
136
 * set it to a method that deinitialize your object.
1 by Gustav Hartvigsson
Initial Code.
137
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
138
void
139
s_object_set_deinitialize_method (SObject * self, MethodFunc method);
1 by Gustav Hartvigsson
Initial Code.
140
141
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
142
 * This function is used to set the ref method.
1 by Gustav Hartvigsson
Initial Code.
143
 * 
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
144
 * @warning DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
1 by Gustav Hartvigsson
Initial Code.
145
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
146
void
147
s_object_set_ref_method (SObject * self, MethodFuncInt method);
1 by Gustav Hartvigsson
Initial Code.
148
149
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
150
 * This function is used to set the unref method.
1 by Gustav Hartvigsson
Initial Code.
151
 * 
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
152
 * @warning DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
1 by Gustav Hartvigsson
Initial Code.
153
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
154
void
155
s_object_set_unref_method (SObject * self, MethodFuncInt method);
1 by Gustav Hartvigsson
Initial Code.
156
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
157
/**!
158
 * This function is used to set the get_refcount method.
1 by Gustav Hartvigsson
Initial Code.
159
 * 
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
160
 * @warning DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
1 by Gustav Hartvigsson
Initial Code.
161
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
162
void
163
s_object_set_get_refcount_method (SObject * self,  MethodFuncInt method);
1 by Gustav Hartvigsson
Initial Code.
164
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
165
/**!
166
 * This function is used to set the to_string method.
1 by Gustav Hartvigsson
Initial Code.
167
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
168
void
169
s_object_set_to_string_method (SObject * self, ToStringFunc method);
5.2.9 by Gustav Hartvigsson
* Added license to files
170
22 by Gustav Hartvigsson
* Made code compile
171
/**
172
 *
173
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
174
void
175
s_object_set_free_method (SObject * self, MethodFunc method);
22 by Gustav Hartvigsson
* Made code compile
176
5.2.9 by Gustav Hartvigsson
* Added license to files
177
178
/* concrete functions are defined in the C file.
1 by Gustav Hartvigsson
Initial Code.
179
 */
180
181
/* ----------------------
182
 * Base object functions.
183
 * ----------------------
184
 */
185
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
186
/** @brief
5.2.9 by Gustav Hartvigsson
* Added license to files
187
 * Initializes an SObject
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
188
 * 
189
 * @param self The object to initialize.
190
 * 
5.2.9 by Gustav Hartvigsson
* Added license to files
191
 * 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.
192
 * the methods to be used with the object and sets the reference count to one.
1 by Gustav Hartvigsson
Initial Code.
193
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
194
void
195
s_object_initialize (SObject * self, const char * name);
1 by Gustav Hartvigsson
Initial Code.
196
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
197
/** @brief
1 by Gustav Hartvigsson
Initial Code.
198
 * This function creates a new base object.
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
199
 * 
5.2.9 by Gustav Hartvigsson
* Added license to files
200
 * @return a new SObject
1 by Gustav Hartvigsson
Initial Code.
201
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
202
SObject *
203
s_object_new ();
1 by Gustav Hartvigsson
Initial Code.
204
205
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
206
 * This function desensitizes/frees an object even if it is still referenced.
5.2.9 by Gustav Hartvigsson
* Added license to files
207
 * This is usually a bad idea, use s_object_unref () instead.
1 by Gustav Hartvigsson
Initial Code.
208
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
209
void
210
s_object_free (SObject * self);
1 by Gustav Hartvigsson
Initial Code.
211
212
/**
213
 * This function gets the class (which hold the object methods).
214
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
215
SObjectClass *
216
s_object_get_class (SObject * self);
1 by Gustav Hartvigsson
Initial Code.
217
218
/**
219
 * This function sets the instance class of an object.
220
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
221
void
222
s_object_set_class (SObject * self, SObjectClass * klass);
1 by Gustav Hartvigsson
Initial Code.
223
224
/**
225
 * 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.
226
 * When an object reaches zero, it will deinitialize the object using the
227
 * objects deinitialize method.
1 by Gustav Hartvigsson
Initial Code.
228
 * 
229
 * It returns the current (after change) reference count.
230
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
231
int
232
s_object_unref (SObject * self);
1 by Gustav Hartvigsson
Initial Code.
233
234
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
235
 * This function is used to increase the reference count of an object.
1 by Gustav Hartvigsson
Initial Code.
236
 *
237
 * Returns the current (after change) reference count.
238
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
239
int
240
s_object_ref (SObject * self);
1 by Gustav Hartvigsson
Initial Code.
241
242
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
243
 * This function returns the current reference count without changing it.
1 by Gustav Hartvigsson
Initial Code.
244
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
245
int
246
s_object_get_refcount (SObject * self);
1 by Gustav Hartvigsson
Initial Code.
247
248
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
249
 * This function returns a textual (string) that represents the object.
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
250
 * The method can be set using s_object_set_to_string_method().
1 by Gustav Hartvigsson
Initial Code.
251
 *
252
 * Note: The string that is returned must be freed.
253
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
254
char *
255
s_object_to_string (SObject * self);
1 by Gustav Hartvigsson
Initial Code.
256
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
257
/**
258
 * @}
259
 */
260
22 by Gustav Hartvigsson
* Made code compile
261
END_DECLS
1 by Gustav Hartvigsson
Initial Code.
262
263
#endif