-
Notifications
You must be signed in to change notification settings - Fork 3
/
classinfo.cxx
62 lines (52 loc) · 1.89 KB
/
classinfo.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//-< CLASSINFO.CXX >-------------------------------------------------*--------*
// POST++ Version 1.0 (c) 1998 GARRET * ? *
// (Persistent Object Storage) * /\| *
// * / \ *
// Created: 2-Feb-98 K.A. Knizhnik * / [] \ *
// Last update: 2-Feb-98 K.A. Knizhnik * GARRET *
//-------------------------------------------------------------------*--------*
// Implementation of class descriptor methods
//-------------------------------------------------------------------*--------*
#define INSIDE_POST
#include "classinfo.h"
BEGIN_POST_NAMESPACE
const unsigned class_hash_table_size = 117;
class_descriptor* class_descriptor::hash_table[class_hash_table_size];
class_descriptor* class_descriptor::list;
int class_descriptor::count;
inline unsigned string_hash_function(const char* name)
{
unsigned h = 0, g;
while(*name) {
h = (h << 4) + *name++;
if ((g = h & 0xF0000000) != 0) {
h ^= g >> 24;
}
h &= ~g;
}
return h;
}
class_descriptor::class_descriptor(const char* class_name,
size_t class_size,
void (*default_constructor)(object*))
: id(count++), size(class_size)
{
assert(!find_class(class_name));
name = class_name;
constructor = default_constructor;
next = list;
list = this;
unsigned h = string_hash_function(class_name) % class_hash_table_size;
collision_chain = hash_table[h];
hash_table[h] = this;
}
class_descriptor* class_descriptor::find_class(char const* class_name)
{
unsigned h = string_hash_function(class_name) % class_hash_table_size;
class_descriptor* cp;
for (cp = hash_table[h];
cp != NULL && strcmp(cp->name, class_name) != 0;
cp = cp->collision_chain);
return cp;
}
END_POST_NAMESPACE