498
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2002, 2003, 2004, |
|
4 2005, 2006, 2007 John W. Eaton |
498
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
498
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
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 |
6109
|
36 OCTINTERP_API |
2872
|
37 octave_value_list |
508
|
38 { |
|
39 public: |
|
40 |
2086
|
41 octave_value_list (void) |
2872
|
42 : data () { } |
1968
|
43 |
5275
|
44 octave_value_list (octave_idx_type n, const octave_value& val) |
2872
|
45 : data (n, val) { } |
511
|
46 |
2086
|
47 octave_value_list (const octave_value& tc) |
2872
|
48 : data (1, tc) { } |
1968
|
49 |
2086
|
50 octave_value_list (const octave_value_list& obj) |
4150
|
51 : data (obj.data), names (obj.names) { } |
508
|
52 |
4189
|
53 ~octave_value_list (void) { } |
|
54 |
2970
|
55 void *operator new (size_t size) |
|
56 { return allocator.alloc (size); } |
|
57 |
4280
|
58 void operator delete (void *p, size_t size) |
|
59 { allocator.free (p, size); } |
|
60 |
5775
|
61 // FIXME -- without this, I have errors with the stack of |
4214
|
62 // octave_value_list objects in ov-usr-fcn.h. Why? |
|
63 void *operator new (size_t size, void *p) |
|
64 { return ::operator new (size, p); } |
|
65 |
4280
|
66 void operator delete (void *p, void *) |
4352
|
67 { |
|
68 #if defined (HAVE_PLACEMENT_DELETE) |
|
69 ::operator delete (p, static_cast<void *> (0)); |
|
70 #else |
|
71 ::operator delete (p); |
|
72 #endif |
|
73 } |
2970
|
74 |
2086
|
75 octave_value_list& operator = (const octave_value_list& obj) |
508
|
76 { |
1968
|
77 if (this != &obj) |
4150
|
78 { |
|
79 data = obj.data; |
|
80 names = obj.names; |
|
81 } |
1968
|
82 |
508
|
83 return *this; |
|
84 } |
|
85 |
3933
|
86 bool valid_scalar_indices (void) const; |
|
87 |
2872
|
88 // Assignment will resize on range errors. |
508
|
89 |
5275
|
90 octave_value& operator () (octave_idx_type n) { return elem (n); } |
1968
|
91 |
5275
|
92 octave_value operator () (octave_idx_type n) const { return elem (n); } |
526
|
93 |
5275
|
94 octave_idx_type length (void) const { return data.size (); } |
2872
|
95 |
2951
|
96 bool empty (void) const { return length () == 0; } |
|
97 |
5275
|
98 void resize (octave_idx_type n) { data.resize (n); } |
2872
|
99 |
5275
|
100 void resize (octave_idx_type n, const octave_value& val); |
2872
|
101 |
|
102 octave_value_list& prepend (const octave_value& val); |
|
103 |
|
104 octave_value_list& append (const octave_value& val); |
|
105 |
|
106 octave_value_list& append (const octave_value_list& lst); |
|
107 |
|
108 octave_value_list& reverse (void); |
|
109 |
6335
|
110 octave_value_list |
|
111 splice (octave_idx_type offset, octave_idx_type len, |
|
112 const octave_value_list& lst = octave_value_list ()) const; |
3195
|
113 |
2872
|
114 bool all_strings_p (void) const; |
1968
|
115 |
5846
|
116 bool has_magic_colon (void) const; |
|
117 |
3523
|
118 string_vector make_argv (const std::string&) const; |
526
|
119 |
2943
|
120 void stash_name_tags (const string_vector& nm) { names = nm; } |
|
121 |
|
122 string_vector name_tags (void) const { return names; } |
|
123 |
526
|
124 private: |
508
|
125 |
2970
|
126 static octave_allocator allocator; |
|
127 |
4591
|
128 std::vector<octave_value> data; |
2872
|
129 |
2943
|
130 // This list of strings can be used to tag each element of data with |
|
131 // a name. By default, it is empty. |
|
132 string_vector names; |
|
133 |
2872
|
134 // This constructor is private with no definition to keep statements |
|
135 // like |
|
136 // |
|
137 // octave_value_list foo = 5; |
|
138 // octave_value_list foo = 5.0; |
|
139 // |
|
140 // from doing different things. Instead, you have to use the |
|
141 // constructor |
|
142 // |
|
143 // octave_value_list (n, val); |
|
144 // |
|
145 // and supply a default value to create a vector-valued |
|
146 // octave_value_list. |
565
|
147 |
5275
|
148 octave_value_list (octave_idx_type n); |
565
|
149 |
4591
|
150 octave_value_list (const Array<octave_value>& d); |
526
|
151 |
5275
|
152 octave_value& elem (octave_idx_type n) |
1968
|
153 { |
4591
|
154 static Matrix empty_matrix; |
|
155 |
|
156 if (n >= length ()) |
|
157 resize (n+1, empty_matrix); |
|
158 |
|
159 return data[n]; |
1968
|
160 } |
|
161 |
5275
|
162 octave_value elem (octave_idx_type n) const |
1968
|
163 { |
4591
|
164 #if defined (BOUNDS_CHECKING) |
|
165 return data.at (n); |
|
166 #else |
|
167 return data[n]; |
|
168 #endif |
1968
|
169 } |
508
|
170 }; |
498
|
171 |
504
|
172 #endif |
|
173 |
498
|
174 /* |
|
175 ;;; Local Variables: *** |
|
176 ;;; mode: C++ *** |
|
177 ;;; End: *** |
|
178 */ |