void Node_X10_init(void) { /* MUST be called before any light is created */ // Insert the lines below for any derived subclasses //if (!Node_X10) {Node_X10_init();} //if (!NodeClass_X10) {Node_X10_init();} if (!Node) {Node_init();} if (!NodeClass) {Node_init();} if (! NodeClass_X10) { NodeClass_X10 = new(Class, // should be "Class" "NodeClass_X10", // should be "SomethingClass" Class, // should be "Class" sizeof(struct NodeClass_X10), // size of self ctor, NodeClass_X10_ctor, //SomethingClass_ctor 0); // Terminator }
/*Add a value to the start of the list*/ void List_add_to_first(List *l, void * data) { Node *n = Node_init(l->node_size, data); n->next = l->first; /*if we dont have anything in the list*/ if (l->first != NULL) { ((Node*)l->first)->previous = n; } l->first = n; if (l->last == NULL) { l->last = n; } ++l->length; }
/*Add a value to the end of the list*/ void List_add_to_last(List * l, void * data) { Node *n = Node_init(l->node_size, data); /*if there is a node in the end*/ if (l->last != NULL) { ((Node*)l->last)->next = n; n->previous = l->last; } l->last = n; if (l->first == NULL) { l->first = n; } ++l->length; }
/*Create a new list , if data = NULL there will be no node in the list */ List * List_create(size_t data_size, void *data) { List * l = malloc(sizeof(List)); l->first = NULL; l->last = NULL; l->length = 0; l->node_size = data_size + (sizeof(void*) * 2); /*you have to state the data size , otherwise i dont know how much to allocate*/ if (data_size == NULL) { return NULL; } if (data != NULL) { Node * n = Node_init(data_size, data); l->first = n; l->last = n; l->length = 1; } return l; }