Mercurial > hg > octave-nkf
annotate src/ov-scalar.h @ 9585:06b8b51dca48
also handle user-defined graphics properties in new property name validation scheme
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 28 Aug 2009 18:37:31 -0400 |
parents | d865363208d6 |
children | e793865ede63 |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2004, 2005, 2006, |
8920 | 4 2007, 2008, 2009 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 #if !defined (octave_scalar_h) | |
25 #define octave_scalar_h 1 | |
26 | |
27 #include <cstdlib> | |
28 | |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
29 #include <iosfwd> |
2376 | 30 #include <string> |
31 | |
5110 | 32 #include "lo-ieee.h" |
2889 | 33 #include "lo-mappers.h" |
2376 | 34 #include "lo-utils.h" |
35 #include "mx-base.h" | |
2477 | 36 #include "oct-alloc.h" |
2376 | 37 #include "str-vec.h" |
38 | |
5943 | 39 #include "gripes.h" |
2376 | 40 #include "ov-base.h" |
4749 | 41 #include "ov-re-mat.h" |
3223 | 42 #include "ov-base-scalar.h" |
2376 | 43 #include "ov-typeinfo.h" |
44 | |
45 class Octave_map; | |
46 class octave_value_list; | |
47 | |
48 class tree_walker; | |
49 | |
50 // Real scalar values. | |
51 | |
52 class | |
6153 | 53 OCTINTERP_API |
3223 | 54 octave_scalar : public octave_base_scalar<double> |
2376 | 55 { |
56 public: | |
57 | |
58 octave_scalar (void) | |
3223 | 59 : octave_base_scalar<double> (0.0) { } |
2376 | 60 |
61 octave_scalar (double d) | |
3223 | 62 : octave_base_scalar<double> (d) { } |
2376 | 63 |
64 octave_scalar (const octave_scalar& s) | |
3223 | 65 : octave_base_scalar<double> (s) { } |
2376 | 66 |
67 ~octave_scalar (void) { } | |
68 | |
5759 | 69 octave_base_value *clone (void) const { return new octave_scalar (*this); } |
4749 | 70 |
71 // We return an octave_matrix here instead of an octave_scalar so | |
72 // that in expressions like A(2,2,2) = 2 (for A previously | |
73 // undefined), A will be empty instead of a 1x1 object. | |
5759 | 74 octave_base_value *empty_clone (void) const { return new octave_matrix (); } |
2376 | 75 |
5885 | 76 octave_value do_index_op (const octave_value_list& idx, |
77 bool resize_ok = false); | |
2376 | 78 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8202
diff
changeset
|
79 type_conv_info numeric_demotion_function (void) const; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
80 |
2376 | 81 idx_vector index_vector (void) const { return idx_vector (scalar); } |
82 | |
5110 | 83 octave_value any (int = 0) const |
84 { return (scalar != 0 && ! lo_ieee_isnan (scalar)); } | |
85 | |
2376 | 86 bool is_real_scalar (void) const { return true; } |
87 | |
88 bool is_real_type (void) const { return true; } | |
89 | |
5895 | 90 bool is_double_type (void) const { return true; } |
91 | |
7576 | 92 bool is_float_type (void) const { return true; } |
93 | |
5533 | 94 int8NDArray |
95 int8_array_value (void) const | |
96 { return int8NDArray (dim_vector (1, 1), scalar); } | |
97 | |
98 int16NDArray | |
99 int16_array_value (void) const | |
100 { return int16NDArray (dim_vector (1, 1), scalar); } | |
101 | |
102 int32NDArray | |
103 int32_array_value (void) const | |
104 { return int32NDArray (dim_vector (1, 1), scalar); } | |
105 | |
106 int64NDArray | |
107 int64_array_value (void) const | |
108 { return int64NDArray (dim_vector (1, 1), scalar); } | |
109 | |
110 uint8NDArray | |
111 uint8_array_value (void) const | |
112 { return uint8NDArray (dim_vector (1, 1), scalar); } | |
113 | |
114 uint16NDArray | |
115 uint16_array_value (void) const | |
116 { return uint16NDArray (dim_vector (1, 1), scalar); } | |
117 | |
118 uint32NDArray | |
119 uint32_array_value (void) const | |
120 { return uint32NDArray (dim_vector (1, 1), scalar); } | |
121 | |
122 uint64NDArray | |
123 uint64_array_value (void) const | |
124 { return uint64NDArray (dim_vector (1, 1), scalar); } | |
125 | |
8854
97d146d1648b
add missing scalar->int scalar conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8437
diff
changeset
|
126 #define DEFINE_INT_SCALAR_VALUE(TYPE) \ |
97d146d1648b
add missing scalar->int scalar conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8437
diff
changeset
|
127 octave_ ## TYPE \ |
97d146d1648b
add missing scalar->int scalar conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8437
diff
changeset
|
128 TYPE ## _scalar_value (void) const \ |
97d146d1648b
add missing scalar->int scalar conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8437
diff
changeset
|
129 { return octave_ ## TYPE (scalar); } |
97d146d1648b
add missing scalar->int scalar conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8437
diff
changeset
|
130 |
97d146d1648b
add missing scalar->int scalar conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8437
diff
changeset
|
131 DEFINE_INT_SCALAR_VALUE (int8) |
97d146d1648b
add missing scalar->int scalar conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8437
diff
changeset
|
132 DEFINE_INT_SCALAR_VALUE (int16) |
97d146d1648b
add missing scalar->int scalar conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8437
diff
changeset
|
133 DEFINE_INT_SCALAR_VALUE (int32) |
97d146d1648b
add missing scalar->int scalar conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8437
diff
changeset
|
134 DEFINE_INT_SCALAR_VALUE (int64) |
97d146d1648b
add missing scalar->int scalar conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8437
diff
changeset
|
135 DEFINE_INT_SCALAR_VALUE (uint8) |
97d146d1648b
add missing scalar->int scalar conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8437
diff
changeset
|
136 DEFINE_INT_SCALAR_VALUE (uint16) |
97d146d1648b
add missing scalar->int scalar conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8437
diff
changeset
|
137 DEFINE_INT_SCALAR_VALUE (uint32) |
97d146d1648b
add missing scalar->int scalar conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8437
diff
changeset
|
138 DEFINE_INT_SCALAR_VALUE (uint64) |
97d146d1648b
add missing scalar->int scalar conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8437
diff
changeset
|
139 |
97d146d1648b
add missing scalar->int scalar conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8437
diff
changeset
|
140 #undef DEFINE_INT_SCALAR_VALUE |
97d146d1648b
add missing scalar->int scalar conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8437
diff
changeset
|
141 |
2376 | 142 double double_value (bool = false) const { return scalar; } |
143 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
144 float float_value (bool = false) const { return static_cast<float> (scalar); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
145 |
2916 | 146 double scalar_value (bool = false) const { return scalar; } |
147 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
148 float float_scalar_value (bool = false) const { return static_cast<float> (scalar); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
149 |
3145 | 150 Matrix matrix_value (bool = false) const |
151 { return Matrix (1, 1, scalar); } | |
2376 | 152 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
153 FloatMatrix float_matrix_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
154 { return FloatMatrix (1, 1, scalar); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
155 |
4569 | 156 NDArray array_value (bool = false) const |
4630 | 157 { return NDArray (dim_vector (1, 1), scalar); } |
4505 | 158 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
159 FloatNDArray float_array_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
160 { return FloatNDArray (dim_vector (1, 1), scalar); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
161 |
5989 | 162 SparseMatrix sparse_matrix_value (bool = false) const |
163 { return SparseMatrix (Matrix (1, 1, scalar)); } | |
164 | |
8202
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
7922
diff
changeset
|
165 // FIXME Need SparseComplexMatrix (Matrix) constructor!!! |
5989 | 166 SparseComplexMatrix sparse_complex_matrix_value (bool = false) const |
167 { return SparseComplexMatrix (sparse_matrix_value ()); } | |
168 | |
5731 | 169 octave_value resize (const dim_vector& dv, bool fill = false) const; |
4915 | 170 |
2376 | 171 Complex complex_value (bool = false) const { return scalar; } |
172 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
173 FloatComplex float_complex_value (bool = false) const { return scalar; } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
174 |
2376 | 175 ComplexMatrix complex_matrix_value (bool = false) const |
176 { return ComplexMatrix (1, 1, Complex (scalar)); } | |
177 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
178 FloatComplexMatrix float_complex_matrix_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
179 { return FloatComplexMatrix (1, 1, FloatComplex (scalar)); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
180 |
4569 | 181 ComplexNDArray complex_array_value (bool = false) const |
4630 | 182 { return ComplexNDArray (dim_vector (1, 1), Complex (scalar)); } |
4569 | 183 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
184 FloatComplexNDArray float_complex_array_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
185 { return FloatComplexNDArray (dim_vector (1, 1), FloatComplex (scalar)); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
186 |
5533 | 187 charNDArray |
188 char_array_value (bool = false) const | |
189 { | |
190 charNDArray retval (dim_vector (1, 1)); | |
191 retval(0) = static_cast<char> (scalar); | |
192 return retval; | |
193 } | |
194 | |
5943 | 195 bool bool_value (bool warn = false) const |
196 { | |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7885
diff
changeset
|
197 if (xisnan (scalar)) |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7885
diff
changeset
|
198 error ("invalid conversion from NaN to logical"); |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7885
diff
changeset
|
199 else if (warn && scalar != 0 && scalar != 1) |
5943 | 200 gripe_logical_conversion (); |
201 | |
202 return scalar; | |
203 } | |
5533 | 204 |
5943 | 205 boolNDArray bool_array_value (bool warn = false) const |
206 { | |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7885
diff
changeset
|
207 if (xisnan (scalar)) |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7885
diff
changeset
|
208 error ("invalid conversion from NaN to logical"); |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7885
diff
changeset
|
209 else if (warn && scalar != 0 && scalar != 1) |
5943 | 210 gripe_logical_conversion (); |
211 | |
212 return boolNDArray (dim_vector (1, 1), scalar); | |
213 } | |
5533 | 214 |
5279 | 215 octave_value convert_to_str_internal (bool pad, bool force, char type) const; |
3223 | 216 |
2376 | 217 void increment (void) { ++scalar; } |
218 | |
219 void decrement (void) { --scalar; } | |
220 | |
6974 | 221 bool save_ascii (std::ostream& os); |
4687 | 222 |
223 bool load_ascii (std::istream& is); | |
224 | |
225 bool save_binary (std::ostream& os, bool& save_as_floats); | |
226 | |
227 bool load_binary (std::istream& is, bool swap, | |
228 oct_mach_info::float_format fmt); | |
229 | |
230 #if defined (HAVE_HDF5) | |
231 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); | |
232 | |
233 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); | |
234 #endif | |
235 | |
4944 | 236 int write (octave_stream& os, int block_size, |
237 oct_data_conv::data_type output_type, int skip, | |
238 oct_mach_info::float_format flt_fmt) const | |
239 { | |
240 return os.write (array_value (), block_size, output_type, | |
241 skip, flt_fmt); | |
242 } | |
243 | |
5900 | 244 mxArray *as_mxArray (void) const; |
245 | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
246 octave_value erf (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
247 octave_value erfc (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
248 octave_value gamma (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
249 octave_value lgamma (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
250 octave_value abs (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
251 octave_value acos (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
252 octave_value acosh (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
253 octave_value angle (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
254 octave_value arg (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
255 octave_value asin (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
256 octave_value asinh (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
257 octave_value atan (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
258 octave_value atanh (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
259 octave_value ceil (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
260 octave_value conj (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
261 octave_value cos (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
262 octave_value cosh (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
263 octave_value exp (void) const; |
7638
2df457529cfa
implement expm1 and log1p functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7636
diff
changeset
|
264 octave_value expm1 (void) const; |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
265 octave_value fix (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
266 octave_value floor (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
267 octave_value imag (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
268 octave_value log (void) const; |
7740 | 269 octave_value log2 (void) const; |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
270 octave_value log10 (void) const; |
7638
2df457529cfa
implement expm1 and log1p functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7636
diff
changeset
|
271 octave_value log1p (void) const; |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
272 octave_value real (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
273 octave_value round (void) const; |
7636
99c410f7f0b0
implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents:
7576
diff
changeset
|
274 octave_value roundb (void) const; |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
275 octave_value signum (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
276 octave_value sin (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
277 octave_value sinh (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
278 octave_value sqrt (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
279 octave_value tan (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
280 octave_value tanh (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
281 octave_value finite (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
282 octave_value isinf (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
283 octave_value isna (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
284 octave_value isnan (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
285 |
2376 | 286 private: |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
287 octave_value map (double (*fcn) (double)) const; |
2376 | 288 |
4612 | 289 DECLARE_OCTAVE_ALLOCATOR |
2477 | 290 |
4612 | 291 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2376 | 292 }; |
293 | |
294 #endif | |
295 | |
296 /* | |
297 ;;; Local Variables: *** | |
298 ;;; mode: C++ *** | |
299 ;;; End: *** | |
300 */ |