2 Copyright © 1997-98, The AROS Development Team. All rights reserved.
5 Desc: Demo of new OOP system
17 #include "sysdep/hashed_methods.h"
19 static struct Bucket
*CopyBucket(struct Bucket
*old_b
);
20 static VOID
FreeBucket(struct Bucket
*b
);
22 /**********************
24 **********************/
26 static ULONG
NumNewMethods(Class
*cl
, struct InterfaceDescr
*ifDescr
)
29 ULONG numnewmethods
= 0;
33 ht
= (struct Bucket
**)cl
->SuperClass
->HashTable
;
34 for (; ifDescr
->MethodTable
; ifDescr
++)
38 for (i
= 0; i
< ifDescr
->NumMethods
; i
++)
41 mid
= (ifDescr
->InterfaceID
<< NUM_METHOD_BITS
) + i
;
43 if (!HashLookupULONG(ht
, mid
))
55 /* This is rootclass, count the methods */
56 ht
= (struct Bucket
**)cl
->HashTable
;
57 for (; ifDescr
->MethodTable
; ifDescr
++)
59 numnewmethods
+= ifDescr
->NumMethods
;
62 return (numnewmethods
);
65 /***************************
66 ** AllocDispatchTales() **
67 ***************************/
69 BOOL
AllocDispatchTables(Class
*cl
, struct InterfaceDescr
*ifDescr
)
73 entries
= NumNewMethods(cl
, ifDescr
);
75 cl
->HashTable
= (struct MethodBucket
**)NewHash(entries
);
78 /* Save hashtable mask for speed */
79 cl
->HashMask
= HashMask(cl
->HashTable
);
83 /* Copy the superclass hash table */
84 if ( !CopyHash((struct Bucket
**)cl
->HashTable
85 ,(struct Bucket
**)cl
->SuperClass
->HashTable
93 /* Insert our own methods */
94 for (; ifDescr
->MethodTable
; ifDescr
++)
96 IPTR (**mtab
)() = ifDescr
->MethodTable
;
99 for (i
= 0; i
< ifDescr
->NumMethods
; i
++)
101 struct MethodBucket
*b
;
104 mid
= (ifDescr
->InterfaceID
<< NUM_METHOD_BITS
) + i
;
107 /* Method existed in superclass ? */
108 b
= (struct MethodBucket
*)HashLookupULONG((struct Bucket
**)cl
->HashTable
, mid
);
111 b
->MethodFunc
= mtab
[i
];
116 /* Must allocate new bucket */
117 struct MethodBucket
*new_b
;
118 new_b
= (struct MethodBucket
*)malloc( sizeof (struct MethodBucket
) );
123 /* Initialize bucket */
124 new_b
->MethodID
= mid
;
125 new_b
->MethodFunc
= mtab
[i
];
128 /* Add bucket to hashtable */
129 InsertBucket((struct Bucket
**)cl
->HashTable
, (struct Bucket
*)new_b
);
132 } /* for (each method in methodtable) */
134 } /* for (each interface) */
137 ReturnBool ("AllocDispatchTables", TRUE
);
139 FreeHash((struct Bucket
**)cl
->HashTable
, FreeBucket
);
140 ReturnBool ("AllocDispatchTables", FALSE
);
144 VOID
FreeDispatchTables(Class
*cl
)
146 FreeHash((struct Bucket
**)cl
->HashTable
, FreeBucket
);
152 /**************************
153 ** Hash handling hooks **
154 **************************/
155 #define MB(x) ((struct MethodBucket *)x)
156 static struct Bucket
*CopyBucket(struct Bucket
*old_b
)
158 struct MethodBucket
*new_b
;
160 new_b
= (struct MethodBucket
*)malloc(sizeof (struct MethodBucket
) );
163 new_b
->MethodID
= MB(old_b
)->MethodID
;
164 new_b
->MethodFunc
= MB(old_b
)->MethodFunc
;
165 new_b
->mClass
= MB(old_b
)->mClass
;
166 return ((struct Bucket
*)new_b
);
171 static VOID
FreeBucket(struct Bucket
*b
)