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_range_h) |
|
24 #define octave_range_h 1 |
|
25 |
|
26 #include <cstdlib> |
|
27 |
3503
|
28 #include <iostream> |
2376
|
29 #include <string> |
|
30 |
|
31 #include "Range.h" |
|
32 |
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 |
|
39 #include "error.h" |
5051
|
40 #include "oct-stream.h" |
2376
|
41 #include "ov-base.h" |
|
42 #include "ov-typeinfo.h" |
|
43 |
|
44 class Octave_map; |
|
45 class octave_value_list; |
|
46 |
|
47 class tree_walker; |
|
48 |
|
49 // Range values. |
|
50 |
|
51 class |
|
52 octave_range : public octave_base_value |
|
53 { |
|
54 public: |
|
55 |
|
56 octave_range (void) |
|
57 : octave_base_value () { } |
|
58 |
|
59 octave_range (double base, double limit, double inc) |
|
60 : octave_base_value (), range (base, limit, inc) |
|
61 { |
|
62 if (range.nelem () < 0) |
|
63 ::error ("invalid range"); |
|
64 } |
|
65 |
|
66 octave_range (const Range& r) |
|
67 : octave_base_value (), range (r) |
|
68 { |
|
69 if (range.nelem () < 0) |
|
70 ::error ("invalid range"); |
|
71 } |
|
72 |
|
73 octave_range (const octave_range& r) |
|
74 : octave_base_value (), range (r.range) { } |
|
75 |
|
76 ~octave_range (void) { } |
|
77 |
3933
|
78 octave_value *clone (void) const { return new octave_range (*this); } |
|
79 octave_value *empty_clone (void) const { return new octave_range (); } |
2376
|
80 |
2410
|
81 type_conv_fcn numeric_conversion_function (void) const; |
|
82 |
|
83 octave_value *try_narrowing_conversion (void); |
2376
|
84 |
4247
|
85 octave_value subsref (const std::string& type, |
4219
|
86 const std::list<octave_value_list>& idx); |
3933
|
87 |
4661
|
88 octave_value_list subsref (const std::string&, |
|
89 const std::list<octave_value_list>&, int) |
4271
|
90 { |
|
91 panic_impossible (); |
|
92 return octave_value_list (); |
|
93 } |
|
94 |
3933
|
95 octave_value do_index_op (const octave_value_list& idx, int resize_ok); |
|
96 |
|
97 octave_value do_index_op (const octave_value_list& idx) |
|
98 { return do_index_op (idx, 0); } |
2436
|
99 |
2376
|
100 idx_vector index_vector (void) const { return idx_vector (range); } |
|
101 |
4563
|
102 dim_vector dims (void) const |
|
103 { |
|
104 int n = range.nelem (); |
|
105 return dim_vector (n > 0, n); |
|
106 } |
3195
|
107 |
4915
|
108 octave_value resize (const dim_vector& dv) const |
|
109 { NDArray retval = array_value (); retval.resize (dv); return retval; } |
|
110 |
4792
|
111 size_t byte_size (void) const { return 3 * sizeof (double); } |
4791
|
112 |
4627
|
113 octave_value reshape (const dim_vector& new_dims) const |
4901
|
114 { return NDArray (array_value().reshape (new_dims)); } |
4627
|
115 |
2376
|
116 bool is_defined (void) const { return true; } |
|
117 |
2974
|
118 bool is_constant (void) const { return true; } |
|
119 |
2376
|
120 bool is_range (void) const { return true; } |
|
121 |
4017
|
122 octave_value all (int dim = 0) const; |
|
123 |
|
124 octave_value any (int dim = 0) const; |
2376
|
125 |
|
126 bool is_real_type (void) const { return true; } |
|
127 |
|
128 bool valid_as_scalar_index (void) const |
|
129 { |
5042
|
130 double b = range.base (); |
2376
|
131 return (range.nelem () == 1 |
5042
|
132 && ! xisnan (b) && D_NINT (b) == b && NINT (b) == 1); |
2376
|
133 } |
|
134 |
|
135 bool valid_as_zero_index (void) const |
|
136 { |
5042
|
137 double b = range.base (); |
2376
|
138 return (range.nelem () == 1 |
5042
|
139 && ! xisnan (b) && D_NINT (b) == b && NINT (b) == 0); |
2376
|
140 } |
|
141 |
3678
|
142 bool is_numeric_type (void) const { return true; } |
|
143 |
2376
|
144 // XXX DO ME XXX |
|
145 bool is_true (void) const; |
|
146 |
3145
|
147 double double_value (bool = false) const; |
2376
|
148 |
3145
|
149 double scalar_value (bool frc_str_conv = false) const |
|
150 { return double_value (frc_str_conv); } |
2916
|
151 |
3145
|
152 Matrix matrix_value (bool = false) const |
2376
|
153 { return range.matrix_value (); } |
|
154 |
4668
|
155 NDArray array_value (bool = false) const |
|
156 { return range.matrix_value (); } |
|
157 |
3145
|
158 Complex complex_value (bool = false) const; |
2376
|
159 |
3145
|
160 ComplexMatrix complex_matrix_value (bool = false) const |
3587
|
161 { return ComplexMatrix (range.matrix_value ()); } |
2376
|
162 |
4668
|
163 ComplexNDArray complex_array_value (bool = false) const |
|
164 { return ComplexMatrix (range.matrix_value ()); } |
|
165 |
2376
|
166 Range range_value (void) const { return range; } |
|
167 |
4457
|
168 octave_value convert_to_str_internal (bool pad, bool force) const; |
2449
|
169 |
3523
|
170 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901
|
171 |
3523
|
172 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901
|
173 |
3523
|
174 bool print_name_tag (std::ostream& os, const std::string& name) const; |
2376
|
175 |
4687
|
176 bool save_ascii (std::ostream& os, bool& infnan_warned, |
|
177 bool strip_nan_and_inf); |
|
178 |
|
179 bool load_ascii (std::istream& is); |
|
180 |
|
181 bool save_binary (std::ostream& os, bool& save_as_floats); |
|
182 |
|
183 bool load_binary (std::istream& is, bool swap, |
|
184 oct_mach_info::float_format fmt); |
|
185 |
|
186 #if defined (HAVE_HDF5) |
|
187 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); |
|
188 |
|
189 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); |
|
190 #endif |
|
191 |
5051
|
192 int write (octave_stream& os, int block_size, |
|
193 oct_data_conv::data_type output_type, int skip, |
|
194 oct_mach_info::float_format flt_fmt) const |
|
195 { |
|
196 // XXX FIXME XXX -- could be more memory efficient by having a |
|
197 // special case of the octave_stream::write method for ranges. |
|
198 |
|
199 return os.write (matrix_value (), block_size, output_type, skip, |
|
200 flt_fmt); |
|
201 } |
|
202 |
2376
|
203 private: |
|
204 |
|
205 Range range; |
|
206 |
4612
|
207 DECLARE_OCTAVE_ALLOCATOR |
2477
|
208 |
4612
|
209 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2376
|
210 }; |
|
211 |
|
212 #endif |
|
213 |
|
214 /* |
|
215 ;;; Local Variables: *** |
|
216 ;;; mode: C++ *** |
|
217 ;;; End: *** |
|
218 */ |