#include <assert.h>
#include <stdlib.h>
#include <stdio.h>

#include "Object.h"
#include "utils.h"


/* The standard to_string method */
char * _object_standard_to_string (Object * object) {
  return string_new_printf ("(Object:%s)", object->name);
}

void object_initialize (Object * object,
                        char * name,
                        _pointer klass) {
  object->name = name;
  object->klass = klass;
  
  object->reserved0 = NULL;
  object->reserved1 = NULL;
}

void object_class_initialize (ObjectClass * klass,
                              NewFunc new_func,
                              FreeFunc free_func,
                              ToStringFunc to_string_func) {
  assert (new_func != NULL);
  assert (free_func != NULL);
  
  if (to_string_func != NULL) {
    klass->to_string_func = to_string_func;
  } else {
    klass->to_string_func = _object_standard_to_string;
  }
  
  klass->new_func = new_func;
  klass->free_func = free_func;
}

void object_add_private (Object * object, _pointer priv_data) {
  object->priv = priv_data;
}

Object * object_new_from_object (Object * self) {
  return (Object *) self->klass->new_func (self);
}

char * object_to_string (Object * self) {
  return self->klass->to_string_func (self);
}
