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