comparison src/ov-struct.cc @ 5900:c20eb7330d13

[project @ 2006-07-22 08:31:16 by jwe]
author jwe
date Sat, 22 Jul 2006 08:31:17 +0000
parents 84ca47e311b3
children cdef72fcd206
comparison
equal deleted inserted replaced
5899:82c38ce145a7 5900:c20eb7330d13
1273 return retval; 1273 return retval;
1274 } 1274 }
1275 1275
1276 #endif 1276 #endif
1277 1277
1278 mxArray *
1279 octave_struct::as_mxArray (void) const
1280 {
1281 int nf = nfields ();
1282 string_vector kv = map_keys ();
1283 const char **f = static_cast<const char **> (mxArray::malloc (nf * sizeof (const char *)));
1284 for (int i = 0; i < nf; i++)
1285 f[i] = mxArray::strsave (kv[i].c_str ());
1286
1287 mxArray *retval = new mxArray (dims (), nf, f);
1288
1289 mxArray **elts = static_cast<mxArray **> (retval->get_data ());
1290
1291 int nel = numel ();
1292
1293 int ntot = nf * nel;
1294
1295 for (int i = 0; i < nf; i++)
1296 {
1297 Cell c = map.contents (kv[i]);
1298
1299 const octave_value *p = c.data ();
1300
1301 int k = 0;
1302 for (int j = i; j < ntot; j += nf)
1303 elts[j] = new mxArray (p[k++]);
1304 }
1305
1306 return retval;
1307 }
1308
1278 /* 1309 /*
1279 ;;; Local Variables: *** 1310 ;;; Local Variables: ***
1280 ;;; mode: C++ *** 1311 ;;; mode: C++ ***
1281 ;;; End: *** 1312 ;;; End: ***
1282 */ 1313 */