/+junk/c_sdl_joypad_ducktape

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/c_sdl_joypad_ducktape
27 by Gustav Hartvigsson
* Started working on the an object baseclass to make things
1
#ifndef __H_OBJECT__
2
#define __H_OBJECT__
3
4
#include "defs.h"
5
6
/** @file
7
 * Object is the base object for many of the objects that are used in the game.
8
 * It has some primitives that make it easy to use with the EcmaScript
9
 * interpretor.
10
 *
11
 * It is also the base for the GameObject class.
12
 *
13
 * @warning Note that there is no type-checking. So be careful when using this.
14
 *          You will have to keep track of what objects inherent from which
15
 *          object. Also note that there is no consent of interfaces.
16
 */
17
18
BEGIN_DECLS
19
28 by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class".
20
21
#ifndef DOXYGEN_SHOULD_SKIP_THIS
22
typedef struct Object Object;
23
typedef struct ObjectClass ObjectClass;
24
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
25
27 by Gustav Hartvigsson
* Started working on the an object baseclass to make things
26
/**
29 by Gustav Hartvigsson
* Fixed Makefile
27
 * Is the primitive for the the <tt>ObjectClass::to_string_func</tt> method in
28
 * the <tt>ObjectClass</tt>.
27 by Gustav Hartvigsson
* Started working on the an object baseclass to make things
29
 */
30
typedef char * (* ToStringFunc)(Object * object);
31
32
/**
29 by Gustav Hartvigsson
* Fixed Makefile
33
 * This is the primitive for the <tt>ObjectClass::new_func</tt> method.
27 by Gustav Hartvigsson
* Started working on the an object baseclass to make things
34
 */
29 by Gustav Hartvigsson
* Fixed Makefile
35
typedef char * (* NewFunc)(Object * object, ...);
27 by Gustav Hartvigsson
* Started working on the an object baseclass to make things
36
37
/**
38
 * The class for the Object, it is what holds the methods for the object.
39
 */
40
typedef struct ObjectClass {
41
  NewFunc new_func;
42
  FreeFunc free_func;
28 by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class".
43
  ToStringFunc to_string_func;
27 by Gustav Hartvigsson
* Started working on the an object baseclass to make things
44
} ObjectClass;
45
46
typedef struct Object {
47
  ObjectClass * klass;
48
  char * name;
49
  
50
  /* Some reserved space in the Object instance, for good measure. These should
51
   * be NULL
52
   */
53
  _pointer reserved0;
54
  _pointer reserved1;
55
  
56
  _pointer priv;
57
} Object;
58
59
60
/**
29 by Gustav Hartvigsson
* Fixed Makefile
61
 * Initialises the Object to a sane values.
27 by Gustav Hartvigsson
* Started working on the an object baseclass to make things
62
 * 
63
 * @warning This does NOT allocate any memory for the instance.
64
 * 
65
 * @param object The object to initialise.
66
 * 
67
 * @param name The name of the object instance, this should be the same as the
68
 *             "class" name. IE: If the instance is of the type "Foo", then the
69
 *             name should be the same.
70
 * 
71
 * @param klass The class instance to be added to the object instance.
72
 */
73
void object_initialize (Object * object,
74
                        char * name,
75
                        _pointer klass);
76
29 by Gustav Hartvigsson
* Fixed Makefile
77
/**
78
 * Initialises a ObjectClass with methods.
79
 *
80
 * @warning This does NOT allocate any memory for the ObjectClass.
81
 *
82
 * @param klass The ObjectClass to initialise.
83
 * 
84
 * @param new_func The method that is used when creating a new instance of
85
 *                 the object that the class belongs to.
86
 *
87
 * @param to_string_func The method to be used when calling
88
 *        <tt>object_to_string ()</tt> on the object.
89
 */
28 by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class".
90
void object_class_initialize (ObjectClass * klass,
91
                              NewFunc new_func,
92
                              FreeFunc free_func,
29 by Gustav Hartvigsson
* Fixed Makefile
93
                              ToStringFunc to_string_func);
27 by Gustav Hartvigsson
* Started working on the an object baseclass to make things
94
29 by Gustav Hartvigsson
* Fixed Makefile
95
/**
96
 * Add a private data structure ta a Object.
97
 *
98
 * @param object the object to add the private data to.
99
 * @param priv_data the data structure to add to the object.
100
 */
101
void object_add_private (Object * object, _pointer priv_data);
27 by Gustav Hartvigsson
* Started working on the an object baseclass to make things
102
103
/**
104
 * Create a new object of the same type as the one that this is executed on.
105
 *
106
 * This is does not copy the data in the object, it only crates a new instance
107
 * of the object. This is generally not helpful.
108
 */
28 by Gustav Hartvigsson
* Starded working on making GameObject compile with the new "base class".
109
Object * object_new_from_object (Object * self);
27 by Gustav Hartvigsson
* Started working on the an object baseclass to make things
110
111
/**
112
 * Creates a null-terminated string that can be used with in different ways, be
113
 * it for debugging or other purposes.
114
 */
115
char * object_to_string (Object * object);
116
117
/**
118
 * Frees an object.
119
 * 
120
 * This will call an objects free method.
121
 *
122
 * @warning This will only work on objects that inherent from the Object. It
123
 *          may or will cause undefined behaviour when used with object that do
124
 *          not inherent from Object.
125
 */
126
void object_free (Object * object);
127
128
END_DECLS
129
130
#endif /* __H_OBJECT__ */