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 #if defined (__GNUG__) |
|
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 |
|
81 octave_value *clone (void) { return new octave_range (*this); } |
|
82 |
2410
|
83 type_conv_fcn numeric_conversion_function (void) const; |
|
84 |
|
85 octave_value *try_narrowing_conversion (void); |
2376
|
86 |
2974
|
87 octave_value do_index_op (const octave_value_list& idx); |
2436
|
88 |
2376
|
89 idx_vector index_vector (void) const { return idx_vector (range); } |
|
90 |
|
91 int rows (void) const { return (columns () > 0); } |
|
92 int columns (void) const { return range.nelem (); } |
|
93 |
3195
|
94 int length (void) const { return range.nelem (); } |
|
95 |
2376
|
96 bool is_defined (void) const { return true; } |
|
97 |
2974
|
98 bool is_constant (void) const { return true; } |
|
99 |
2376
|
100 bool is_range (void) const { return true; } |
|
101 |
|
102 // XXX DO ME XXX |
|
103 octave_value all (void) const; |
|
104 octave_value any (void) const; |
|
105 |
|
106 bool is_real_type (void) const { return true; } |
|
107 |
|
108 bool valid_as_scalar_index (void) const |
|
109 { |
|
110 return (range.nelem () == 1 |
|
111 && ! xisnan (range.base ()) |
|
112 && NINT (range.base ()) == 1); |
|
113 } |
|
114 |
|
115 bool valid_as_zero_index (void) const |
|
116 { |
|
117 return (range.nelem () == 1 |
|
118 && ! xisnan (range.base ()) |
|
119 && NINT (range.base ()) == 0); |
|
120 } |
|
121 |
|
122 // XXX DO ME XXX |
|
123 bool is_true (void) const; |
|
124 |
3145
|
125 double double_value (bool = false) const; |
2376
|
126 |
3145
|
127 double scalar_value (bool frc_str_conv = false) const |
|
128 { return double_value (frc_str_conv); } |
2916
|
129 |
3145
|
130 Matrix matrix_value (bool = false) const |
2376
|
131 { return range.matrix_value (); } |
|
132 |
3145
|
133 Complex complex_value (bool = false) const; |
2376
|
134 |
3145
|
135 ComplexMatrix complex_matrix_value (bool = false) const |
3587
|
136 { return ComplexMatrix (range.matrix_value ()); } |
2376
|
137 |
|
138 Range range_value (void) const { return range; } |
|
139 |
2449
|
140 octave_value convert_to_str (void) const; |
|
141 |
3523
|
142 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901
|
143 |
3523
|
144 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901
|
145 |
3523
|
146 bool print_name_tag (std::ostream& os, const std::string& name) const; |
2376
|
147 |
|
148 private: |
|
149 |
|
150 Range range; |
|
151 |
3219
|
152 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2477
|
153 |
3219
|
154 DECLARE_OCTAVE_ALLOCATOR |
2376
|
155 }; |
|
156 |
|
157 #endif |
|
158 |
|
159 /* |
|
160 ;;; Local Variables: *** |
|
161 ;;; mode: C++ *** |
|
162 ;;; End: *** |
|
163 */ |