/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/Matrix.h

  • Committer: Gustav Hartvigsson
  • Date: 2015-08-27 15:01:32 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20150827150132-pwijpi0k2f4f96rg
* Working on SMatrix to finish it off.
* Added (non working?) s_wstiring_to_string () to convert Wide Strings (wchar_t *) to Byte Strings (char *).
* fixed spelling of tuple in Matrix.[h,c]
* added documentation to different parts of the code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 * @defgroup SMatrix SMatrix
16
16
 * @addtogroup SMatrix
17
17
 * @{
18
 
 * A SMatrix is a 2d, square array.
19
 
 */
20
 
typedef struct _SMatrix SMatrix;
21
 
 
 
18
 * A SMatrix is a 2d, rectangular array.
 
19
 */
 
20
/**
 
21
 * An SMatrix is an opaque data structure representing a simple rectangular
 
22
 * matrix.
 
23
 *
 
24
 * An SMatrix Stores pointers to data, and not the data itself.
 
25
 * So when using functions like s_matrix_realloc, it only copies the pointers
 
26
 * over from the old SMatrix to the new.
 
27
 */
 
28
typedef struct SMatrix SMatrix;
 
29
 
 
30
/**
 
31
 * convenience structure to store type into and name of a tuple.
 
32
 * Example:
 
33
 @code{.c}
 
34
typedef enum {
 
35
  MY_TUPLE_ENUM_NAME,
 
36
  MY_TUPLE_ENUM_AGE,
 
37
  MY_TUPLE_ENUM_HEIGHT,
 
38
  MY_TUPLE_ENUM_END_OF_TUPLE
 
39
} MyRowInfoEnum;
 
40
 
 
41
const SMatrixRowInformation my_row_info[] = {
 
42
  {"Name", S_TYPE_STRING},
 
43
  {"Age", S_TYPE_UINT},
 
44
  {"Height", S_TYPE_UINT}
 
45
  {NULL, NULL}
 
46
};
 
47
 @endcode
 
48
 * The information can then be used like this:
 
49
 @code{.c}
 
50
for (int i = 0, i <= s_matrix_get_last_tuple_n (my_matrix), i++) {
 
51
  spointer tmp_tuple = s_matrix_get_tuple (my_matrix, i);
 
52
  for (int j = 0, j <= MY_TUPLE_ENUM_END_OF_TUPLE, j++) {
 
53
    s_print ("%s: %s", my_row_info[j], tmp_tuple[j]);
 
54
  }
 
55
  s_print ("\n");
 
56
  free (tmp_tuple);
 
57
}
 
58
 @endcode
 
59
 *
 
60
 */
 
61
typedef struct SMatrixRowInformation {
 
62
  char *    name; /**< Name of the row. */
 
63
  SType     type; /**< Type of the row. */
 
64
} SMatrixRowInformation;
22
65
 
23
66
SMatrix *
24
67
s_matrix_new (size_t width, size_t height);
29
72
/**
30
73
 * Reallocate a SMatrix from one tuple width to an other.
31
74
 *
32
 
 * @note The new tuple size must be larger then the last, or it will be
33
 
 * turnicated.
 
75
 * @warning The new tuple size must be larger then the last, or it will be
 
76
 * turnicated, but not freed.
34
77
 *
35
 
 * @note You need to free the old SMatrix yourself, this is to avoid memory
36
 
 * leaks.
 
78
 * @note You need to free the old SMatrix yourself
 
79
 * <em>(but not the data stored)</em>, this is to avoid memory leaks.
37
80
 */
38
81
SMatrix *
39
82
s_matrix_realloc (SMatrix * self, size_t width);
46
89
spointer
47
90
s_matrix_get (SMatrix * self, size_t x, size_t y);
48
91
 
 
92
/**
 
93
 * Returns the number representing the last tuple.
 
94
 * IE: it the last tuple has the x position of 10, this will return 10.
 
95
 *
 
96
 * @param self The SMatrix to get the x coordinate of the last tuple.
 
97
 *
 
98
 * @return The x coordinate of the last tuple.
 
99
 *
 
100
 * @note The value way be wrong.
 
101
 */
 
102
size_t
 
103
s_matrix_get_last_tuple_n (SMatrix self);
 
104
 
 
105
/**
 
106
 * @brief Set data at a point [x,y] in the array.
 
107
 *
 
108
 * @param self The SMatrix to operate on.
 
109
 * @param x The x coordinates of where to put the data.
 
110
 *          (What tuple to put it in).
 
111
 * @param y The y coordinates to put the data in.
 
112
 *          (What position in the tuple to put it in).
 
113
 * @param data The data to be placed in the SMatrix.
 
114
 */
49
115
void
50
116
s_matrix_set (SMatrix * self, size_t x, size_t y, spointer data);
51
117
 
 
118
/**
 
119
 * Gets tuple x in SMatrix self.
 
120
 * 
 
121
 * @param self the matrix to perform the operation on.
 
122
 * @param x the tuple to get.
 
123
 *
 
124
 * @return a pointer to an array congaing painters to the data in the tuple.
 
125
 *
 
126
 * @see s_matrix_get_tuple_as_dynamic_array()
 
127
 */
52
128
spointer *
53
 
s_matrix_get_tupel (SMatrix * self, size_t x);
 
129
s_matrix_get_tuple (SMatrix * self, size_t x);
54
130
 
 
131
/**
 
132
 * Append a tuple to a SMatrix.
 
133
 *
 
134
 * @param self The SMatrix to perform the operation on.
 
135
 * @param tuple The <em>allocated</em> data tuple to be copied into the SMatrix.
 
136
 *
 
137
 * @note This function will consume (free) allocated data for the tuple.
 
138
 *
 
139
 * @note The function assumes that the tuple has the same width as specified
 
140
 *       during construction or reallocation. Any dangling pointers will
 
141
 *       <em>not</em> be freed.
 
142
 */
55
143
void
56
 
s_matrix_append (SMatrix * self, spointer data);
 
144
s_matrix_append (SMatrix * self, spointer tuple);
57
145
 
 
146
/**
 
147
 * Get tuple x as a SDynamicArray.
 
148
 *
 
149
 * @param self the SMatrix to perform the operation on.
 
150
 * @param x the tuple to get.
 
151
 *
 
152
 * @return An SDynamicArray containing pointers to the data in the tuple.
 
153
 *
 
154
 * @see s_matrix_get_tuple
 
155
 */
58
156
SDynamicArray *
59
 
s_matrix_get_tupel_as_dynamic_array (SMatrix * self, size_t x);
 
157
s_matrix_get_tuple_as_dynamic_array (SMatrix * self, size_t x);
60
158
 
61
159
/**
62
160
 * This iterates over each tuple. giving the tuple as the item in the