/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
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
23
/** @file */
24
1 by Gustav Hartvigsson
Initial Code.
25
#ifndef __H_BASE_OBJECT__
26
#define __H_BASE_OBJECT__
27
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
28
#include "defs.h"
21 by Gustav Hartvigsson
Woops!
29
#include "utils.h"
5.1.4 by Gustav Hartvigsson
* Added a comment to baseoject.h describing what the file does.
30
/** @file
5.2.9 by Gustav Hartvigsson
* Added license to files
31
 * 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.
32
 * 
33
 * Almost all other data structures in this library are children to this object
34
 * type.
35
 *
5.2.9 by Gustav Hartvigsson
* Added license to files
36
 * 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.
37
 * reference counting of objects via built in functions.
38
 */
39
1 by Gustav Hartvigsson
Initial Code.
40
/* ---------------------------------------------------
41
 * This is just a test of creating a small typesystem.
42
 * It will include refrence counting.
43
 * ---------------------------------------------------
44
 */
45
22 by Gustav Hartvigsson
* Made code compile
46
BEGIN_DECLS
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
47
5.2.9 by Gustav Hartvigsson
* Added license to files
48
typedef struct _SObjectClass SObjectClass;
49
50
51
typedef struct _SObject SObject;
3 by Gustav Hartvigsson
Fixed a few things...
52
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
53
/**
54
 * The class holds all the "virtual" functions, also knows  as methods
55
 * that are to be used with the object.
56
 * 
57
 */
5.2.9 by Gustav Hartvigsson
* Added license to files
58
struct _SObjectClass {
22 by Gustav Hartvigsson
* Made code compile
59
  void (* initialize)(SObject *);
60
  void (* deinitialize);
61
  void (* free)(SObject *);
62
  int (* ref)(SObject *);
63
  int (* unref)(SObject *);
64
  int (* get_refcount)(SObject *);
65
  char * (* to_string)(SObject *);
3 by Gustav Hartvigsson
Fixed a few things...
66
};
67
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
68
/**
69
 * The instance holds the data that is associated with the object.
70
 * it also holds a pointer to the class of the object.
71
 * 
72
 */
5.2.9 by Gustav Hartvigsson
* Added license to files
73
struct _SObject {
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
74
  char * name;
5.2.9 by Gustav Hartvigsson
* Added license to files
75
  SObjectClass * base_class;
3 by Gustav Hartvigsson
Fixed a few things...
76
  unsigned int refcount;
77
};
78
1 by Gustav Hartvigsson
Initial Code.
79
80
/* -----------------
81
 * Helper functions...
82
 * -----------------
83
 */
5.2.9 by Gustav Hartvigsson
* Added license to files
84
/** This function is used to set the method to initialize a new instance of an
1 by Gustav Hartvigsson
Initial Code.
85
 * object.
86
 */
22 by Gustav Hartvigsson
* Made code compile
87
void s_object_set_initialize_method (SObject * self, void (* method)(SObject *));
1 by Gustav Hartvigsson
Initial Code.
88
89
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
90
 * This function is used to set the method to deinitialize an object.
1 by Gustav Hartvigsson
Initial Code.
91
 * 
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
92
 * set it to a method that deinitialize your object.
1 by Gustav Hartvigsson
Initial Code.
93
 */
22 by Gustav Hartvigsson
* Made code compile
94
void s_object_set_deinitialize_method (SObject * self, void (* method)(SObject *));
1 by Gustav Hartvigsson
Initial Code.
95
96
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
97
 * This function is used to set the ref method.
1 by Gustav Hartvigsson
Initial Code.
98
 * 
99
 * DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
100
 */
5.2.9 by Gustav Hartvigsson
* Added license to files
101
void s_object_set_ref_method (SObject * self, int (* method)(SObject *));
1 by Gustav Hartvigsson
Initial Code.
102
103
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
104
 * This function is used to set the unref method.
1 by Gustav Hartvigsson
Initial Code.
105
 * 
106
 * DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
107
 */
5.2.9 by Gustav Hartvigsson
* Added license to files
108
void s_object_set_unref_method (SObject * self, int (* method)(SObject *));
1 by Gustav Hartvigsson
Initial Code.
109
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
110
/**!
111
 * This function is used to set the get_refcount method.
1 by Gustav Hartvigsson
Initial Code.
112
 * 
113
 * DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
114
 */
5.2.9 by Gustav Hartvigsson
* Added license to files
115
void s_object_set_get_refcount_method (SObject * self, int (* method)(SObject *));
1 by Gustav Hartvigsson
Initial Code.
116
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
117
/**!
118
 * This function is used to set the to_string method.
1 by Gustav Hartvigsson
Initial Code.
119
 */
5.2.9 by Gustav Hartvigsson
* Added license to files
120
void s_object_set_to_string_method (SObject * self, char * (* method)(SObject *));
121
22 by Gustav Hartvigsson
* Made code compile
122
/**
123
 *
124
 */
125
void s_object_set_free_method (SObject * self, void (* method)(SObject *));
126
5.2.9 by Gustav Hartvigsson
* Added license to files
127
128
/* concrete functions are defined in the C file.
1 by Gustav Hartvigsson
Initial Code.
129
 */
130
131
/* ----------------------
132
 * Base object functions.
133
 * ----------------------
134
 */
135
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
136
/** @brief
5.2.9 by Gustav Hartvigsson
* Added license to files
137
 * Initializes an SObject
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
138
 * 
139
 * @param self The object to initialize.
140
 * 
5.2.9 by Gustav Hartvigsson
* Added license to files
141
 * 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.
142
 * the methods to be used with the object and sets the reference count to one.
1 by Gustav Hartvigsson
Initial Code.
143
 */
22 by Gustav Hartvigsson
* Made code compile
144
void s_object_initialize (SObject * self);
1 by Gustav Hartvigsson
Initial Code.
145
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
146
/** @brief
1 by Gustav Hartvigsson
Initial Code.
147
 * This function creates a new base object.
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
148
 * 
149
 * 
150
 * 
5.2.9 by Gustav Hartvigsson
* Added license to files
151
 * @return a new SObject
1 by Gustav Hartvigsson
Initial Code.
152
 */
5.2.9 by Gustav Hartvigsson
* Added license to files
153
SObject * s_object_new ();
1 by Gustav Hartvigsson
Initial Code.
154
155
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
156
 * This function desensitizes/frees an object even if it is still referenced.
5.2.9 by Gustav Hartvigsson
* Added license to files
157
 * This is usually a bad idea, use s_object_unref () instead.
1 by Gustav Hartvigsson
Initial Code.
158
 */
5.2.9 by Gustav Hartvigsson
* Added license to files
159
void s_object_free (SObject * self);
1 by Gustav Hartvigsson
Initial Code.
160
161
/**
162
 * This function gets the class (which hold the object methods).
163
 */
5.2.9 by Gustav Hartvigsson
* Added license to files
164
void * s_object_get_class (SObject * self);
1 by Gustav Hartvigsson
Initial Code.
165
166
/**
167
 * This function sets the instance class of an object.
168
 */
5.2.9 by Gustav Hartvigsson
* Added license to files
169
void s_object_set_class (SObject * self, SObjectClass * klass);
1 by Gustav Hartvigsson
Initial Code.
170
171
/**
172
 * 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.
173
 * When an object reaches zero, it will deinitialize the object using the
174
 * objects deinitialize method.
1 by Gustav Hartvigsson
Initial Code.
175
 * 
176
 * It returns the current (after change) reference count.
177
 */
5.2.9 by Gustav Hartvigsson
* Added license to files
178
int s_object_unref (SObject * self);
1 by Gustav Hartvigsson
Initial Code.
179
180
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
181
 * This function is used to increase the reference count of an object.
1 by Gustav Hartvigsson
Initial Code.
182
 *
183
 * Returns the current (after change) reference count.
184
 */
5.2.9 by Gustav Hartvigsson
* Added license to files
185
int s_object_ref (SObject * self);
1 by Gustav Hartvigsson
Initial Code.
186
187
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
188
 * This function returns the current reference count without changing it.
1 by Gustav Hartvigsson
Initial Code.
189
 */
5.2.9 by Gustav Hartvigsson
* Added license to files
190
int s_object_get_refcount (SObject * self);
1 by Gustav Hartvigsson
Initial Code.
191
192
/**
5.1.1 by Gustav Hartvigsson
* Started work on making the code more prasable by DoxyGen.
193
 * This function returns a textual (string) that represents the object.
5.2.9 by Gustav Hartvigsson
* Added license to files
194
 * The method can be set using s_object_set_to_string_method.
1 by Gustav Hartvigsson
Initial Code.
195
 *
196
 * Note: The string that is returned must be freed.
197
 */
5.2.9 by Gustav Hartvigsson
* Added license to files
198
char * s_object_to_string (SObject * self);
1 by Gustav Hartvigsson
Initial Code.
199
22 by Gustav Hartvigsson
* Made code compile
200
END_DECLS
1 by Gustav Hartvigsson
Initial Code.
201
202
#endif