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 (const octave_value_list& obj) |
4150
|
53 : data (obj.data), names (obj.names) { } |
508
|
54 |
4189
|
55 ~octave_value_list (void) { } |
|
56 |
2970
|
57 void *operator new (size_t size) |
|
58 { return allocator.alloc (size); } |
|
59 |
4280
|
60 void operator delete (void *p, size_t size) |
|
61 { allocator.free (p, size); } |
|
62 |
4214
|
63 // XXX FIXME XXX -- without this, I have errors with the stack of |
|
64 // octave_value_list objects in ov-usr-fcn.h. Why? |
|
65 void *operator new (size_t size, void *p) |
|
66 { return ::operator new (size, p); } |
|
67 |
4280
|
68 void operator delete (void *p, void *) |
4352
|
69 { |
|
70 #if defined (HAVE_PLACEMENT_DELETE) |
|
71 ::operator delete (p, static_cast<void *> (0)); |
|
72 #else |
|
73 ::operator delete (p); |
|
74 #endif |
|
75 } |
2970
|
76 |
2086
|
77 octave_value_list& operator = (const octave_value_list& obj) |
508
|
78 { |
1968
|
79 if (this != &obj) |
4150
|
80 { |
|
81 data = obj.data; |
|
82 names = obj.names; |
|
83 } |
1968
|
84 |
508
|
85 return *this; |
|
86 } |
|
87 |
3933
|
88 bool valid_scalar_indices (void) const; |
|
89 |
2872
|
90 // Assignment will resize on range errors. |
508
|
91 |
2086
|
92 octave_value& operator () (int n) { return elem (n); } |
1968
|
93 |
2086
|
94 octave_value operator () (int n) const { return elem (n); } |
526
|
95 |
2872
|
96 int length (void) const { return data.length (); } |
|
97 |
2951
|
98 bool empty (void) const { return length () == 0; } |
|
99 |
2872
|
100 void resize (int n) { data.resize (n); } |
|
101 |
4548
|
102 void resize (int n, const octave_value& val) { data.resize_and_fill (n, val); } |
2872
|
103 |
|
104 octave_value_list& prepend (const octave_value& val); |
|
105 |
|
106 octave_value_list& append (const octave_value& val); |
|
107 |
|
108 octave_value_list& append (const octave_value_list& lst); |
|
109 |
|
110 octave_value_list& reverse (void); |
|
111 |
3195
|
112 octave_value_list splice (int offset, int length, |
|
113 const octave_value_list& lst) const; |
|
114 |
3933
|
115 octave_value_list index (idx_vector& i, int resize_ok = 0) const; |
3219
|
116 |
3932
|
117 octave_value_list& assign (const idx_vector& i, |
4216
|
118 const octave_value_list& rhs, |
|
119 const octave_value& fill_val = octave_value ()); |
3932
|
120 |
2872
|
121 bool all_strings_p (void) const; |
1968
|
122 |
3523
|
123 string_vector make_argv (const std::string&) const; |
526
|
124 |
2943
|
125 void stash_name_tags (const string_vector& nm) { names = nm; } |
|
126 |
|
127 string_vector name_tags (void) const { return names; } |
|
128 |
526
|
129 private: |
508
|
130 |
2970
|
131 static octave_allocator allocator; |
|
132 |
2872
|
133 Array<octave_value> data; |
|
134 |
2943
|
135 // This list of strings can be used to tag each element of data with |
|
136 // a name. By default, it is empty. |
|
137 string_vector names; |
|
138 |
2872
|
139 // This constructor is private with no definition to keep statements |
|
140 // like |
|
141 // |
|
142 // octave_value_list foo = 5; |
|
143 // octave_value_list foo = 5.0; |
|
144 // |
|
145 // from doing different things. Instead, you have to use the |
|
146 // constructor |
|
147 // |
|
148 // octave_value_list (n, val); |
|
149 // |
|
150 // and supply a default value to create a vector-valued |
|
151 // octave_value_list. |
565
|
152 |
2086
|
153 octave_value_list (int n); |
565
|
154 |
3219
|
155 octave_value_list (const Array<octave_value>& d) |
|
156 : data (d) { } |
|
157 |
1968
|
158 void maybe_resize (int n) |
|
159 { |
|
160 if (n >= length ()) |
4548
|
161 data.resize_and_fill (n + 1, Matrix ()); |
1968
|
162 } |
526
|
163 |
2086
|
164 octave_value& elem (int n) |
1968
|
165 { |
|
166 maybe_resize (n); |
2872
|
167 return data.elem (n); |
1968
|
168 } |
|
169 |
2086
|
170 octave_value elem (int n) const |
1968
|
171 { |
2872
|
172 return data.elem (n); |
1968
|
173 } |
508
|
174 }; |
498
|
175 |
504
|
176 #endif |
|
177 |
498
|
178 /* |
|
179 ;;; Local Variables: *** |
|
180 ;;; mode: C++ *** |
|
181 ;;; End: *** |
|
182 */ |