Mercurial > hg > octave-nkf
annotate src/ov-ch-mat.cc @ 9784:f786dca09f79
implement nfields
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sun, 08 Nov 2009 21:25:46 +0100 |
parents | f42f0d707e8e |
children | f80c566bc751 |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2004, 2005, 2006, |
8920 | 4 2007, 2008 John W. Eaton |
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 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
3503 | 28 #include <iostream> |
2901 | 29 |
2376 | 30 #include "lo-ieee.h" |
31 #include "mx-base.h" | |
32 | |
3219 | 33 #include "ov-base.h" |
34 #include "ov-base-mat.h" | |
35 #include "ov-base-mat.cc" | |
2376 | 36 #include "ov-ch-mat.h" |
37 #include "gripes.h" | |
38 #include "pr-output.h" | |
39 | |
4513 | 40 template class octave_base_matrix<charNDArray>; |
2376 | 41 |
6720 | 42 idx_vector |
43 octave_char_matrix::index_vector (void) const | |
44 { | |
45 const char *p = matrix.data (); | |
46 if (numel () == 1 && *p == ':') | |
47 return idx_vector (':'); | |
48 else | |
49 return idx_vector (array_value (true)); | |
50 } | |
51 | |
2376 | 52 double |
53 octave_char_matrix::double_value (bool) const | |
54 { | |
4102 | 55 double retval = lo_ieee_nan_value (); |
2376 | 56 |
4455 | 57 if (rows () > 0 && columns () > 0) |
58 { | |
5781 | 59 gripe_implicit_conversion ("Octave:array-as-scalar", |
60 "character matrix", "real scalar"); | |
4455 | 61 |
8956
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
62 retval = static_cast<unsigned char> (matrix (0, 0)); |
4455 | 63 } |
2376 | 64 else |
65 gripe_invalid_conversion ("character matrix", "real scalar"); | |
66 | |
67 return retval; | |
68 } | |
69 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
70 float |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
71 octave_char_matrix::float_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
72 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
73 float retval = lo_ieee_float_nan_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
74 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
75 if (rows () > 0 && columns () > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
76 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
77 gripe_implicit_conversion ("Octave:array-as-scalar", |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
78 "character matrix", "real scalar"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
79 |
8956
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
80 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
|
81 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
82 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
83 gripe_invalid_conversion ("character matrix", "real scalar"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
84 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
85 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
86 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
87 |
2376 | 88 Complex |
89 octave_char_matrix::complex_value (bool) const | |
90 { | |
4102 | 91 double tmp = lo_ieee_nan_value (); |
92 | |
93 Complex retval (tmp, tmp); | |
2376 | 94 |
4455 | 95 if (rows () > 0 && columns () > 0) |
96 { | |
5781 | 97 gripe_implicit_conversion ("Octave:array-as-scalar", |
98 "character matrix", "complex scalar"); | |
4455 | 99 |
8956
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
100 retval = static_cast<unsigned char> (matrix (0, 0)); |
4455 | 101 } |
2376 | 102 else |
103 gripe_invalid_conversion ("character matrix", "complex scalar"); | |
104 | |
105 return retval; | |
106 } | |
107 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
108 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
109 octave_char_matrix::float_complex_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
110 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
111 float tmp = lo_ieee_float_nan_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
112 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
113 FloatComplex retval (tmp, tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
114 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
115 if (rows () > 0 && columns () > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
116 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
117 gripe_implicit_conversion ("Octave:array-as-scalar", |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
118 "character matrix", "complex scalar"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
119 |
8956
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
120 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
|
121 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
122 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
123 gripe_invalid_conversion ("character matrix", "complex scalar"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
124 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
125 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
126 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
127 |
4643 | 128 void |
129 octave_char_matrix::print_raw (std::ostream& os, | |
130 bool pr_as_read_syntax) const | |
131 { | |
132 octave_print_internal (os, matrix, pr_as_read_syntax, | |
133 current_print_indent_level ()); | |
134 } | |
135 | |
5900 | 136 mxArray * |
137 octave_char_matrix::as_mxArray (void) const | |
138 { | |
139 mxArray *retval = new mxArray (mxCHAR_CLASS, dims (), mxREAL); | |
140 | |
141 mxChar *pr = static_cast<mxChar *> (retval->get_data ()); | |
142 | |
6686 | 143 mwSize nel = numel (); |
5900 | 144 |
145 const char *p = matrix.data (); | |
146 | |
6686 | 147 for (mwIndex i = 0; i < nel; i++) |
5900 | 148 pr[i] = p[i]; |
149 | |
150 return retval; | |
151 } | |
152 | |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
153 #define MACRO_WRAPPER(FCN, CTYPE_FCN) \ |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
154 static int x ## FCN (int c) { return CTYPE_FCN (c); } |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
155 |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
156 #define STRING_MAPPER(FCN, AMAP, CTYPE_FCN) \ |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
157 MACRO_WRAPPER (FCN, CTYPE_FCN) \ |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
158 \ |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
159 octave_value \ |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
160 octave_char_matrix::FCN (void) const \ |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
161 { \ |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
162 static charNDArray::mapper smap = x ## FCN; \ |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
163 return matrix.AMAP (smap); \ |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
164 } |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
165 |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
166 #define TOSTRING_MAPPER(FCN, AMAP, CTYPE_FCN) \ |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
167 MACRO_WRAPPER (FCN, CTYPE_FCN) \ |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
168 \ |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
169 octave_value \ |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
170 octave_char_matrix::FCN (void) const \ |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
171 { \ |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
172 static charNDArray::mapper smap = x ## FCN; \ |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
173 return octave_value (matrix.AMAP (smap), is_sq_string () ? '\'' : '"'); \ |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
174 } |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
175 |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
176 STRING_MAPPER (xisalnum, bmap, isalnum) |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
177 STRING_MAPPER (xisalpha, bmap, isalpha) |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
178 STRING_MAPPER (xisascii, bmap, isascii) |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
179 STRING_MAPPER (xiscntrl, bmap, iscntrl) |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
180 STRING_MAPPER (xisdigit, bmap, isdigit) |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
181 STRING_MAPPER (xisgraph, bmap, isgraph) |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
182 STRING_MAPPER (xislower, bmap, islower) |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
183 STRING_MAPPER (xisprint, bmap, isprint) |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
184 STRING_MAPPER (xispunct, bmap, ispunct) |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
185 STRING_MAPPER (xisspace, bmap, isspace) |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
186 STRING_MAPPER (xisupper, bmap, isupper) |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
187 STRING_MAPPER (xisxdigit, bmap, isxdigit) |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
188 STRING_MAPPER (xtoascii, dmap, toascii) |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
189 TOSTRING_MAPPER (xtolower, smap, tolower) |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
190 TOSTRING_MAPPER (xtoupper, smap, toupper) |
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
8956
diff
changeset
|
191 |
2376 | 192 /* |
193 ;;; Local Variables: *** | |
194 ;;; mode: C++ *** | |
195 ;;; End: *** | |
196 */ |