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" |
2943
|
33 #include "str-vec.h" |
498
|
34 |
2369
|
35 #include "ov.h" |
498
|
36 |
737
|
37 class |
2872
|
38 octave_value_list |
508
|
39 { |
|
40 public: |
|
41 |
2086
|
42 octave_value_list (void) |
2872
|
43 : data () { } |
1968
|
44 |
2086
|
45 octave_value_list (int n, const octave_value& val) |
2872
|
46 : data (n, val) { } |
511
|
47 |
2086
|
48 octave_value_list (const octave_value& tc) |
2872
|
49 : data (1, tc) { } |
1968
|
50 |
2086
|
51 octave_value_list (double d) |
2872
|
52 : data (1, octave_value (d)) { } |
1968
|
53 |
2086
|
54 octave_value_list (const Matrix& m) |
2872
|
55 : data (1, octave_value (m)) { } |
1968
|
56 |
2086
|
57 octave_value_list (const DiagMatrix& d) |
2872
|
58 : data (1, octave_value (d)) { } |
526
|
59 |
2086
|
60 octave_value_list (const RowVector& v, int pcv) |
2872
|
61 : data (1, octave_value (v, pcv)) { } |
1968
|
62 |
2086
|
63 octave_value_list (const ColumnVector& v, int pcv) |
2872
|
64 : data (1, octave_value (v, pcv)) { } |
1968
|
65 |
2086
|
66 octave_value_list (const Complex& c) |
2872
|
67 : data (1, octave_value (c)) { } |
1968
|
68 |
2086
|
69 octave_value_list (const ComplexMatrix& m) |
2872
|
70 : data (1, octave_value (m)) { } |
526
|
71 |
2086
|
72 octave_value_list (const ComplexDiagMatrix& d) |
2872
|
73 : data (1, octave_value (d)) { } |
1968
|
74 |
2086
|
75 octave_value_list (const ComplexRowVector& v, int pcv) |
2872
|
76 : data (1, octave_value (v, pcv)) { } |
1968
|
77 |
2086
|
78 octave_value_list (const ComplexColumnVector& v, int pcv) |
2872
|
79 : data (1, octave_value (v, pcv)) { } |
1968
|
80 |
2086
|
81 octave_value_list (const char *s) |
2872
|
82 : data (1, octave_value (s)) { } |
526
|
83 |
2086
|
84 octave_value_list (const string& s) |
2872
|
85 : data (1, octave_value (s)) { } |
1968
|
86 |
2086
|
87 octave_value_list (const string_vector& s) |
2872
|
88 : data (1, octave_value (s)) { } |
526
|
89 |
2086
|
90 octave_value_list (double base, double limit, double inc) |
2872
|
91 : data (1, octave_value (base, limit, inc)) { } |
526
|
92 |
2086
|
93 octave_value_list (const Range& r) |
2872
|
94 : data (1, octave_value (r)) { } |
1968
|
95 |
2086
|
96 octave_value_list (const octave_value_list& obj) |
2872
|
97 : data (obj.data) { } |
508
|
98 |
2086
|
99 octave_value_list& operator = (const octave_value_list& obj) |
508
|
100 { |
1968
|
101 if (this != &obj) |
2872
|
102 data = obj.data; |
1968
|
103 |
508
|
104 return *this; |
|
105 } |
|
106 |
2872
|
107 // Assignment will resize on range errors. |
508
|
108 |
2086
|
109 octave_value& operator () (int n) { return elem (n); } |
1968
|
110 |
2086
|
111 octave_value operator () (int n) const { return elem (n); } |
526
|
112 |
2872
|
113 int length (void) const { return data.length (); } |
|
114 |
|
115 void resize (int n) { data.resize (n); } |
|
116 |
|
117 void resize (int n, const octave_value& val) { data.resize (n, val); } |
|
118 |
|
119 octave_value_list& prepend (const octave_value& val); |
|
120 |
|
121 octave_value_list& append (const octave_value& val); |
|
122 |
|
123 octave_value_list& append (const octave_value_list& lst); |
|
124 |
|
125 octave_value_list& reverse (void); |
|
126 |
|
127 bool all_strings_p (void) const; |
1968
|
128 |
|
129 string_vector make_argv (const string&) const; |
526
|
130 |
2943
|
131 void stash_name_tags (const string_vector& nm) { names = nm; } |
|
132 |
|
133 string_vector name_tags (void) const { return names; } |
|
134 |
526
|
135 private: |
508
|
136 |
2872
|
137 Array<octave_value> data; |
|
138 |
2943
|
139 // This list of strings can be used to tag each element of data with |
|
140 // a name. By default, it is empty. |
|
141 string_vector names; |
|
142 |
2872
|
143 // This constructor is private with no definition to keep statements |
|
144 // like |
|
145 // |
|
146 // octave_value_list foo = 5; |
|
147 // octave_value_list foo = 5.0; |
|
148 // |
|
149 // from doing different things. Instead, you have to use the |
|
150 // constructor |
|
151 // |
|
152 // octave_value_list (n, val); |
|
153 // |
|
154 // and supply a default value to create a vector-valued |
|
155 // octave_value_list. |
565
|
156 |
2086
|
157 octave_value_list (int n); |
565
|
158 |
1968
|
159 void maybe_resize (int n) |
|
160 { |
|
161 if (n >= length ()) |
2872
|
162 data.resize (n + 1, Matrix ()); |
1968
|
163 } |
526
|
164 |
2086
|
165 octave_value& elem (int n) |
1968
|
166 { |
|
167 maybe_resize (n); |
2872
|
168 return data.elem (n); |
1968
|
169 } |
|
170 |
2086
|
171 octave_value elem (int n) const |
1968
|
172 { |
2872
|
173 return data.elem (n); |
1968
|
174 } |
508
|
175 }; |
498
|
176 |
504
|
177 #endif |
|
178 |
498
|
179 /* |
|
180 ;;; Local Variables: *** |
|
181 ;;; mode: C++ *** |
|
182 ;;; End: *** |
|
183 */ |