/+junk/c_sdl_joypad_ducktape

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/c_sdl_joypad_ducktape

« back to all changes in this revision

Viewing changes to src/Object.h

  • Committer: Gustav Hartvigsson
  • Date: 2014-08-31 18:43:53 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20140831184353-20wfpher7cqzx3at
* Started working on the an object baseclass to make things
   easyer when working with the EcmaScript stuffs.
* Added BEGIN_DEGLS and END_DECELS.
* Fixed up the docs a bit...

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
20
/**
 
21
 * Is the primitive for the the <tt> to_string </tt> method in the
 
22
 * <tt>ObjectClass</tt>.
 
23
 */
 
24
typedef char * (* ToStringFunc)(Object * object);
 
25
 
 
26
/**
 
27
 * This is the primitive for the <tt> new_func </tt> method.
 
28
 */
 
29
typedef char * (* NewFunc)(Object * object);
 
30
 
 
31
/**
 
32
 * The class for the Object, it is what holds the methods for the object.
 
33
 */
 
34
typedef struct ObjectClass {
 
35
  NewFunc new_func;
 
36
  FreeFunc free_func;
 
37
  ToStringFunc to_string;
 
38
} ObjectClass;
 
39
 
 
40
typedef struct Object {
 
41
  ObjectClass * klass;
 
42
  char * name;
 
43
  
 
44
  /* Some reserved space in the Object instance, for good measure. These should
 
45
   * be NULL
 
46
   */
 
47
  _pointer reserved0;
 
48
  _pointer reserved1;
 
49
  
 
50
  _pointer priv;
 
51
} Object;
 
52
 
 
53
 
 
54
/**
 
55
 * Initialises the object to a sane values.
 
56
 * 
 
57
 * @warning This does NOT allocate any memory for the instance.
 
58
 * 
 
59
 * @param object The object to initialise.
 
60
 * 
 
61
 * @param name The name of the object instance, this should be the same as the
 
62
 *             "class" name. IE: If the instance is of the type "Foo", then the
 
63
 *             name should be the same.
 
64
 * 
 
65
 * @param klass The class instance to be added to the object instance.
 
66
 */
 
67
void object_initialize (Object * object,
 
68
                        char * name,
 
69
                        _pointer klass);
 
70
 
 
71
 
 
72
void object_class_initialize (ObjectClass * klass, )
 
73
 
 
74
 
 
75
/**
 
76
 * Create a new object of the same type as the one that this is executed on.
 
77
 *
 
78
 * This is does not copy the data in the object, it only crates a new instance
 
79
 * of the object. This is generally not helpful.
 
80
 */
 
81
Object * object_new_from_object (object * self);
 
82
 
 
83
/**
 
84
 * Creates a null-terminated string that can be used with in different ways, be
 
85
 * it for debugging or other purposes.
 
86
 */
 
87
char * object_to_string (Object * object);
 
88
 
 
89
/**
 
90
 * Frees an object.
 
91
 * 
 
92
 * This will call an objects free method.
 
93
 *
 
94
 * @warning This will only work on objects that inherent from the Object. It
 
95
 *          may or will cause undefined behaviour when used with object that do
 
96
 *          not inherent from Object.
 
97
 */
 
98
void object_free (Object * object);
 
99
 
 
100
END_DECLS
 
101
 
 
102
#endif /* __H_OBJECT__ */