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> |
4591
|
31 #include <vector> |
1968
|
32 |
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 |
4591
|
96 int length (void) const { return data.size (); } |
2872
|
97 |
2951
|
98 bool empty (void) const { return length () == 0; } |
|
99 |
2872
|
100 void resize (int n) { data.resize (n); } |
|
101 |
4591
|
102 void resize (int n, const octave_value& 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 |
2872
|
115 bool all_strings_p (void) const; |
1968
|
116 |
3523
|
117 string_vector make_argv (const std::string&) const; |
526
|
118 |
2943
|
119 void stash_name_tags (const string_vector& nm) { names = nm; } |
|
120 |
|
121 string_vector name_tags (void) const { return names; } |
|
122 |
526
|
123 private: |
508
|
124 |
2970
|
125 static octave_allocator allocator; |
|
126 |
4591
|
127 std::vector<octave_value> data; |
2872
|
128 |
2943
|
129 // This list of strings can be used to tag each element of data with |
|
130 // a name. By default, it is empty. |
|
131 string_vector names; |
|
132 |
2872
|
133 // This constructor is private with no definition to keep statements |
|
134 // like |
|
135 // |
|
136 // octave_value_list foo = 5; |
|
137 // octave_value_list foo = 5.0; |
|
138 // |
|
139 // from doing different things. Instead, you have to use the |
|
140 // constructor |
|
141 // |
|
142 // octave_value_list (n, val); |
|
143 // |
|
144 // and supply a default value to create a vector-valued |
|
145 // octave_value_list. |
565
|
146 |
2086
|
147 octave_value_list (int n); |
565
|
148 |
4591
|
149 octave_value_list (const Array<octave_value>& d); |
526
|
150 |
2086
|
151 octave_value& elem (int n) |
1968
|
152 { |
4591
|
153 static Matrix empty_matrix; |
|
154 |
|
155 if (n >= length ()) |
|
156 resize (n+1, empty_matrix); |
|
157 |
|
158 return data[n]; |
1968
|
159 } |
|
160 |
2086
|
161 octave_value elem (int n) const |
1968
|
162 { |
4591
|
163 #if defined (BOUNDS_CHECKING) |
|
164 return data.at (n); |
|
165 #else |
|
166 return data[n]; |
|
167 #endif |
1968
|
168 } |
508
|
169 }; |
498
|
170 |
504
|
171 #endif |
|
172 |
498
|
173 /* |
|
174 ;;; Local Variables: *** |
|
175 ;;; mode: C++ *** |
|
176 ;;; End: *** |
|
177 */ |