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 |
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 |
|
35 #include "Range.h" |
|
36 |
2889
|
37 #include "lo-mappers.h" |
2376
|
38 #include "lo-utils.h" |
|
39 #include "mx-base.h" |
2477
|
40 #include "oct-alloc.h" |
2376
|
41 #include "str-vec.h" |
|
42 |
|
43 #include "error.h" |
|
44 #include "ov-base.h" |
|
45 #include "ov-typeinfo.h" |
|
46 |
|
47 class Octave_map; |
|
48 class octave_value_list; |
|
49 |
|
50 class tree_walker; |
|
51 |
|
52 // Range values. |
|
53 |
|
54 class |
|
55 octave_range : public octave_base_value |
|
56 { |
|
57 public: |
|
58 |
|
59 octave_range (void) |
|
60 : octave_base_value () { } |
|
61 |
|
62 octave_range (double base, double limit, double inc) |
|
63 : octave_base_value (), range (base, limit, inc) |
|
64 { |
|
65 if (range.nelem () < 0) |
|
66 ::error ("invalid range"); |
|
67 } |
|
68 |
|
69 octave_range (const Range& r) |
|
70 : octave_base_value (), range (r) |
|
71 { |
|
72 if (range.nelem () < 0) |
|
73 ::error ("invalid range"); |
|
74 } |
|
75 |
|
76 octave_range (const octave_range& r) |
|
77 : octave_base_value (), range (r.range) { } |
|
78 |
|
79 ~octave_range (void) { } |
|
80 |
3933
|
81 octave_value *clone (void) const { return new octave_range (*this); } |
|
82 octave_value *empty_clone (void) const { return new octave_range (); } |
2376
|
83 |
2410
|
84 type_conv_fcn numeric_conversion_function (void) const; |
|
85 |
|
86 octave_value *try_narrowing_conversion (void); |
2376
|
87 |
4247
|
88 octave_value subsref (const std::string& type, |
4219
|
89 const std::list<octave_value_list>& idx); |
3933
|
90 |
4661
|
91 octave_value_list subsref (const std::string&, |
|
92 const std::list<octave_value_list>&, int) |
4271
|
93 { |
|
94 panic_impossible (); |
|
95 return octave_value_list (); |
|
96 } |
|
97 |
3933
|
98 octave_value do_index_op (const octave_value_list& idx, int resize_ok); |
|
99 |
|
100 octave_value do_index_op (const octave_value_list& idx) |
|
101 { return do_index_op (idx, 0); } |
2436
|
102 |
2376
|
103 idx_vector index_vector (void) const { return idx_vector (range); } |
|
104 |
4563
|
105 dim_vector dims (void) const |
|
106 { |
|
107 int n = range.nelem (); |
|
108 return dim_vector (n > 0, n); |
|
109 } |
3195
|
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 |
|
114 { return NDArray (matrix_value().reshape (new_dims)); } |
|
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 { |
|
130 return (range.nelem () == 1 |
|
131 && ! xisnan (range.base ()) |
|
132 && NINT (range.base ()) == 1); |
|
133 } |
|
134 |
|
135 bool valid_as_zero_index (void) const |
|
136 { |
|
137 return (range.nelem () == 1 |
|
138 && ! xisnan (range.base ()) |
|
139 && NINT (range.base ()) == 0); |
|
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 |
2376
|
192 private: |
|
193 |
|
194 Range range; |
|
195 |
4612
|
196 DECLARE_OCTAVE_ALLOCATOR |
2477
|
197 |
4612
|
198 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2376
|
199 }; |
|
200 |
|
201 #endif |
|
202 |
|
203 /* |
|
204 ;;; Local Variables: *** |
|
205 ;;; mode: C++ *** |
|
206 ;;; End: *** |
|
207 */ |