Mercurial > octave
annotate libinterp/octave-value/ov-ch-mat.cc @ 23219:3ac9f9ecfae5 stable
maint: Update copyright dates.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 22 Feb 2017 12:39:29 -0500 |
parents | e9a0469dedd9 |
children | 092078913d54 |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 1996-2017 John W. Eaton |
11523 | 4 Copyright (C) 2009-2010 VZLU Prague |
2376 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2376 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2376 | 21 |
22 */ | |
23 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
24 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
25 # include "config.h" |
2376 | 26 #endif |
27 | |
9941
1369f13ae6b2
several fixes by M. Goffioul
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
28 #include <cctype> |
3503 | 29 #include <iostream> |
2901 | 30 |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
31 #include "dNDArray.h" |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
32 #include "fNDArray.h" |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
33 #include "int8NDArray.h" |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
34 #include "int16NDArray.h" |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
35 #include "int32NDArray.h" |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
36 #include "int64NDArray.h" |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
37 #include "uint8NDArray.h" |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
38 #include "uint16NDArray.h" |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
39 #include "uint32NDArray.h" |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
40 #include "uint64NDArray.h" |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
41 |
2376 | 42 #include "lo-ieee.h" |
43 #include "mx-base.h" | |
44 | |
15149
62a35ae7d6a2
use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents:
15057
diff
changeset
|
45 #include "mxarray.h" |
3219 | 46 #include "ov-base.h" |
47 #include "ov-base-mat.h" | |
48 #include "ov-base-mat.cc" | |
2376 | 49 #include "ov-ch-mat.h" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
50 #include "errwarn.h" |
2376 | 51 #include "pr-output.h" |
52 | |
4513 | 53 template class octave_base_matrix<charNDArray>; |
2376 | 54 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
55 idx_vector |
18130
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
56 octave_char_matrix::index_vector (bool /* require_integers */) const |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
57 { |
6720 | 58 const char *p = matrix.data (); |
59 if (numel () == 1 && *p == ':') | |
60 return idx_vector (':'); | |
61 else | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
62 return idx_vector (array_value (true)); |
6720 | 63 } |
64 | |
2376 | 65 double |
66 octave_char_matrix::double_value (bool) const | |
67 { | |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
68 if (rows () == 0 || columns () == 0) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
69 err_invalid_conversion ("character matrix", "real scalar"); |
4455 | 70 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
71 warn_implicit_conversion ("Octave:array-to-scalar", |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
72 "character matrix", "real scalar"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
73 |
22477
6bf1cbb90705
Remove unnecessary initializations in float_value and double_value methods
Julien Bect <julien.bect@centralesupelec.fr>
parents:
22407
diff
changeset
|
74 return static_cast<unsigned char> (matrix(0, 0)); |
2376 | 75 } |
76 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
77 float |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
78 octave_char_matrix::float_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
79 { |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
80 if (rows () == 0 && columns () == 0) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
81 err_invalid_conversion ("character matrix", "real scalar"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
82 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
83 warn_implicit_conversion ("Octave:array-to-scalar", |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
84 "character matrix", "real scalar"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
85 |
22477
6bf1cbb90705
Remove unnecessary initializations in float_value and double_value methods
Julien Bect <julien.bect@centralesupelec.fr>
parents:
22407
diff
changeset
|
86 return static_cast<unsigned char> (matrix(0, 0)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
87 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
88 |
20252
7fa170cc14fe
Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
89 octave_int64 |
7fa170cc14fe
Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
90 octave_char_matrix::int64_scalar_value () const |
7fa170cc14fe
Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
91 { |
7fa170cc14fe
Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
92 octave_int64 retval = 0; |
7fa170cc14fe
Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
93 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
94 if (rows () == 0 || columns () == 0) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
95 err_invalid_conversion ("character matrix", "int64 scalar"); |
20252
7fa170cc14fe
Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
96 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
97 warn_implicit_conversion ("Octave:array-to-scalar", |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
98 "character matrix", "int64 scalar"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
99 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
100 retval = octave_int64 (matrix(0, 0)); |
20252
7fa170cc14fe
Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
101 |
7fa170cc14fe
Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
102 return retval; |
7fa170cc14fe
Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
103 } |
7fa170cc14fe
Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
104 |
7fa170cc14fe
Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
105 octave_uint64 |
7fa170cc14fe
Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
106 octave_char_matrix::uint64_scalar_value () const |
7fa170cc14fe
Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
107 { |
7fa170cc14fe
Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
108 octave_uint64 retval = 0; |
7fa170cc14fe
Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
109 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
110 if (rows () == 0 || columns () == 0) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
111 err_invalid_conversion ("character matrix", "uint64 scalar"); |
20252
7fa170cc14fe
Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
112 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
113 warn_implicit_conversion ("Octave:array-to-scalar", |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
114 "character matrix", "uint64 scalar"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
115 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
116 retval = octave_uint64 (matrix(0, 0)); |
20252
7fa170cc14fe
Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
117 |
7fa170cc14fe
Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
118 return retval; |
7fa170cc14fe
Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
119 } |
7fa170cc14fe
Return correct hex value for printf when used with string inputs (bug #45263).
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
120 |
2376 | 121 Complex |
122 octave_char_matrix::complex_value (bool) const | |
123 { | |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
124 if (rows () == 0 && columns () == 0) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
125 err_invalid_conversion ("character matrix", "complex scalar"); |
4455 | 126 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
127 warn_implicit_conversion ("Octave:array-to-scalar", |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
128 "character matrix", "complex scalar"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
129 |
22508
0b278f54f60a
Remove unnecessary initializations in complex_value methods.
Julien Bect <jbect@users.sourceforge.net>
parents:
22477
diff
changeset
|
130 return Complex (static_cast<unsigned char> (matrix(0, 0)), 0); |
2376 | 131 } |
132 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
133 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
134 octave_char_matrix::float_complex_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
135 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
136 float tmp = lo_ieee_float_nan_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
137 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
138 FloatComplex retval (tmp, tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
139 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
140 if (rows () == 0 || columns () == 0) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
141 err_invalid_conversion ("character matrix", "complex scalar"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
142 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
143 warn_implicit_conversion ("Octave:array-to-scalar", |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
144 "character matrix", "complex scalar"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
145 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
146 retval = static_cast<unsigned char> (matrix(0, 0)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
147 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
148 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
149 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
150 |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
151 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
152 octave_char_matrix::as_double (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
153 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
154 return NDArray (matrix); |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
155 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
156 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
157 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
158 octave_char_matrix::as_single (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
159 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
160 return FloatNDArray (matrix); |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
161 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
162 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
163 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
164 octave_char_matrix::as_int8 (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
165 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
166 return int8NDArray (matrix); |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
167 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
168 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
169 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
170 octave_char_matrix::as_int16 (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
171 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
172 return int16NDArray (matrix); |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
173 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
174 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
175 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
176 octave_char_matrix::as_int32 (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
177 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
178 return int32NDArray (matrix); |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
179 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
180 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
181 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
182 octave_char_matrix::as_int64 (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
183 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
184 return int64NDArray (matrix); |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
185 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
186 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
187 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
188 octave_char_matrix::as_uint8 (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
189 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
190 return uint8NDArray (matrix); |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
191 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
192 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
193 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
194 octave_char_matrix::as_uint16 (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
195 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
196 return uint16NDArray (matrix); |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
197 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
198 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
199 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
200 octave_char_matrix::as_uint32 (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
201 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
202 return uint32NDArray (matrix); |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
203 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
204 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
205 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
206 octave_char_matrix::as_uint64 (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
207 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
208 return uint64NDArray (matrix); |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
209 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
210 |
4643 | 211 void |
212 octave_char_matrix::print_raw (std::ostream& os, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
213 bool pr_as_read_syntax) const |
4643 | 214 { |
215 octave_print_internal (os, matrix, pr_as_read_syntax, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
216 current_print_indent_level ()); |
4643 | 217 } |
218 | |
5900 | 219 mxArray * |
220 octave_char_matrix::as_mxArray (void) const | |
221 { | |
222 mxArray *retval = new mxArray (mxCHAR_CLASS, dims (), mxREAL); | |
223 | |
224 mxChar *pr = static_cast<mxChar *> (retval->get_data ()); | |
225 | |
6686 | 226 mwSize nel = numel (); |
5900 | 227 |
228 const char *p = matrix.data (); | |
229 | |
6686 | 230 for (mwIndex i = 0; i < nel; i++) |
5900 | 231 pr[i] = p[i]; |
232 | |
233 return retval; | |
234 } | |
235 | |
15491
c9844b82945f
reformat interesting comment
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15452
diff
changeset
|
236 // The C++ standard guarantees cctype defines functions, not macros (and |
c9844b82945f
reformat interesting comment
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15452
diff
changeset
|
237 // hence macros *CAN'T* be defined if only cctype is included) so |
15850
ffd1a99733bd
build: Check for isascii() before using it.
Rik <rik@octave.org>
parents:
15501
diff
changeset
|
238 // there's no need to fuck around. The exceptions are isascii and |
ffd1a99733bd
build: Check for isascii() before using it.
Rik <rik@octave.org>
parents:
15501
diff
changeset
|
239 // toascii, which are not C++. Oddly enough, all those character |
ffd1a99733bd
build: Check for isascii() before using it.
Rik <rik@octave.org>
parents:
15501
diff
changeset
|
240 // functions are int (*) (int), even in C++. Wicked! |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9690
diff
changeset
|
241 static inline int xisascii (int c) |
15850
ffd1a99733bd
build: Check for isascii() before using it.
Rik <rik@octave.org>
parents:
15501
diff
changeset
|
242 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
243 #if defined (HAVE_ISASCII) |
15850
ffd1a99733bd
build: Check for isascii() before using it.
Rik <rik@octave.org>
parents:
15501
diff
changeset
|
244 return isascii (c); |
ffd1a99733bd
build: Check for isascii() before using it.
Rik <rik@octave.org>
parents:
15501
diff
changeset
|
245 #else |
ffd1a99733bd
build: Check for isascii() before using it.
Rik <rik@octave.org>
parents:
15501
diff
changeset
|
246 return (c >= 0x00 && c <= 0x7f); |
ffd1a99733bd
build: Check for isascii() before using it.
Rik <rik@octave.org>
parents:
15501
diff
changeset
|
247 #endif |
ffd1a99733bd
build: Check for isascii() before using it.
Rik <rik@octave.org>
parents:
15501
diff
changeset
|
248 } |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
249 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9690
diff
changeset
|
250 static inline int xtoascii (int c) |
15452
4d960b078272
build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
251 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
252 #if defined (HAVE_TOASCII) |
15452
4d960b078272
build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
253 return toascii (c); |
4d960b078272
build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
254 #else |
4d960b078272
build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
255 return (c & 0x7F); |
4d960b078272
build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
256 #endif |
4d960b078272
build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
257 } |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9690
diff
changeset
|
258 |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9690
diff
changeset
|
259 octave_value |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9690
diff
changeset
|
260 octave_char_matrix::map (unary_mapper_t umap) const |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9690
diff
changeset
|
261 { |
15501
814c4b0d5c49
make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents:
15491
diff
changeset
|
262 octave_value retval; |
814c4b0d5c49
make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents:
15491
diff
changeset
|
263 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9690
diff
changeset
|
264 switch (umap) |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9690
diff
changeset
|
265 { |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
266 #define STRING_MAPPER(UMAP,FCN,TYPE) \ |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
267 case umap_ ## UMAP: \ |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
268 return octave_value (matrix.map<TYPE, int (&) (int)> (FCN)) |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
269 |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
270 STRING_MAPPER (xisalnum, std::isalnum, bool); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
271 STRING_MAPPER (xisalpha, std::isalpha, bool); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
272 STRING_MAPPER (xisascii, xisascii, bool); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
273 STRING_MAPPER (xiscntrl, std::iscntrl, bool); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
274 STRING_MAPPER (xisdigit, std::isdigit, bool); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
275 STRING_MAPPER (xisgraph, std::isgraph, bool); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
276 STRING_MAPPER (xislower, std::islower, bool); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
277 STRING_MAPPER (xisprint, std::isprint, bool); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
278 STRING_MAPPER (xispunct, std::ispunct, bool); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
279 STRING_MAPPER (xisspace, std::isspace, bool); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
280 STRING_MAPPER (xisupper, std::isupper, bool); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
281 STRING_MAPPER (xisxdigit, std::isxdigit, bool); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
282 STRING_MAPPER (xtoascii, xtoascii, double); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
283 STRING_MAPPER (xtolower, std::tolower, char); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
284 STRING_MAPPER (xtoupper, std::toupper, char); |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
285 |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20252
diff
changeset
|
286 // For Matlab compatibility, these should work on ASCII values |
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20252
diff
changeset
|
287 // without error or warning. |
15501
814c4b0d5c49
make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents:
15491
diff
changeset
|
288 case umap_abs: |
814c4b0d5c49
make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents:
15491
diff
changeset
|
289 case umap_ceil: |
814c4b0d5c49
make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents:
15491
diff
changeset
|
290 case umap_fix: |
814c4b0d5c49
make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents:
15491
diff
changeset
|
291 case umap_floor: |
814c4b0d5c49
make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents:
15491
diff
changeset
|
292 case umap_imag: |
814c4b0d5c49
make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents:
15491
diff
changeset
|
293 case umap_isinf: |
814c4b0d5c49
make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents:
15491
diff
changeset
|
294 case umap_isnan: |
814c4b0d5c49
make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents:
15491
diff
changeset
|
295 case umap_real: |
814c4b0d5c49
make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents:
15491
diff
changeset
|
296 case umap_round: |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9690
diff
changeset
|
297 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9690
diff
changeset
|
298 octave_matrix m (array_value (true)); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9690
diff
changeset
|
299 return m.map (umap); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9690
diff
changeset
|
300 } |
15501
814c4b0d5c49
make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents:
15491
diff
changeset
|
301 |
814c4b0d5c49
make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents:
15491
diff
changeset
|
302 default: |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20252
diff
changeset
|
303 error ("%s: argument must be numeric", get_umap_name (umap)); |
15501
814c4b0d5c49
make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents:
15491
diff
changeset
|
304 break; |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9690
diff
changeset
|
305 } |
15501
814c4b0d5c49
make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents:
15491
diff
changeset
|
306 |
814c4b0d5c49
make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents:
15491
diff
changeset
|
307 return retval; |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9690
diff
changeset
|
308 } |