comparison src/oct-map.cc @ 4675:f6d6335c08f6

[project @ 2003-12-16 05:11:26 by jwe]
author jwe
date Tue, 16 Dec 2003 05:11:27 +0000
parents 87c01a296263
children c88afb778c41
comparison
equal deleted inserted replaced
4674:7736835a5c8e 4675:f6d6335c08f6
33 33
34 #include "oct-map.h" 34 #include "oct-map.h"
35 #include "utils.h" 35 #include "utils.h"
36 36
37 Cell 37 Cell
38 Octave_map::operator [] (const std::string& k) const 38 Octave_map::contents (const std::string& k) const
39 { 39 {
40 const_iterator p = seek (k); 40 const_iterator p = seek (k);
41 41
42 return p != end () ? p->second : Cell (); 42 return p != end () ? p->second : Cell ();
43 } 43 }
62 Octave_map retval; 62 Octave_map retval;
63 63
64 if (new_dims != dims ()) 64 if (new_dims != dims ())
65 { 65 {
66 for (const_iterator p = begin (); p != end (); p++) 66 for (const_iterator p = begin (); p != end (); p++)
67 retval[key(p)] = contents(p).reshape (new_dims); 67 retval.assign (key(p), contents(p).reshape (new_dims));
68 68
69 dimensions = new_dims; 69 dimensions = new_dims;
70 } 70 }
71 71
72 return retval; 72 return retval;
124 124
125 for (int i = 0; i < len; i++) 125 for (int i = 0; i < len; i++)
126 { 126 {
127 std::string k = t_keys[i]; 127 std::string k = t_keys[i];
128 128
129 Cell t_rhs = rhs[k]; 129 Cell t_rhs = rhs.contents (k);
130 130
131 assign (idx, k, t_rhs); 131 assign (idx, k, t_rhs);
132 132
133 if (error_state) 133 if (error_state)
134 break; 134 break;
199 } 199 }
200 200
201 dimensions = new_dims; 201 dimensions = new_dims;
202 202
203 map[k] = tmp; 203 map[k] = tmp;
204 }
205
206 return *this;
207 }
208
209 Octave_map&
210 Octave_map::assign (const std::string& k, const octave_value& rhs)
211 {
212 if (empty ())
213 {
214 map[k] = Cell (rhs);
215
216 dimensions = dim_vector (1, 1);
217 }
218 else
219 {
220 dim_vector dv = dims ();
221
222 if (dv.all_ones ())
223 map[k] = Cell (rhs);
224 else
225 error ("invalid structure assignment");
204 } 226 }
205 227
206 return *this; 228 return *this;
207 } 229 }
208 230
236 Cell tmp = contents(p).index (idx); 258 Cell tmp = contents(p).index (idx);
237 259
238 if (error_state) 260 if (error_state)
239 break; 261 break;
240 262
241 retval[key(p)] = tmp; 263 retval.assign (key(p), tmp);
242 } 264 }
243 265
244 return error_state ? Octave_map () : retval; 266 return error_state ? Octave_map () : retval;
245 } 267 }
246 268