summaryrefslogtreecommitdiff
path: root/modules/graphics/includes/sciMatrix.h
blob: fde02beab23ba1704ab58e09f87b659f746426ff (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) 2006 - INRIA - Jean-Baptiste Silvy
 *
 * This file must be used under the terms of the CeCILL.
 * This source file is licensed as described in the file COPYING, which
 * you should have received as part of this distribution.  The terms
 * are also available at
 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 *
 */

/*----------------------------------------------------------------------------------*/
/* File    : sciMatrix.h                                                                     */
/* Desc.   : Allocation and deletion and modifications of matrices of pointers               */
/*           The matrix is stored by colmuns like in Scilab.                                 */
/*           These matrices can be used as generic matrices since they used void * pointers  */
/*----------------------------------------------------------------------------------*/

#ifndef _SCI_MATRIX_H_
#define _SCI_MATRIX_H_

#include "dynlib_graphics.h"

/*----------------------------------------------------------------------------------*/
/**
 * a matrix on void pointers
 */
typedef struct
{
    void ** data ; /**< the data are stored in an array of void pointers */
    int nbCol   ;
    int nbRow   ;
}
sciMatrix;

/*----------------------------------------------------------------------------------*/
/* Constructors */
/*@{*/
/**
 * allocate a matrix with no elements (nbrow = nbcol = 0)
 */
GRAPHICS_IMPEXP sciMatrix * emptyMatrix(void);

/**
 * create a nbRow x nbCol matrix of NULL pointers.
 */
GRAPHICS_IMPEXP sciMatrix * newMatrix(int nbRow, int nbCol);

/**
 * create a nbRow x nbCol matrix which data are dataMat (directly, no copy).
 */
GRAPHICS_IMPEXP sciMatrix * newCompleteMatrix(void ** dataMat, int nbRow, int nbCol);
/*@}*/
/* note that we cannot use a copy constructor since we don't know how to copy two elements */
/* of the matrix! Maybe it is possible with some function pointers, but it seems a bit */
/* tricky for me. For something clean, C++ may be better. */
/*----------------------------------------------------------------------------------*/
/* destructor */
/*@{*/
/**
 * delete the structure and data
 */
GRAPHICS_IMPEXP void deleteMatrix(sciMatrix * mat);

/**
 * delete only the structure, not the data (use with caution).
 */
GRAPHICS_IMPEXP void desallocateMatrix(sciMatrix * mat);
/*@}*/
/*----------------------------------------------------------------------------------*/
/* accessors */
/*@{*/
/**
 * retrieve the element (row,col) of the matrix.
 */
GRAPHICS_IMPEXP void * getMatElement(const sciMatrix * mat, int row, int col);

GRAPHICS_IMPEXP int     getMatNbRow(const sciMatrix * mat);

GRAPHICS_IMPEXP int     getMatNbCol(const sciMatrix * mat);

/**
 * get the pointer on the array of data. May be used for faster access to the data.
 */
GRAPHICS_IMPEXP void ** getMatData( const sciMatrix * mat);

/**
 * set an element of the matrix to a new value but does not desalocate the previous
 * if one exists.
 * @param newValue the new value which will be inserted directly in the matrix (no copy).
 */
GRAPHICS_IMPEXP void setMatElement(   sciMatrix * mat, int row, int col, void * newValue);

/**
 * desalocate the (row,col) element and put a new one.
 * @param newValue the new value which will be inserted directly in the matrix (no copy).
 */
GRAPHICS_IMPEXP void changeMatElement(sciMatrix * mat, int row, int col, void * newValue);

/**
 * desalocate the (row,col) current element (i,j) and copy the new one. The size of the element
 * must be given in order to allocate memory.
 * @param copyValue copied value.
 * @param valueSize size of the data inserted in the matrix (ex: sizeof(double)).
 */
GRAPHICS_IMPEXP void copyMatElement(      sciMatrix * mat      ,
        int             row      ,
        int             col      ,
        const void          * copyValue,
        int             valueSize);
/*@}*/
/*----------------------------------------------------------------------------------*/

#endif /* _SCI_MATRIX_H_ */