5
5
6
6
namespace RDotNet
7
7
{
8
- /// <summary>
9
- /// A matrix of strings.
10
- /// </summary>
11
- [ SecurityPermission ( SecurityAction . Demand , Flags = SecurityPermissionFlag . UnmanagedCode ) ]
12
- public class CharacterMatrix : Matrix < string >
13
- {
14
- /// <summary>
15
- /// Creates a new empty CharacterMatrix with the specified size.
16
- /// </summary>
17
- /// <param name="engine">The <see cref="REngine"/> handling this instance.</param>
18
- /// <param name="rowCount">The row size.</param>
19
- /// <param name="columnCount">The column size.</param>
20
- /// <seealso cref="REngineExtension.CreateCharacterMatrix(REngine, int, int)"/>
21
- public CharacterMatrix ( REngine engine , int rowCount , int columnCount )
22
- : base ( engine , SymbolicExpressionType . CharacterVector , rowCount , columnCount )
23
- { }
8
+ /// <summary>
9
+ /// A matrix of strings.
10
+ /// </summary>
11
+ [ SecurityPermission ( SecurityAction . Demand , Flags = SecurityPermissionFlag . UnmanagedCode ) ]
12
+ public class CharacterMatrix : Matrix < string >
13
+ {
14
+ /// <summary>
15
+ /// Creates a new empty CharacterMatrix with the specified size.
16
+ /// </summary>
17
+ /// <param name="engine">The <see cref="REngine"/> handling this instance.</param>
18
+ /// <param name="rowCount">The row size.</param>
19
+ /// <param name="columnCount">The column size.</param>
20
+ /// <seealso cref="REngineExtension.CreateCharacterMatrix(REngine, int, int)"/>
21
+ public CharacterMatrix ( REngine engine , int rowCount , int columnCount )
22
+ : base ( engine , SymbolicExpressionType . CharacterVector , rowCount , columnCount )
23
+ { }
24
24
25
- /// <summary>
26
- /// Creates a new CharacterMatrix with the specified values.
27
- /// </summary>
28
- /// <param name="engine">The <see cref="REngine"/> handling this instance.</param>
29
- /// <param name="matrix">The values.</param>
30
- /// <seealso cref="REngineExtension.CreateCharacterMatrix(REngine, string[,])"/>
31
- public CharacterMatrix ( REngine engine , string [ , ] matrix )
32
- : base ( engine , SymbolicExpressionType . CharacterVector , matrix )
33
- { }
25
+ /// <summary>
26
+ /// Creates a new CharacterMatrix with the specified values.
27
+ /// </summary>
28
+ /// <param name="engine">The <see cref="REngine"/> handling this instance.</param>
29
+ /// <param name="matrix">The values.</param>
30
+ /// <seealso cref="REngineExtension.CreateCharacterMatrix(REngine, string[,])"/>
31
+ public CharacterMatrix ( REngine engine , string [ , ] matrix )
32
+ : base ( engine , SymbolicExpressionType . CharacterVector , matrix )
33
+ { }
34
34
35
- /// <summary>
36
- /// Creates a new instance for a string matrix.
37
- /// </summary>
38
- /// <param name="engine">The <see cref="REngine"/> handling this instance.</param>
39
- /// <param name="coerced">The pointer to a string matrix.</param>
40
- protected internal CharacterMatrix ( REngine engine , IntPtr coerced )
41
- : base ( engine , coerced )
42
- { }
35
+ /// <summary>
36
+ /// Creates a new instance for a string matrix.
37
+ /// </summary>
38
+ /// <param name="engine">The <see cref="REngine"/> handling this instance.</param>
39
+ /// <param name="coerced">The pointer to a string matrix.</param>
40
+ protected internal CharacterMatrix ( REngine engine , IntPtr coerced )
41
+ : base ( engine , coerced )
42
+ { }
43
43
44
- /// <summary>
45
- /// Gets or sets the element at the specified index.
46
- /// </summary>
47
- /// <param name="rowIndex">The zero-based rowIndex index of the element to get or set.</param>
48
- /// <param name="columnIndex">The zero-based columnIndex index of the element to get or set.</param>
49
- /// <returns>The element at the specified index.</returns>
50
- public override string this [ int rowIndex , int columnIndex ]
51
- {
52
- get
53
- {
54
- if ( rowIndex < 0 || RowCount <= rowIndex )
44
+ /// <summary>
45
+ /// Gets or sets the element at the specified index.
46
+ /// </summary>
47
+ /// <param name="rowIndex">The zero-based rowIndex index of the element to get or set.</param>
48
+ /// <param name="columnIndex">The zero-based columnIndex index of the element to get or set.</param>
49
+ /// <returns>The element at the specified index.</returns>
50
+ public override string this [ int rowIndex , int columnIndex ]
51
+ {
52
+ get
55
53
{
56
- throw new ArgumentOutOfRangeException ( "rowIndex" ) ;
54
+ if ( rowIndex < 0 || RowCount <= rowIndex )
55
+ {
56
+ throw new ArgumentOutOfRangeException ( "rowIndex" ) ;
57
+ }
58
+ if ( columnIndex < 0 || ColumnCount <= columnIndex )
59
+ {
60
+ throw new ArgumentOutOfRangeException ( "columnIndex" ) ;
61
+ }
62
+ using ( new ProtectedPointer ( this ) )
63
+ {
64
+ int offset = GetOffset ( rowIndex , columnIndex ) ;
65
+ IntPtr pointer = Marshal . ReadIntPtr ( DataPointer , offset ) ;
66
+ return new InternalString ( Engine , pointer ) ;
67
+ }
57
68
}
58
- if ( columnIndex < 0 || ColumnCount <= columnIndex )
69
+ set
59
70
{
60
- throw new ArgumentOutOfRangeException ( "columnIndex" ) ;
71
+ if ( rowIndex < 0 || RowCount <= rowIndex )
72
+ {
73
+ throw new ArgumentOutOfRangeException ( "rowIndex" ) ;
74
+ }
75
+ if ( columnIndex < 0 || ColumnCount <= columnIndex )
76
+ {
77
+ throw new ArgumentOutOfRangeException ( "columnIndex" ) ;
78
+ }
79
+ using ( new ProtectedPointer ( this ) )
80
+ {
81
+ SetValue ( rowIndex , columnIndex , value ) ;
82
+ }
61
83
}
62
- using ( new ProtectedPointer ( this ) )
63
- {
64
- int offset = GetOffset ( rowIndex , columnIndex ) ;
65
- IntPtr pointer = Marshal . ReadIntPtr ( DataPointer , offset ) ;
66
- return new InternalString ( Engine , pointer ) ;
67
- }
68
- }
69
- set
70
- {
71
- if ( rowIndex < 0 || RowCount <= rowIndex )
72
- {
73
- throw new ArgumentOutOfRangeException ( "rowIndex" ) ;
74
- }
75
- if ( columnIndex < 0 || ColumnCount <= columnIndex )
76
- {
77
- throw new ArgumentOutOfRangeException ( "columnIndex" ) ;
78
- }
79
- using ( new ProtectedPointer ( this ) )
84
+ }
85
+
86
+ private void SetValue ( int rowIndex , int columnIndex , string value )
87
+ {
88
+ int offset = GetOffset ( rowIndex , columnIndex ) ;
89
+ SymbolicExpression s = value == null ? Engine . NilValue : new InternalString ( Engine , value ) ;
90
+ using ( new ProtectedPointer ( s ) )
80
91
{
81
- SetValue ( rowIndex , columnIndex , value ) ;
92
+ Marshal . WriteIntPtr ( DataPointer , offset , s . DangerousGetHandle ( ) ) ;
82
93
}
83
- }
84
- }
85
-
86
- private void SetValue ( int rowIndex , int columnIndex , string value )
87
- {
88
- int offset = GetOffset ( rowIndex , columnIndex ) ;
89
- SymbolicExpression s = value == null ? Engine . NilValue : new InternalString ( Engine , value ) ;
90
- using ( new ProtectedPointer ( s ) )
91
- {
92
- Marshal . WriteIntPtr ( DataPointer , offset , s . DangerousGetHandle ( ) ) ;
93
- }
94
- }
94
+ }
95
95
96
- /// <summary>
97
- /// Initializes this R matrix, using the values in a rectangular array.
98
- /// </summary>
99
- /// <param name="matrix"></param>
100
- protected override void InitMatrixFastDirect ( string [ , ] matrix )
101
- {
102
- int rows = matrix . GetLength ( 0 ) ;
103
- int cols = matrix . GetLength ( 1 ) ;
104
- for ( int i = 0 ; i < rows ; i ++ )
105
- {
106
- for ( int j = 0 ; j < cols ; j ++ )
96
+ /// <summary>
97
+ /// Initializes this R matrix, using the values in a rectangular array.
98
+ /// </summary>
99
+ /// <param name="matrix"></param>
100
+ protected override void InitMatrixFastDirect ( string [ , ] matrix )
101
+ {
102
+ int rows = matrix . GetLength ( 0 ) ;
103
+ int cols = matrix . GetLength ( 1 ) ;
104
+ for ( int i = 0 ; i < rows ; i ++ )
107
105
{
108
- SetValue ( i , j , matrix [ i , j ] ) ;
106
+ for ( int j = 0 ; j < cols ; j ++ )
107
+ {
108
+ SetValue ( i , j , matrix [ i , j ] ) ;
109
+ }
109
110
}
110
- }
111
- }
111
+ }
112
112
113
- /// <summary>
114
- /// NotSupportedException();
115
- /// </summary>
116
- /// <returns></returns>
117
- protected override string [ , ] GetArrayFast ( )
118
- {
119
- throw new NotSupportedException ( ) ;
120
- }
113
+ /// <summary>
114
+ /// NotSupportedException();
115
+ /// </summary>
116
+ /// <returns></returns>
117
+ protected override string [ , ] GetArrayFast ( )
118
+ {
119
+ throw new NotSupportedException ( ) ;
120
+ }
121
121
122
- /// <summary>
123
- /// Gets the size of a pointer in byte.
124
- /// </summary>
125
- protected override int DataSize
126
- {
127
- get { return Marshal . SizeOf ( typeof ( IntPtr ) ) ; }
128
- }
129
- }
122
+ /// <summary>
123
+ /// Gets the size of a pointer in byte.
124
+ /// </summary>
125
+ protected override int DataSize
126
+ {
127
+ get { return Marshal . SizeOf ( typeof ( IntPtr ) ) ; }
128
+ }
129
+ }
130
130
}
0 commit comments