/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
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
63
64
65
66
67
68
69
#include "Map.h"
#include "baseobject.h"
#include <stdlib.h>


struct _SMapPrivate {
  size_t len; // Length
  SMapItem * items[]; // Use calloc to deal with memory.
};

void method_map_deinit (SMap * Self);

SMapItem * s_map_item_new (void * key, void * value) {
  SMapItem * self = malloc (sizeof (SMapItem));
  self->key = key;
  self->value = value;
}

void s_map_item_free (SMapItem * self) {
  /* FIXME TODO:
   * Need to figure a method to determin if objects (keys and values) are
   * BaseObjectInstance children or not and use the appropriate method for
   * freeing.
   */
  free (self);
}

SMap * s_map_new ( CompFunc comp_func ) {
  SMap * self = malloc (sizeof (SMap));
  SMapClass * klass = malloc (sizeof (SMapClass));
  
  s_base_object_set_class ((SBaseObjectInstance *) self, klass);
  
  s_base_object_set_deinit_method ((SBaseObjectInstance *) self, method_map_deinit);
  
  self->priv = malloc (sizeof (SMapPrivate));
  
  self->priv->len = 0;
  
  klass->is_equal = comp_func;
  
  return self;
}

void s_map_free (SMap * self) {
  //TODO
}


void s_map_add (SMap * self ,void * key, void * value) {
  SMapItem ** items = self->priv->items;
  SMapItem * item = s_map_item_new (key, value);
  if (self->priv->len == 0) {
    
    items = realloc (items, sizeof(SMapItem));
    items[0] = item;
    self->priv->len++;
  } else {
    //TODO
  }
}

void * s_map_get (SMap * self, void * key) {
  
}

void method_map_deinit (SMap * self) {
  
}