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 |
1297
|
26 #if defined (__GNUG__) |
|
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 |
2086
|
61 octave_value_list (const RowVector& v, int pcv) |
2872
|
62 : data (1, octave_value (v, pcv)) { } |
1968
|
63 |
2086
|
64 octave_value_list (const ColumnVector& v, int pcv) |
2872
|
65 : data (1, octave_value (v, pcv)) { } |
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 |
2086
|
76 octave_value_list (const ComplexRowVector& v, int pcv) |
2872
|
77 : data (1, octave_value (v, pcv)) { } |
1968
|
78 |
2086
|
79 octave_value_list (const ComplexColumnVector& v, int pcv) |
2872
|
80 : data (1, octave_value (v, pcv)) { } |
1968
|
81 |
2086
|
82 octave_value_list (const char *s) |
2872
|
83 : data (1, octave_value (s)) { } |
526
|
84 |
2086
|
85 octave_value_list (const 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) |
2872
|
98 : data (obj.data) { } |
508
|
99 |
2970
|
100 void *operator new (size_t size) |
|
101 { return allocator.alloc (size); } |
|
102 |
|
103 void operator delete (void *p, size_t size) |
|
104 { allocator.free (p, size); } |
|
105 |
2086
|
106 octave_value_list& operator = (const octave_value_list& obj) |
508
|
107 { |
1968
|
108 if (this != &obj) |
2872
|
109 data = obj.data; |
1968
|
110 |
508
|
111 return *this; |
|
112 } |
|
113 |
2872
|
114 // Assignment will resize on range errors. |
508
|
115 |
2086
|
116 octave_value& operator () (int n) { return elem (n); } |
1968
|
117 |
2086
|
118 octave_value operator () (int n) const { return elem (n); } |
526
|
119 |
2872
|
120 int length (void) const { return data.length (); } |
|
121 |
2951
|
122 bool empty (void) const { return length () == 0; } |
|
123 |
2872
|
124 void resize (int n) { data.resize (n); } |
|
125 |
|
126 void resize (int n, const octave_value& val) { data.resize (n, val); } |
|
127 |
|
128 octave_value_list& prepend (const octave_value& val); |
|
129 |
|
130 octave_value_list& append (const octave_value& val); |
|
131 |
|
132 octave_value_list& append (const octave_value_list& lst); |
|
133 |
|
134 octave_value_list& reverse (void); |
|
135 |
3195
|
136 octave_value_list splice (int offset, int length, |
|
137 const octave_value_list& lst) const; |
|
138 |
2872
|
139 bool all_strings_p (void) const; |
1968
|
140 |
|
141 string_vector make_argv (const string&) const; |
526
|
142 |
2943
|
143 void stash_name_tags (const string_vector& nm) { names = nm; } |
|
144 |
|
145 string_vector name_tags (void) const { return names; } |
|
146 |
526
|
147 private: |
508
|
148 |
2970
|
149 static octave_allocator allocator; |
|
150 |
2872
|
151 Array<octave_value> data; |
|
152 |
2943
|
153 // This list of strings can be used to tag each element of data with |
|
154 // a name. By default, it is empty. |
|
155 string_vector names; |
|
156 |
2872
|
157 // This constructor is private with no definition to keep statements |
|
158 // like |
|
159 // |
|
160 // octave_value_list foo = 5; |
|
161 // octave_value_list foo = 5.0; |
|
162 // |
|
163 // from doing different things. Instead, you have to use the |
|
164 // constructor |
|
165 // |
|
166 // octave_value_list (n, val); |
|
167 // |
|
168 // and supply a default value to create a vector-valued |
|
169 // octave_value_list. |
565
|
170 |
2086
|
171 octave_value_list (int n); |
565
|
172 |
1968
|
173 void maybe_resize (int n) |
|
174 { |
|
175 if (n >= length ()) |
2872
|
176 data.resize (n + 1, Matrix ()); |
1968
|
177 } |
526
|
178 |
2086
|
179 octave_value& elem (int n) |
1968
|
180 { |
|
181 maybe_resize (n); |
2872
|
182 return data.elem (n); |
1968
|
183 } |
|
184 |
2086
|
185 octave_value elem (int n) const |
1968
|
186 { |
2872
|
187 return data.elem (n); |
1968
|
188 } |
508
|
189 }; |
498
|
190 |
504
|
191 #endif |
|
192 |
498
|
193 /* |
|
194 ;;; Local Variables: *** |
|
195 ;;; mode: C++ *** |
|
196 ;;; End: *** |
|
197 */ |