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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
498
|
21 |
|
22 */ |
|
23 |
504
|
24 #if !defined (octave_oct_obj_h) |
|
25 #define octave_oct_obj_h 1 |
|
26 |
1968
|
27 #include <string> |
4591
|
28 #include <vector> |
1968
|
29 |
2970
|
30 #include "oct-alloc.h" |
2943
|
31 #include "str-vec.h" |
498
|
32 |
2369
|
33 #include "ov.h" |
498
|
34 |
737
|
35 class |
2872
|
36 octave_value_list |
508
|
37 { |
|
38 public: |
|
39 |
2086
|
40 octave_value_list (void) |
2872
|
41 : data () { } |
1968
|
42 |
5275
|
43 octave_value_list (octave_idx_type n, const octave_value& val) |
2872
|
44 : data (n, val) { } |
511
|
45 |
2086
|
46 octave_value_list (const octave_value& tc) |
2872
|
47 : data (1, tc) { } |
1968
|
48 |
2086
|
49 octave_value_list (const octave_value_list& obj) |
4150
|
50 : data (obj.data), names (obj.names) { } |
508
|
51 |
4189
|
52 ~octave_value_list (void) { } |
|
53 |
2970
|
54 void *operator new (size_t size) |
|
55 { return allocator.alloc (size); } |
|
56 |
4280
|
57 void operator delete (void *p, size_t size) |
|
58 { allocator.free (p, size); } |
|
59 |
5775
|
60 // FIXME -- without this, I have errors with the stack of |
4214
|
61 // octave_value_list objects in ov-usr-fcn.h. Why? |
|
62 void *operator new (size_t size, void *p) |
|
63 { return ::operator new (size, p); } |
|
64 |
4280
|
65 void operator delete (void *p, void *) |
4352
|
66 { |
|
67 #if defined (HAVE_PLACEMENT_DELETE) |
|
68 ::operator delete (p, static_cast<void *> (0)); |
|
69 #else |
|
70 ::operator delete (p); |
|
71 #endif |
|
72 } |
2970
|
73 |
2086
|
74 octave_value_list& operator = (const octave_value_list& obj) |
508
|
75 { |
1968
|
76 if (this != &obj) |
4150
|
77 { |
|
78 data = obj.data; |
|
79 names = obj.names; |
|
80 } |
1968
|
81 |
508
|
82 return *this; |
|
83 } |
|
84 |
3933
|
85 bool valid_scalar_indices (void) const; |
|
86 |
2872
|
87 // Assignment will resize on range errors. |
508
|
88 |
5275
|
89 octave_value& operator () (octave_idx_type n) { return elem (n); } |
1968
|
90 |
5275
|
91 octave_value operator () (octave_idx_type n) const { return elem (n); } |
526
|
92 |
5275
|
93 octave_idx_type length (void) const { return data.size (); } |
2872
|
94 |
2951
|
95 bool empty (void) const { return length () == 0; } |
|
96 |
5275
|
97 void resize (octave_idx_type n) { data.resize (n); } |
2872
|
98 |
5275
|
99 void resize (octave_idx_type n, const octave_value& val); |
2872
|
100 |
|
101 octave_value_list& prepend (const octave_value& val); |
|
102 |
|
103 octave_value_list& append (const octave_value& val); |
|
104 |
|
105 octave_value_list& append (const octave_value_list& lst); |
|
106 |
|
107 octave_value_list& reverse (void); |
|
108 |
5275
|
109 octave_value_list splice (octave_idx_type offset, octave_idx_type length, |
3195
|
110 const octave_value_list& lst) const; |
|
111 |
2872
|
112 bool all_strings_p (void) const; |
1968
|
113 |
3523
|
114 string_vector make_argv (const std::string&) const; |
526
|
115 |
2943
|
116 void stash_name_tags (const string_vector& nm) { names = nm; } |
|
117 |
|
118 string_vector name_tags (void) const { return names; } |
|
119 |
526
|
120 private: |
508
|
121 |
2970
|
122 static octave_allocator allocator; |
|
123 |
4591
|
124 std::vector<octave_value> data; |
2872
|
125 |
2943
|
126 // This list of strings can be used to tag each element of data with |
|
127 // a name. By default, it is empty. |
|
128 string_vector names; |
|
129 |
2872
|
130 // This constructor is private with no definition to keep statements |
|
131 // like |
|
132 // |
|
133 // octave_value_list foo = 5; |
|
134 // octave_value_list foo = 5.0; |
|
135 // |
|
136 // from doing different things. Instead, you have to use the |
|
137 // constructor |
|
138 // |
|
139 // octave_value_list (n, val); |
|
140 // |
|
141 // and supply a default value to create a vector-valued |
|
142 // octave_value_list. |
565
|
143 |
5275
|
144 octave_value_list (octave_idx_type n); |
565
|
145 |
4591
|
146 octave_value_list (const Array<octave_value>& d); |
526
|
147 |
5275
|
148 octave_value& elem (octave_idx_type n) |
1968
|
149 { |
4591
|
150 static Matrix empty_matrix; |
|
151 |
|
152 if (n >= length ()) |
|
153 resize (n+1, empty_matrix); |
|
154 |
|
155 return data[n]; |
1968
|
156 } |
|
157 |
5275
|
158 octave_value elem (octave_idx_type n) const |
1968
|
159 { |
4591
|
160 #if defined (BOUNDS_CHECKING) |
|
161 return data.at (n); |
|
162 #else |
|
163 return data[n]; |
|
164 #endif |
1968
|
165 } |
508
|
166 }; |
498
|
167 |
504
|
168 #endif |
|
169 |
498
|
170 /* |
|
171 ;;; Local Variables: *** |
|
172 ;;; mode: C++ *** |
|
173 ;;; End: *** |
|
174 */ |