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