Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d5b67a6eb6e99be3f16c91dc64eb850591aa9886
[simgrid.git] / include / xbt / matrix.h
1 /* $Id$ */
2
3 /* xbt_matrix_t management functions                                        */
4
5 /* Copyright (c) 2006 Martin Quinson. All rights reserved.                  */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 #ifndef XBT_MATRIX_H
11 #define XBT_MATRIX_H
12
13 #include "xbt/misc.h"
14 #include "xbt/function_types.h"
15
16 SG_BEGIN_DECL()
17
18 typedef struct {
19   unsigned int lines, rows;
20   unsigned long elmsize;
21
22   char *data;
23   void_f_pvoid_t *free_f;
24 } s_xbt_matrix_t, *xbt_matrix_t;
25
26
27   /** @brief Retrieve the address of a cell (not its content)
28    *  @hideinitializer */
29 #define xbt_matrix_get_ptr(mat,l,c) \
30   ((void*)&(mat)->data[(c)*(mat)->lines*(mat)->elmsize + (l)*(mat)->elmsize])
31
32   /** @brief Quick retrieval of scalar content
33    *  @hideinitializer */
34 #define xbt_matrix_get_as(mat,l,c,type) *(type*)xbt_matrix_getp(mat,l,c) 
35
36 xbt_matrix_t xbt_matrix_new(int lines, int rows, 
37                             const unsigned long elmsize,
38                             void_f_pvoid_t * const free_f);
39 void xbt_matrix_free(xbt_matrix_t matrix);
40 void xbt_matrix_free_voidp(void *d);
41
42 void xbt_matrix_dump(xbt_matrix_t matrix, const char *name,
43                      void_f_pvoid_t display_fun);
44
45 SG_END_DECL()
46
47
48 #endif /* XBT_MATRIX_H */