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 |
|
32 #include <string> |
|
33 |
|
34 class ostream; |
|
35 |
|
36 #include "Range.h" |
|
37 |
2889
|
38 #include "lo-mappers.h" |
2376
|
39 #include "lo-utils.h" |
|
40 #include "mx-base.h" |
2477
|
41 #include "oct-alloc.h" |
2376
|
42 #include "str-vec.h" |
|
43 |
|
44 #include "error.h" |
|
45 #include "ov-base.h" |
|
46 #include "ov-typeinfo.h" |
|
47 |
|
48 class Octave_map; |
|
49 class octave_value_list; |
|
50 |
|
51 class tree_walker; |
|
52 |
|
53 // Range values. |
|
54 |
|
55 class |
|
56 octave_range : public octave_base_value |
|
57 { |
|
58 public: |
|
59 |
|
60 octave_range (void) |
|
61 : octave_base_value () { } |
|
62 |
|
63 octave_range (double base, double limit, double inc) |
|
64 : octave_base_value (), range (base, limit, inc) |
|
65 { |
|
66 if (range.nelem () < 0) |
|
67 ::error ("invalid range"); |
|
68 } |
|
69 |
|
70 octave_range (const Range& r) |
|
71 : octave_base_value (), range (r) |
|
72 { |
|
73 if (range.nelem () < 0) |
|
74 ::error ("invalid range"); |
|
75 } |
|
76 |
|
77 octave_range (const octave_range& r) |
|
78 : octave_base_value (), range (r.range) { } |
|
79 |
|
80 ~octave_range (void) { } |
|
81 |
|
82 octave_value *clone (void) { return new octave_range (*this); } |
|
83 |
2477
|
84 void *operator new (size_t size) |
|
85 { return allocator.alloc (size); } |
|
86 |
|
87 void operator delete (void *p, size_t size) |
|
88 { allocator.free (p, size); } |
2376
|
89 |
2410
|
90 type_conv_fcn numeric_conversion_function (void) const; |
|
91 |
|
92 octave_value *try_narrowing_conversion (void); |
2376
|
93 |
2974
|
94 octave_value do_index_op (const octave_value_list& idx); |
2436
|
95 |
2376
|
96 idx_vector index_vector (void) const { return idx_vector (range); } |
|
97 |
|
98 int rows (void) const { return (columns () > 0); } |
|
99 int columns (void) const { return range.nelem (); } |
|
100 |
|
101 bool is_defined (void) const { return true; } |
|
102 |
2974
|
103 bool is_constant (void) const { return true; } |
|
104 |
2376
|
105 bool is_range (void) const { return true; } |
|
106 |
|
107 // XXX DO ME XXX |
|
108 octave_value all (void) const; |
|
109 octave_value any (void) const; |
|
110 |
|
111 bool is_real_type (void) const { return true; } |
|
112 |
|
113 bool valid_as_scalar_index (void) const |
|
114 { |
|
115 return (range.nelem () == 1 |
|
116 && ! xisnan (range.base ()) |
|
117 && NINT (range.base ()) == 1); |
|
118 } |
|
119 |
|
120 bool valid_as_zero_index (void) const |
|
121 { |
|
122 return (range.nelem () == 1 |
|
123 && ! xisnan (range.base ()) |
|
124 && NINT (range.base ()) == 0); |
|
125 } |
|
126 |
|
127 // XXX DO ME XXX |
|
128 bool is_true (void) const; |
|
129 |
|
130 double double_value (bool) const; |
|
131 |
2916
|
132 double scalar_value (bool) const { return double_value (); } |
|
133 |
2376
|
134 Matrix matrix_value (bool) const |
|
135 { return range.matrix_value (); } |
|
136 |
|
137 Complex complex_value (bool) const; |
|
138 |
|
139 ComplexMatrix complex_matrix_value (bool) const |
|
140 { return range.matrix_value (); } |
|
141 |
|
142 Range range_value (void) const { return range; } |
|
143 |
2599
|
144 octave_value not (void) const; |
|
145 |
|
146 octave_value uminus (void) const { return octave_value (- range); } |
|
147 |
2376
|
148 octave_value transpose (void) const; |
|
149 |
|
150 octave_value hermitian (void) const; |
|
151 |
2449
|
152 octave_value convert_to_str (void) const; |
|
153 |
2901
|
154 void print (ostream& os, bool pr_as_read_syntax = false) const; |
|
155 |
|
156 void print_raw (ostream& os, bool pr_as_read_syntax = false) const; |
|
157 |
|
158 bool print_name_tag (ostream& os, const string& name) const; |
2376
|
159 |
|
160 int type_id (void) const { return t_id; } |
|
161 |
|
162 string type_name (void) const { return t_name; } |
|
163 |
|
164 static int static_type_id (void) { return t_id; } |
|
165 |
|
166 static void register_type (void) |
|
167 { t_id = octave_value_typeinfo::register_type (t_name); } |
|
168 |
|
169 private: |
|
170 |
|
171 Range range; |
|
172 |
2477
|
173 static octave_allocator allocator; |
|
174 |
|
175 // Type id of range objects, set by register_type (). |
2376
|
176 static int t_id; |
|
177 |
2477
|
178 // Type name of scalar objects, defined in ov-range.cc. |
2376
|
179 static const string t_name; |
|
180 }; |
|
181 |
|
182 #endif |
|
183 |
|
184 /* |
|
185 ;;; Local Variables: *** |
|
186 ;;; mode: C++ *** |
|
187 ;;; End: *** |
|
188 */ |