498
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
498
|
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 |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
498
|
20 |
|
21 */ |
|
22 |
504
|
23 #if !defined (octave_oct_obj_h) |
|
24 #define octave_oct_obj_h 1 |
|
25 |
4192
|
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
1297
|
27 #pragma interface |
|
28 #endif |
|
29 |
1968
|
30 #include <string> |
|
31 |
498
|
32 #include "Array.h" |
2970
|
33 #include "oct-alloc.h" |
2943
|
34 #include "str-vec.h" |
498
|
35 |
2369
|
36 #include "ov.h" |
498
|
37 |
737
|
38 class |
2872
|
39 octave_value_list |
508
|
40 { |
|
41 public: |
|
42 |
2086
|
43 octave_value_list (void) |
2872
|
44 : data () { } |
1968
|
45 |
2086
|
46 octave_value_list (int n, const octave_value& val) |
2872
|
47 : data (n, val) { } |
511
|
48 |
2086
|
49 octave_value_list (const octave_value& tc) |
2872
|
50 : data (1, tc) { } |
1968
|
51 |
2086
|
52 octave_value_list (double d) |
2872
|
53 : data (1, octave_value (d)) { } |
1968
|
54 |
2086
|
55 octave_value_list (const Matrix& m) |
2872
|
56 : data (1, octave_value (m)) { } |
1968
|
57 |
2086
|
58 octave_value_list (const DiagMatrix& d) |
2872
|
59 : data (1, octave_value (d)) { } |
526
|
60 |
3418
|
61 octave_value_list (const RowVector& v) |
|
62 : data (1, octave_value (v)) { } |
1968
|
63 |
3418
|
64 octave_value_list (const ColumnVector& v) |
|
65 : data (1, octave_value (v)) { } |
1968
|
66 |
2086
|
67 octave_value_list (const Complex& c) |
2872
|
68 : data (1, octave_value (c)) { } |
1968
|
69 |
2086
|
70 octave_value_list (const ComplexMatrix& m) |
2872
|
71 : data (1, octave_value (m)) { } |
526
|
72 |
2086
|
73 octave_value_list (const ComplexDiagMatrix& d) |
2872
|
74 : data (1, octave_value (d)) { } |
1968
|
75 |
3418
|
76 octave_value_list (const ComplexRowVector& v) |
|
77 : data (1, octave_value (v)) { } |
1968
|
78 |
3418
|
79 octave_value_list (const ComplexColumnVector& v) |
|
80 : data (1, octave_value (v)) { } |
1968
|
81 |
2086
|
82 octave_value_list (const char *s) |
2872
|
83 : data (1, octave_value (s)) { } |
526
|
84 |
3523
|
85 octave_value_list (const std::string& s) |
2872
|
86 : data (1, octave_value (s)) { } |
1968
|
87 |
2086
|
88 octave_value_list (const string_vector& s) |
2872
|
89 : data (1, octave_value (s)) { } |
526
|
90 |
2086
|
91 octave_value_list (double base, double limit, double inc) |
2872
|
92 : data (1, octave_value (base, limit, inc)) { } |
526
|
93 |
2086
|
94 octave_value_list (const Range& r) |
2872
|
95 : data (1, octave_value (r)) { } |
1968
|
96 |
2086
|
97 octave_value_list (const octave_value_list& obj) |
4150
|
98 : data (obj.data), names (obj.names) { } |
508
|
99 |
4189
|
100 ~octave_value_list (void) { } |
|
101 |
2970
|
102 void *operator new (size_t size) |
|
103 { return allocator.alloc (size); } |
|
104 |
4214
|
105 // XXX FIXME XXX -- without this, I have errors with the stack of |
|
106 // octave_value_list objects in ov-usr-fcn.h. Why? |
|
107 void *operator new (size_t size, void *p) |
|
108 { return ::operator new (size, p); } |
|
109 |
2970
|
110 void operator delete (void *p, size_t size) |
|
111 { allocator.free (p, size); } |
|
112 |
2086
|
113 octave_value_list& operator = (const octave_value_list& obj) |
508
|
114 { |
1968
|
115 if (this != &obj) |
4150
|
116 { |
|
117 data = obj.data; |
|
118 names = obj.names; |
|
119 } |
1968
|
120 |
508
|
121 return *this; |
|
122 } |
|
123 |
3933
|
124 bool valid_scalar_indices (void) const; |
|
125 |
2872
|
126 // Assignment will resize on range errors. |
508
|
127 |
2086
|
128 octave_value& operator () (int n) { return elem (n); } |
1968
|
129 |
2086
|
130 octave_value operator () (int n) const { return elem (n); } |
526
|
131 |
2872
|
132 int length (void) const { return data.length (); } |
|
133 |
2951
|
134 bool empty (void) const { return length () == 0; } |
|
135 |
2872
|
136 void resize (int n) { data.resize (n); } |
|
137 |
|
138 void resize (int n, const octave_value& val) { data.resize (n, val); } |
|
139 |
|
140 octave_value_list& prepend (const octave_value& val); |
|
141 |
|
142 octave_value_list& append (const octave_value& val); |
|
143 |
|
144 octave_value_list& append (const octave_value_list& lst); |
|
145 |
|
146 octave_value_list& reverse (void); |
|
147 |
3195
|
148 octave_value_list splice (int offset, int length, |
|
149 const octave_value_list& lst) const; |
|
150 |
3933
|
151 octave_value_list index (idx_vector& i, int resize_ok = 0) const; |
3219
|
152 |
3932
|
153 octave_value_list& assign (const idx_vector& i, |
|
154 const octave_value_list& rhs); |
|
155 |
2872
|
156 bool all_strings_p (void) const; |
1968
|
157 |
3523
|
158 string_vector make_argv (const std::string&) const; |
526
|
159 |
2943
|
160 void stash_name_tags (const string_vector& nm) { names = nm; } |
|
161 |
|
162 string_vector name_tags (void) const { return names; } |
|
163 |
526
|
164 private: |
508
|
165 |
2970
|
166 static octave_allocator allocator; |
|
167 |
2872
|
168 Array<octave_value> data; |
|
169 |
2943
|
170 // This list of strings can be used to tag each element of data with |
|
171 // a name. By default, it is empty. |
|
172 string_vector names; |
|
173 |
2872
|
174 // This constructor is private with no definition to keep statements |
|
175 // like |
|
176 // |
|
177 // octave_value_list foo = 5; |
|
178 // octave_value_list foo = 5.0; |
|
179 // |
|
180 // from doing different things. Instead, you have to use the |
|
181 // constructor |
|
182 // |
|
183 // octave_value_list (n, val); |
|
184 // |
|
185 // and supply a default value to create a vector-valued |
|
186 // octave_value_list. |
565
|
187 |
2086
|
188 octave_value_list (int n); |
565
|
189 |
3219
|
190 octave_value_list (const Array<octave_value>& d) |
|
191 : data (d) { } |
|
192 |
1968
|
193 void maybe_resize (int n) |
|
194 { |
|
195 if (n >= length ()) |
2872
|
196 data.resize (n + 1, Matrix ()); |
1968
|
197 } |
526
|
198 |
2086
|
199 octave_value& elem (int n) |
1968
|
200 { |
|
201 maybe_resize (n); |
2872
|
202 return data.elem (n); |
1968
|
203 } |
|
204 |
2086
|
205 octave_value elem (int n) const |
1968
|
206 { |
2872
|
207 return data.elem (n); |
1968
|
208 } |
508
|
209 }; |
498
|
210 |
504
|
211 #endif |
|
212 |
498
|
213 /* |
|
214 ;;; Local Variables: *** |
|
215 ;;; mode: C++ *** |
|
216 ;;; End: *** |
|
217 */ |