2003-12-22 19:29:21 +03:00
|
|
|
/*
|
2004-01-07 10:57:00 +03:00
|
|
|
* $HEADER$
|
2003-12-22 19:29:21 +03:00
|
|
|
*/
|
2004-01-07 10:57:00 +03:00
|
|
|
|
2004-02-10 17:04:27 +03:00
|
|
|
/**
|
2004-02-13 00:30:06 +03:00
|
|
|
* @file
|
|
|
|
*
|
|
|
|
* Implementation of lam_object_t, the base lam foundation class
|
2004-02-10 17:04:27 +03:00
|
|
|
*/
|
2003-12-22 19:29:21 +03:00
|
|
|
|
2004-02-13 00:30:06 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2004-03-17 21:45:16 +03:00
|
|
|
#include "constants.h"
|
|
|
|
#include "lfc/lam_object.h"
|
2003-12-22 19:29:21 +03:00
|
|
|
|
2004-02-13 00:30:06 +03:00
|
|
|
/*
|
|
|
|
* Instantiation of class descriptor for the base class. This is
|
|
|
|
* special, since be mark it as already initialized, with no parent
|
|
|
|
* and no constructor or desctructor
|
|
|
|
*/
|
2004-02-13 01:42:39 +03:00
|
|
|
lam_class_t lam_object_t_class = {
|
2004-02-13 00:30:06 +03:00
|
|
|
"lam_object_t", /* name */
|
|
|
|
NULL, /* parent class */
|
|
|
|
NULL, /* constructor */
|
|
|
|
NULL, /* destructor */
|
|
|
|
1, /* initialized -- this class is preinitialized */
|
|
|
|
0, /* class hierarchy depth */
|
|
|
|
NULL, /* array of constructors */
|
|
|
|
NULL /* array of destructors */
|
|
|
|
};
|
2003-12-22 19:29:21 +03:00
|
|
|
|
2004-02-10 17:04:27 +03:00
|
|
|
|
2004-02-13 00:30:06 +03:00
|
|
|
/*
|
|
|
|
* Lazy initialization of class descriptor.
|
|
|
|
*/
|
2004-02-13 01:42:39 +03:00
|
|
|
void lam_class_initialize(lam_class_t *class)
|
2003-12-22 19:29:21 +03:00
|
|
|
{
|
2004-02-13 01:42:39 +03:00
|
|
|
lam_class_t *c;
|
2004-02-13 00:30:06 +03:00
|
|
|
int i;
|
2003-12-22 19:29:21 +03:00
|
|
|
|
2004-02-13 00:30:06 +03:00
|
|
|
assert(class);
|
|
|
|
assert(0 == class->cls_initialized);
|
2004-02-10 17:04:27 +03:00
|
|
|
|
2004-02-13 00:30:06 +03:00
|
|
|
/*
|
|
|
|
* First calculate depth of class hierarchy
|
|
|
|
*/
|
|
|
|
|
|
|
|
class->cls_depth = 0;
|
|
|
|
for (c = class; c; c = c->cls_parent) {
|
|
|
|
class->cls_depth += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate arrays for hierarchy of constructors and destructors
|
|
|
|
*/
|
2004-02-10 17:04:27 +03:00
|
|
|
|
2004-02-13 00:30:06 +03:00
|
|
|
class->cls_construct_array = malloc(class->cls_depth *
|
|
|
|
sizeof(lam_construct_t));
|
|
|
|
if (NULL == class->cls_construct_array) {
|
|
|
|
perror("Out of memory");
|
|
|
|
}
|
2004-02-10 17:04:27 +03:00
|
|
|
|
2004-02-13 00:30:06 +03:00
|
|
|
class->cls_destruct_array = malloc(class->cls_depth *
|
|
|
|
sizeof(lam_destruct_t));
|
|
|
|
if (NULL == class->cls_destruct_array) {
|
|
|
|
perror("Out of memory");
|
|
|
|
}
|
|
|
|
|
|
|
|
c = class;
|
|
|
|
for (i = 0; i < class->cls_depth; i++) {
|
|
|
|
class->cls_construct_array[i] = c->cls_construct;
|
|
|
|
class->cls_destruct_array[i] = c->cls_destruct;
|
|
|
|
c = c->cls_parent;
|
|
|
|
}
|
2004-02-10 17:04:27 +03:00
|
|
|
|
2004-02-13 00:30:06 +03:00
|
|
|
class->cls_initialized = 1;
|
|
|
|
}
|