15
15
* @defgroup SMatrix SMatrix
16
16
* @addtogroup SMatrix
18
* A SMatrix is a 2d, square array.
20
typedef struct _SMatrix SMatrix;
18
* A SMatrix is a 2d, rectangular array.
21
* An SMatrix is an opaque data structure representing a simple rectangular
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.
28
typedef struct SMatrix SMatrix;
31
* convenience structure to store type into and name of a tuple.
38
MY_TUPLE_ENUM_END_OF_TUPLE
41
const SMatrixRowInformation my_row_info[] = {
42
{"Name", S_TYPE_STRING},
44
{"Height", S_TYPE_UINT}
48
* The information can then be used like this:
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]);
61
typedef struct SMatrixRowInformation {
62
char * name; /**< Name of the row. */
63
SType type; /**< Type of the row. */
64
} SMatrixRowInformation;
24
67
s_matrix_new (size_t width, size_t height);
30
73
* Reallocate a SMatrix from one tuple width to an other.
32
* @note The new tuple size must be larger then the last, or it will be
75
* @warning The new tuple size must be larger then the last, or it will be
76
* turnicated, but not freed.
35
* @note You need to free the old SMatrix yourself, this is to avoid memory
78
* @note You need to free the old SMatrix yourself
79
* <em>(but not the data stored)</em>, this is to avoid memory leaks.
39
82
s_matrix_realloc (SMatrix * self, size_t width);
47
90
s_matrix_get (SMatrix * self, size_t x, size_t y);
93
* Returns the number representing the last tuple.
94
* IE: it the last tuple has the x position of 10, this will return 10.
96
* @param self The SMatrix to get the x coordinate of the last tuple.
98
* @return The x coordinate of the last tuple.
100
* @note The value way be wrong.
103
s_matrix_get_last_tuple_n (SMatrix self);
106
* @brief Set data at a point [x,y] in the array.
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.
50
116
s_matrix_set (SMatrix * self, size_t x, size_t y, spointer data);
119
* Gets tuple x in SMatrix self.
121
* @param self the matrix to perform the operation on.
122
* @param x the tuple to get.
124
* @return a pointer to an array congaing painters to the data in the tuple.
126
* @see s_matrix_get_tuple_as_dynamic_array()
53
s_matrix_get_tupel (SMatrix * self, size_t x);
129
s_matrix_get_tuple (SMatrix * self, size_t x);
132
* Append a tuple to a SMatrix.
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.
137
* @note This function will consume (free) allocated data for the tuple.
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.
56
s_matrix_append (SMatrix * self, spointer data);
144
s_matrix_append (SMatrix * self, spointer tuple);
147
* Get tuple x as a SDynamicArray.
149
* @param self the SMatrix to perform the operation on.
150
* @param x the tuple to get.
152
* @return An SDynamicArray containing pointers to the data in the tuple.
154
* @see s_matrix_get_tuple
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);
62
160
* This iterates over each tuple. giving the tuple as the item in the