/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk

« back to all changes in this revision

Viewing changes to src/Map.h

  • Committer: Gustav Hartvigsson
  • Date: 2013-09-06 15:05:32 UTC
  • mfrom: (5.2.4 simple_type_system_SMap)
  • Revision ID: gustav.hartvigsson@gmail.com-20130906150532-tudew69vmiljy1t6
* Merged the still unfinished SMap impleementation,
* TODO:
       To build a working SMap the system must determin whether or not an
       object is a child to SBaseObjectInstance or not.

       This is a non-trivial thing to do, and req. a lot of base work:
         A lookup table for objects is needed, with appropriet functions
         and probobly a main-loop.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    (C) Gustav Hartvigsson, 2013.
 
3
    
 
4
    This program is free software: you can redistribute it and/or modify
 
5
    it under the terms of the GNU Lesser General Public License as
 
6
    published by the Free Software Foundation, either version 3 of the
 
7
    License.
 
8
 
 
9
    This program is distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
    GNU General Public License for more details.
 
13
 
 
14
    You should have received a copy of the GNU General Public License
 
15
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
*/
 
17
 
 
18
#ifndef __H_MAP__
 
19
#define __H_MAP__
 
20
 
 
21
/**
 
22
 * An SMap is a data structure that holds many mappings of objects to objects:
 
23
 * say, a string to an other string. This can be likened to the Dict structure
 
24
 * in python, but not fully.
 
25
 * 
 
26
 * An SMap is made up of SMapItems, each MapItem holds two pointers to data.
 
27
 * The first pointer is the key, the secold is the value.
 
28
 *
 
29
 * please note that SMaps can be slow and are unordered.
 
30
 *
 
31
 * @file
 
32
 */
 
33
 
 
34
#include "SimpleTypeSystem.h"
 
35
#include "baseobject.h"
 
36
#include <stdbool.h>
 
37
 
 
38
/** @brief
 
39
 * SMapItem holds the mapping of a key to a value.
 
40
 */
 
41
typedef struct _SMapItem SMapItem;
 
42
 
 
43
/** @brief
 
44
 * An SMap is a map many SMapItems. Mapping between a key and a value.
 
45
 * 
 
46
 * functions:
 
47
 * * \c s_map_new \c ()
 
48
 * * \c s_map_free \c ()
 
49
 * * \c s_map_add \c ()
 
50
 * * \c s_map_get \c ()
 
51
 */
 
52
typedef struct _SMap SMap;
 
53
 
 
54
 
 
55
typedef struct _SMapClass SMapClass;
 
56
 
 
57
 
 
58
typedef struct _SMapPrivate SMapPrivate;
 
59
 
 
60
/**
 
61
 * Data structure representing an SMapItem
 
62
 */
 
63
struct _SMapItem {
 
64
  void * key; /** The Key */
 
65
  void * value; /** The Value */
 
66
};
 
67
 
 
68
/** @brief
 
69
 * Data structure representing an SMap
 
70
 */
 
71
struct _SMap {
 
72
  SBaseObjectInstance parent; /** The parent instance */
 
73
  SMapPrivate * priv; /** Private data pointer */
 
74
};
 
75
 
 
76
struct _SMapClass {
 
77
  SBaseObjectClass parentclass;
 
78
  bool CompFunc is_equal; /** method to check if items are equal. */
 
79
};
 
80
 
 
81
/* -------------------------------
 
82
 * The SMapItem functions.
 
83
 * -------------------------------
 
84
 */
 
85
 
 
86
/** @breif
 
87
 * create a new SMapItem.
 
88
 *
 
89
 * @param key The key to be added to the item.
 
90
 * @param value The value to be added to the item.
 
91
 */
 
92
SMapItem * s_map_item_new (void * key, void * value);
 
93
 
 
94
/** @breif
 
95
 * Frees a SMapItem.
 
96
 * 
 
97
 * @param self the item to be freed.
 
98
 */
 
99
void s_map_item_free (SMapItem * self);
 
100
 
 
101
/* -------------------------------
 
102
 * The SMap functions.
 
103
 * -------------------------------
 
104
 */
 
105
 
 
106
/** @brief
 
107
 * s_map_new creates a new SMap object, it takes a CompFunc as an argument.
 
108
 *
 
109
 * @param comp_func tells the SMap object if the key already exists when
 
110
 * adding key/value pares or when searching after a key when retrieving a value.
 
111
 *
 
112
 * A the @c CompFunc returns true if the first and second parameters are equal,
 
113
 * otherwise false.
 
114
 */
 
115
SMap * s_map_new ( CompFunc comp_func );
 
116
 
 
117
/** @breif
 
118
 * This function frees an instance of an SMap.
 
119
 * 
 
120
 * @param self the object to free.
 
121
 */
 
122
void s_map_free (SMap * self);
 
123
 
 
124
/** @breif
 
125
 * This function adds a key/value pair to an SMap.
 
126
 * 
 
127
 * @param self the SMap to add the key/value pair to.
 
128
 * @param key the key that is used to 
 
129
 */
 
130
void s_map_add (SMap * self ,void * key, void * value);
 
131
 
 
132
/** @breif
 
133
 * Get a value using using a key.
 
134
 * 
 
135
 * @param self the SMap that you want to retrieve a value from.
 
136
 * @param key the key that you use to retrieve the value from the SMap from
 
137
 *            with.
 
138
 */
 
139
void * s_map_get (SMap * self, void * key);
 
140
 
 
141
#endif