2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_scalar_h) |
|
24 #define octave_scalar_h 1 |
|
25 |
4192
|
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2376
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <cstdlib> |
|
31 |
3503
|
32 #include <iostream> |
2376
|
33 #include <string> |
|
34 |
2889
|
35 #include "lo-mappers.h" |
2376
|
36 #include "lo-utils.h" |
|
37 #include "mx-base.h" |
2477
|
38 #include "oct-alloc.h" |
2376
|
39 #include "str-vec.h" |
|
40 |
|
41 #include "ov-base.h" |
4749
|
42 #include "ov-re-mat.h" |
3223
|
43 #include "ov-base-scalar.h" |
2376
|
44 #include "ov-typeinfo.h" |
|
45 |
|
46 class Octave_map; |
|
47 class octave_value_list; |
|
48 |
|
49 class tree_walker; |
|
50 |
|
51 // Real scalar values. |
|
52 |
|
53 class |
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 |
3933
|
69 octave_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. |
|
74 octave_value *empty_clone (void) const { return new octave_matrix (); } |
2376
|
75 |
3933
|
76 octave_value do_index_op (const octave_value_list& idx, int resize_ok); |
2376
|
77 |
|
78 idx_vector index_vector (void) const { return idx_vector (scalar); } |
|
79 |
|
80 bool is_real_scalar (void) const { return true; } |
|
81 |
|
82 bool is_real_type (void) const { return true; } |
|
83 |
|
84 bool valid_as_scalar_index (void) const |
|
85 { return (! xisnan (scalar) && NINT (scalar) == 1); } |
|
86 |
|
87 bool valid_as_zero_index (void) const |
|
88 { return (! xisnan (scalar) && NINT (scalar) == 0); } |
|
89 |
|
90 double double_value (bool = false) const { return scalar; } |
|
91 |
2916
|
92 double scalar_value (bool = false) const { return scalar; } |
|
93 |
3145
|
94 Matrix matrix_value (bool = false) const |
|
95 { return Matrix (1, 1, scalar); } |
2376
|
96 |
4569
|
97 NDArray array_value (bool = false) const |
4630
|
98 { return NDArray (dim_vector (1, 1), scalar); } |
4505
|
99 |
4915
|
100 octave_value resize (const dim_vector& dv) const |
|
101 { NDArray retval (dv); if (dv.numel()) retval(0) = scalar; return retval; } |
|
102 |
2376
|
103 Complex complex_value (bool = false) const { return scalar; } |
|
104 |
|
105 ComplexMatrix complex_matrix_value (bool = false) const |
|
106 { return ComplexMatrix (1, 1, Complex (scalar)); } |
|
107 |
4569
|
108 ComplexNDArray complex_array_value (bool = false) const |
4630
|
109 { return ComplexNDArray (dim_vector (1, 1), Complex (scalar)); } |
4569
|
110 |
4645
|
111 std::streamoff streamoff_value (void) const; |
|
112 |
4701
|
113 streamoff_array streamoff_array_value (void) const; |
|
114 |
4457
|
115 octave_value convert_to_str_internal (bool pad, bool force) const; |
3223
|
116 |
2376
|
117 void increment (void) { ++scalar; } |
|
118 |
|
119 void decrement (void) { --scalar; } |
|
120 |
4687
|
121 bool save_ascii (std::ostream& os, bool& infnan_warned, |
|
122 bool strip_nan_and_inf); |
|
123 |
|
124 bool load_ascii (std::istream& is); |
|
125 |
|
126 bool save_binary (std::ostream& os, bool& save_as_floats); |
|
127 |
|
128 bool load_binary (std::istream& is, bool swap, |
|
129 oct_mach_info::float_format fmt); |
|
130 |
|
131 #if defined (HAVE_HDF5) |
|
132 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); |
|
133 |
|
134 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); |
|
135 #endif |
|
136 |
2376
|
137 private: |
|
138 |
4612
|
139 DECLARE_OCTAVE_ALLOCATOR |
2477
|
140 |
4612
|
141 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2376
|
142 }; |
|
143 |
|
144 #endif |
|
145 |
|
146 /* |
|
147 ;;; Local Variables: *** |
|
148 ;;; mode: C++ *** |
|
149 ;;; End: *** |
|
150 */ |