comparison src/oct-obj.h @ 4591:2c9de1be042a

[project @ 2003-11-11 00:23:35 by jwe]
author jwe
date Tue, 11 Nov 2003 00:23:35 +0000
parents 820323598f4f
children e35b034d3523
comparison
equal deleted inserted replaced
4590:2cb70e155939 4591:2c9de1be042a
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) 26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION)
27 #pragma interface 27 #pragma interface
28 #endif 28 #endif
29 29
30 #include <string> 30 #include <string>
31 #include <vector>
31 32
32 #include "Array.h"
33 #include "oct-alloc.h" 33 #include "oct-alloc.h"
34 #include "str-vec.h" 34 #include "str-vec.h"
35 35
36 #include "ov.h" 36 #include "ov.h"
37 37
91 91
92 octave_value& operator () (int n) { return elem (n); } 92 octave_value& operator () (int n) { return elem (n); }
93 93
94 octave_value operator () (int n) const { return elem (n); } 94 octave_value operator () (int n) const { return elem (n); }
95 95
96 int length (void) const { return data.length (); } 96 int length (void) const { return data.size (); }
97 97
98 bool empty (void) const { return length () == 0; } 98 bool empty (void) const { return length () == 0; }
99 99
100 void resize (int n) { data.resize (n); } 100 void resize (int n) { data.resize (n); }
101 101
102 void resize (int n, const octave_value& val) { data.resize_and_fill (n, val); } 102 void resize (int n, const octave_value& val);
103 103
104 octave_value_list& prepend (const octave_value& val); 104 octave_value_list& prepend (const octave_value& val);
105 105
106 octave_value_list& append (const octave_value& val); 106 octave_value_list& append (const octave_value& val);
107 107
109 109
110 octave_value_list& reverse (void); 110 octave_value_list& reverse (void);
111 111
112 octave_value_list splice (int offset, int length, 112 octave_value_list splice (int offset, int length,
113 const octave_value_list& lst) const; 113 const octave_value_list& lst) const;
114
115 octave_value_list index (idx_vector& i, int resize_ok = 0) const;
116
117 octave_value_list& assign (const idx_vector& i,
118 const octave_value_list& rhs,
119 const octave_value& fill_val = octave_value ());
120 114
121 bool all_strings_p (void) const; 115 bool all_strings_p (void) const;
122 116
123 string_vector make_argv (const std::string&) const; 117 string_vector make_argv (const std::string&) const;
124 118
128 122
129 private: 123 private:
130 124
131 static octave_allocator allocator; 125 static octave_allocator allocator;
132 126
133 Array<octave_value> data; 127 std::vector<octave_value> data;
134 128
135 // This list of strings can be used to tag each element of data with 129 // This list of strings can be used to tag each element of data with
136 // a name. By default, it is empty. 130 // a name. By default, it is empty.
137 string_vector names; 131 string_vector names;
138 132
150 // and supply a default value to create a vector-valued 144 // and supply a default value to create a vector-valued
151 // octave_value_list. 145 // octave_value_list.
152 146
153 octave_value_list (int n); 147 octave_value_list (int n);
154 148
155 octave_value_list (const Array<octave_value>& d) 149 octave_value_list (const Array<octave_value>& d);
156 : data (d) { }
157
158 void maybe_resize (int n)
159 {
160 if (n >= length ())
161 data.resize_and_fill (n + 1, Matrix ());
162 }
163 150
164 octave_value& elem (int n) 151 octave_value& elem (int n)
165 { 152 {
166 maybe_resize (n); 153 static Matrix empty_matrix;
167 return data.elem (n); 154
155 if (n >= length ())
156 resize (n+1, empty_matrix);
157
158 return data[n];
168 } 159 }
169 160
170 octave_value elem (int n) const 161 octave_value elem (int n) const
171 { 162 {
172 return data.elem (n); 163 #if defined (BOUNDS_CHECKING)
164 return data.at (n);
165 #else
166 return data[n];
167 #endif
173 } 168 }
174 }; 169 };
175 170
176 #endif 171 #endif
177 172