Mercurial > hg > octave-nkf
annotate src/ov-struct.cc @ 11804:7a92d9b3e7d0 release-3-0-x
octave_struct::subsref: don't resize for simple x(idx) case
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 12 Aug 2008 13:20:27 -0400 |
parents | 72830070a17b |
children |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2004, 2005, 2006, |
11740 | 4 2007, 2008 John W. Eaton |
2376 | 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. | |
2376 | 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/>. | |
2376 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
3503 | 28 #include <iostream> |
2376 | 29 |
3933 | 30 #include "Cell.h" |
4358 | 31 #include "defun.h" |
2376 | 32 #include "error.h" |
4358 | 33 #include "gripes.h" |
2979 | 34 #include "oct-lvalue.h" |
3932 | 35 #include "ov-list.h" |
2376 | 36 #include "ov-struct.h" |
37 #include "unwind-prot.h" | |
6811 | 38 #include "utils.h" |
2948 | 39 #include "variables.h" |
2376 | 40 |
4750 | 41 #include "Array-util.h" |
42 | |
4687 | 43 #include "byte-swap.h" |
44 #include "ls-oct-ascii.h" | |
45 #include "ls-oct-binary.h" | |
46 #include "ls-hdf5.h" | |
47 #include "ls-utils.h" | |
5759 | 48 #include "pr-output.h" |
4687 | 49 |
3219 | 50 DEFINE_OCTAVE_ALLOCATOR(octave_struct); |
2376 | 51 |
4612 | 52 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(octave_struct, "struct", "struct"); |
2376 | 53 |
4513 | 54 Cell |
3933 | 55 octave_struct::dotref (const octave_value_list& idx) |
2962 | 56 { |
4513 | 57 Cell retval; |
3933 | 58 |
59 assert (idx.length () == 1); | |
2962 | 60 |
3933 | 61 std::string nm = idx(0).string_value (); |
62 | |
4219 | 63 Octave_map::const_iterator p = map.seek (nm); |
2376 | 64 |
4219 | 65 if (p != map.end ()) |
3933 | 66 retval = map.contents (p); |
67 else | |
2376 | 68 error ("structure has no member `%s'", nm.c_str ()); |
69 | |
70 return retval; | |
71 } | |
72 | |
4513 | 73 #if 0 |
3933 | 74 static void |
75 gripe_invalid_index (void) | |
76 { | |
77 error ("invalid index for structure array"); | |
78 } | |
4513 | 79 #endif |
3933 | 80 |
81 static void | |
82 gripe_invalid_index_for_assignment (void) | |
83 { | |
84 error ("invalid index for structure array assignment"); | |
85 } | |
86 | |
87 static void | |
88 gripe_invalid_index_type (const std::string& nm, char t) | |
89 { | |
90 error ("%s cannot be indexed with %c", nm.c_str (), t); | |
91 } | |
92 | |
93 static void | |
94 gripe_failed_assignment (void) | |
95 { | |
96 error ("assignment to structure element failed"); | |
97 } | |
98 | |
4994 | 99 octave_value_list |
4247 | 100 octave_struct::subsref (const std::string& type, |
4994 | 101 const std::list<octave_value_list>& idx, |
102 int nargout) | |
3933 | 103 { |
4994 | 104 octave_value_list retval; |
3933 | 105 |
106 int skip = 1; | |
107 | |
108 switch (type[0]) | |
109 { | |
110 case '(': | |
111 { | |
112 if (type.length () > 1 && type[1] == '.') | |
113 { | |
4219 | 114 std::list<octave_value_list>::const_iterator p = idx.begin (); |
115 octave_value_list key_idx = *++p; | |
3933 | 116 |
4513 | 117 Cell tmp = dotref (key_idx); |
3933 | 118 |
119 if (! error_state) | |
120 { | |
11632 | 121 Cell t = tmp.index (idx.front (), true); |
3933 | 122 |
4994 | 123 retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); |
3933 | 124 |
4513 | 125 // We handled two index elements, so tell |
126 // next_subsref to skip both of them. | |
3933 | 127 |
4513 | 128 skip++; |
3933 | 129 } |
130 } | |
131 else | |
11804
7a92d9b3e7d0
octave_struct::subsref: don't resize for simple x(idx) case
John W. Eaton <jwe@octave.org>
parents:
11740
diff
changeset
|
132 retval(0) = map.index (idx.front (), false); |
3933 | 133 } |
134 break; | |
135 | |
136 case '.': | |
137 { | |
5592 | 138 if (map.numel() > 0) |
139 { | |
140 Cell t = dotref (idx.front ()); | |
3933 | 141 |
5592 | 142 retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); |
143 } | |
3933 | 144 } |
145 break; | |
146 | |
147 case '{': | |
148 gripe_invalid_index_type (type_name (), type[0]); | |
149 break; | |
150 | |
151 default: | |
152 panic_impossible (); | |
153 } | |
154 | |
5775 | 155 // FIXME -- perhaps there should be an |
4994 | 156 // octave_value_list::next_subsref member function? See also |
157 // octave_user_function::subsref. | |
158 | |
159 if (idx.size () > 1) | |
5028 | 160 retval = retval(0).next_subsref (nargout, type, idx, skip); |
3933 | 161 |
162 return retval; | |
163 } | |
164 | |
11804
7a92d9b3e7d0
octave_struct::subsref: don't resize for simple x(idx) case
John W. Eaton <jwe@octave.org>
parents:
11740
diff
changeset
|
165 /* |
7a92d9b3e7d0
octave_struct::subsref: don't resize for simple x(idx) case
John W. Eaton <jwe@octave.org>
parents:
11740
diff
changeset
|
166 %!test |
7a92d9b3e7d0
octave_struct::subsref: don't resize for simple x(idx) case
John W. Eaton <jwe@octave.org>
parents:
11740
diff
changeset
|
167 %! x(1).a.a = 1; x(2).a.a = 2; |
7a92d9b3e7d0
octave_struct::subsref: don't resize for simple x(idx) case
John W. Eaton <jwe@octave.org>
parents:
11740
diff
changeset
|
168 %! assert (size (x), [1, 2]); |
7a92d9b3e7d0
octave_struct::subsref: don't resize for simple x(idx) case
John W. Eaton <jwe@octave.org>
parents:
11740
diff
changeset
|
169 %! assert (x(1).a.a, 1); |
7a92d9b3e7d0
octave_struct::subsref: don't resize for simple x(idx) case
John W. Eaton <jwe@octave.org>
parents:
11740
diff
changeset
|
170 %! assert (x(2).a.a, 2); |
7a92d9b3e7d0
octave_struct::subsref: don't resize for simple x(idx) case
John W. Eaton <jwe@octave.org>
parents:
11740
diff
changeset
|
171 */ |
7a92d9b3e7d0
octave_struct::subsref: don't resize for simple x(idx) case
John W. Eaton <jwe@octave.org>
parents:
11740
diff
changeset
|
172 |
3933 | 173 octave_value |
4513 | 174 octave_struct::numeric_conv (const Cell& val, |
3933 | 175 const std::string& type) |
176 { | |
177 octave_value retval; | |
178 | |
179 if (val.length () == 1) | |
180 { | |
181 retval = val(0); | |
182 | |
183 if (type.length () > 0 && type[0] == '.' && ! retval.is_map ()) | |
184 retval = Octave_map (); | |
185 } | |
186 else | |
187 gripe_invalid_index_for_assignment (); | |
188 | |
189 return retval; | |
190 } | |
191 | |
192 octave_value | |
4247 | 193 octave_struct::subsasgn (const std::string& type, |
4219 | 194 const std::list<octave_value_list>& idx, |
3933 | 195 const octave_value& rhs) |
2376 | 196 { |
3933 | 197 octave_value retval; |
198 | |
199 int n = type.length (); | |
200 | |
201 octave_value t_rhs = rhs; | |
202 | |
203 if (n > 1 && ! (type.length () == 2 && type[0] == '(' && type[1] == '.')) | |
204 { | |
205 switch (type[0]) | |
206 { | |
207 case '(': | |
208 { | |
209 if (type.length () > 1 && type[1] == '.') | |
210 { | |
4219 | 211 std::list<octave_value_list>::const_iterator p = idx.begin (); |
212 octave_value_list t_idx = *p; | |
3933 | 213 |
4513 | 214 octave_value_list key_idx = *++p; |
215 | |
216 assert (key_idx.length () == 1); | |
3933 | 217 |
4513 | 218 std::string key = key_idx(0).string_value (); |
3933 | 219 |
4513 | 220 octave_value u; |
3933 | 221 |
4513 | 222 if (! map.contains (key)) |
223 u = octave_value::empty_conv (type.substr (2), rhs); | |
224 else | |
225 { | |
4675 | 226 Cell map_val = map.contents (key); |
3933 | 227 |
4513 | 228 Cell map_elt = map_val.index (idx.front (), true); |
3933 | 229 |
4513 | 230 u = numeric_conv (map_elt, type.substr (2)); |
231 } | |
3933 | 232 |
4513 | 233 if (! error_state) |
234 { | |
235 std::list<octave_value_list> next_idx (idx); | |
3933 | 236 |
4513 | 237 // We handled two index elements, so subsasgn to |
238 // needs to skip both of them. | |
3933 | 239 |
4513 | 240 next_idx.erase (next_idx.begin ()); |
241 next_idx.erase (next_idx.begin ()); | |
4059 | 242 |
4513 | 243 u.make_unique (); |
244 | |
245 t_rhs = u.subsasgn (type.substr (2), next_idx, rhs); | |
3933 | 246 } |
247 } | |
248 else | |
249 gripe_invalid_index_for_assignment (); | |
250 } | |
251 break; | |
252 | |
253 case '.': | |
254 { | |
255 octave_value_list key_idx = idx.front (); | |
256 | |
257 assert (key_idx.length () == 1); | |
258 | |
259 std::string key = key_idx(0).string_value (); | |
260 | |
261 octave_value u; | |
262 | |
263 if (! map.contains (key)) | |
264 u = octave_value::empty_conv (type.substr (1), rhs); | |
265 else | |
266 { | |
4675 | 267 Cell map_val = map.contents (key); |
3933 | 268 |
269 u = numeric_conv (map_val, type.substr (1)); | |
270 } | |
271 | |
272 if (! error_state) | |
273 { | |
4219 | 274 std::list<octave_value_list> next_idx (idx); |
3933 | 275 |
4219 | 276 next_idx.erase (next_idx.begin ()); |
3933 | 277 |
4059 | 278 u.make_unique (); |
279 | |
3933 | 280 t_rhs = u.subsasgn (type.substr (1), next_idx, rhs); |
281 } | |
282 } | |
283 break; | |
284 | |
285 case '{': | |
286 gripe_invalid_index_type (type_name (), type[0]); | |
287 break; | |
288 | |
289 default: | |
290 panic_impossible (); | |
291 } | |
292 } | |
293 | |
294 if (! error_state) | |
295 { | |
296 switch (type[0]) | |
297 { | |
298 case '(': | |
299 { | |
300 if (n > 1 && type[1] == '.') | |
301 { | |
4219 | 302 std::list<octave_value_list>::const_iterator p = idx.begin (); |
303 octave_value_list key_idx = *++p; | |
3933 | 304 |
305 assert (key_idx.length () == 1); | |
306 | |
307 std::string key = key_idx(0).string_value (); | |
308 | |
309 if (! error_state) | |
310 { | |
4513 | 311 map.assign (idx.front (), key, t_rhs); |
3933 | 312 |
4513 | 313 if (! error_state) |
5759 | 314 { |
315 count++; | |
316 retval = octave_value (this); | |
317 } | |
3933 | 318 else |
4513 | 319 gripe_failed_assignment (); |
3933 | 320 } |
321 else | |
322 gripe_failed_assignment (); | |
323 } | |
324 else | |
4197 | 325 { |
5592 | 326 if (t_rhs.is_map()) |
4197 | 327 { |
5592 | 328 Octave_map rhs_map = t_rhs.map_value (); |
4197 | 329 |
330 if (! error_state) | |
5592 | 331 { |
332 map.assign (idx.front (), rhs_map); | |
333 | |
334 if (! error_state) | |
5759 | 335 { |
336 count++; | |
337 retval = octave_value (this); | |
338 } | |
5592 | 339 else |
340 gripe_failed_assignment (); | |
341 } | |
4197 | 342 else |
5592 | 343 error ("invalid structure assignment"); |
4197 | 344 } |
4513 | 345 else |
5592 | 346 { |
347 if (t_rhs.is_empty()) | |
348 { | |
349 map.maybe_delete_elements (idx.front()); | |
350 | |
351 if (! error_state) | |
5759 | 352 { |
353 count++; | |
354 retval = octave_value (this); | |
355 } | |
5592 | 356 else |
357 gripe_failed_assignment (); | |
358 } | |
359 else | |
360 error ("invalid structure assignment"); | |
361 } | |
4197 | 362 } |
3933 | 363 } |
364 break; | |
365 | |
366 case '.': | |
367 { | |
368 octave_value_list key_idx = idx.front (); | |
369 | |
370 assert (key_idx.length () == 1); | |
371 | |
372 std::string key = key_idx(0).string_value (); | |
373 | |
6833 | 374 if (t_rhs.is_cs_list ()) |
375 { | |
376 Cell tmp_cell = Cell (t_rhs.list_value ()); | |
377 | |
7040 | 378 // The shape of the RHS is irrelevant, we just want |
379 // the number of elements to agree and to preserve the | |
380 // shape of the left hand side of the assignment. | |
381 | |
382 if (numel () == tmp_cell.numel ()) | |
383 tmp_cell = tmp_cell.reshape (dims ()); | |
6833 | 384 |
385 map.assign (key, tmp_cell); | |
386 } | |
387 else | |
388 map.assign (key, t_rhs); | |
3933 | 389 |
390 if (! error_state) | |
5759 | 391 { |
392 count++; | |
393 retval = octave_value (this); | |
394 } | |
3933 | 395 else |
396 gripe_failed_assignment (); | |
397 } | |
398 break; | |
399 | |
400 case '{': | |
401 gripe_invalid_index_type (type_name (), type[0]); | |
402 break; | |
403 | |
404 default: | |
405 panic_impossible (); | |
406 } | |
407 } | |
408 else | |
409 gripe_failed_assignment (); | |
410 | |
411 return retval; | |
2376 | 412 } |
413 | |
7046 | 414 octave_value |
415 octave_struct::do_index_op (const octave_value_list& idx, bool resize_ok) | |
416 { | |
417 octave_value retval; | |
418 | |
419 octave_idx_type n_idx = idx.length (); | |
420 | |
421 int nd = map.ndims (); | |
422 | |
423 switch (n_idx) | |
424 { | |
425 case 0: | |
426 retval = map; | |
427 break; | |
428 | |
429 case 1: | |
430 { | |
431 idx_vector i = idx (0).index_vector (); | |
432 | |
433 if (! error_state) | |
434 retval = map.index (i, resize_ok, Cell::resize_fill_value ()); | |
435 } | |
436 break; | |
437 | |
438 default: | |
439 { | |
440 if (n_idx == 2 && nd == 2) | |
441 { | |
442 idx_vector i = idx (0).index_vector (); | |
443 | |
444 if (! error_state) | |
445 { | |
446 idx_vector j = idx (1).index_vector (); | |
447 | |
448 if (! error_state) | |
449 retval = map.index (i, j, resize_ok, | |
450 Cell::resize_fill_value ()); | |
451 } | |
452 } | |
453 else | |
454 { | |
455 Array<idx_vector> idx_vec (n_idx); | |
456 | |
457 for (octave_idx_type i = 0; i < n_idx; i++) | |
458 { | |
459 idx_vec(i) = idx(i).index_vector (); | |
460 | |
461 if (error_state) | |
462 break; | |
463 } | |
464 | |
465 if (! error_state) | |
466 retval = map.index (idx_vec, resize_ok, | |
467 Cell::resize_fill_value ()); | |
468 } | |
469 } | |
470 break; | |
471 } | |
472 | |
473 return retval; | |
474 } | |
475 | |
4791 | 476 size_t |
477 octave_struct::byte_size (void) const | |
478 { | |
479 // Neglect the size of the fieldnames. | |
480 | |
481 size_t retval = 0; | |
482 | |
483 for (Octave_map::const_iterator p = map.begin (); p != map.end (); p++) | |
484 { | |
485 std::string key = map.key (p); | |
486 | |
487 octave_value val = octave_value (map.contents (p)); | |
488 | |
489 retval += val.byte_size (); | |
490 } | |
491 | |
492 return retval; | |
493 } | |
494 | |
2376 | 495 void |
3523 | 496 octave_struct::print (std::ostream& os, bool) const |
2901 | 497 { |
498 print_raw (os); | |
499 } | |
500 | |
501 void | |
3523 | 502 octave_struct::print_raw (std::ostream& os, bool) const |
2376 | 503 { |
2985 | 504 unwind_protect::begin_frame ("octave_struct_print"); |
2376 | 505 |
506 unwind_protect_int (Vstruct_levels_to_print); | |
507 | |
3961 | 508 if (Vstruct_levels_to_print >= 0) |
2376 | 509 { |
5598 | 510 bool print_keys_only = (Vstruct_levels_to_print == 0 |
511 || map.numel () == 0); | |
3961 | 512 |
513 Vstruct_levels_to_print--; | |
514 | |
2901 | 515 indent (os); |
516 os << "{"; | |
517 newline (os); | |
2376 | 518 |
2901 | 519 increment_indent_level (); |
2376 | 520 |
5598 | 521 octave_idx_type n = map.numel (); |
3932 | 522 |
5598 | 523 if (n == 0 || (n > 1 && print_keys_only)) |
4604 | 524 { |
525 indent (os); | |
526 dim_vector dv = dims (); | |
527 os << dv.str () << " struct array containing the fields:"; | |
528 newline (os); | |
529 newline (os); | |
530 | |
531 increment_indent_level (); | |
532 } | |
533 | |
5880 | 534 string_vector key_list = map.keys (); |
535 | |
536 for (octave_idx_type i = 0; i < key_list.length (); i++) | |
2376 | 537 { |
5880 | 538 std::string key = key_list[i]; |
539 | |
540 Cell val = map.contents (key); | |
2376 | 541 |
4499 | 542 octave_value tmp = (n == 1) ? val(0) : octave_value (val, true); |
3961 | 543 |
544 if (print_keys_only) | |
3932 | 545 { |
3961 | 546 indent (os); |
4604 | 547 os << key; |
548 if (n == 1) | |
549 { | |
550 dim_vector dv = tmp.dims (); | |
551 os << ": " << dv.str () << " " << tmp.type_name (); | |
552 } | |
3961 | 553 newline (os); |
3932 | 554 } |
3961 | 555 else |
4121 | 556 tmp.print_with_name (os, key); |
2376 | 557 } |
558 | |
5598 | 559 if (n == 0 || (n > 1 && print_keys_only)) |
4604 | 560 decrement_indent_level (); |
561 | |
2901 | 562 decrement_indent_level (); |
2376 | 563 |
2901 | 564 indent (os); |
565 os << "}"; | |
566 newline (os); | |
2376 | 567 } |
568 else | |
2901 | 569 { |
3961 | 570 indent (os); |
571 os << "<structure>"; | |
2901 | 572 newline (os); |
573 } | |
2376 | 574 |
2985 | 575 unwind_protect::run_frame ("octave_struct_print"); |
2376 | 576 } |
577 | |
2901 | 578 bool |
3523 | 579 octave_struct::print_name_tag (std::ostream& os, const std::string& name) const |
2901 | 580 { |
3961 | 581 bool retval = false; |
582 | |
2901 | 583 indent (os); |
3961 | 584 |
585 if (Vstruct_levels_to_print < 0) | |
586 os << name << " = "; | |
587 else | |
588 { | |
589 os << name << " ="; | |
590 newline (os); | |
591 retval = true; | |
592 } | |
593 | |
594 return retval; | |
2901 | 595 } |
596 | |
4744 | 597 static bool |
598 scalar (const dim_vector& dims) | |
599 { | |
600 return dims.length () == 2 && dims (0) == 1 && dims (1) == 1; | |
601 } | |
602 | |
603 /* | |
604 %!shared x | |
605 %! x(1).a=1; x(2).a=2; x(1).b=3; x(2).b=3; | |
606 %!assert(struct('a',1,'b',3),x(1)) | |
5592 | 607 %!assert(isempty(x([]))) |
608 %!assert(isempty(struct('a',{},'b',{}))) | |
4744 | 609 %!assert(struct('a',{1,2},'b',{3,3}),x) |
610 %!assert(struct('a',{1,2},'b',3),x) | |
611 %!assert(struct('a',{1,2},'b',{3}),x) | |
612 %!assert(struct('b',3,'a',{1,2}),x) | |
613 %!assert(struct('b',{3},'a',{1,2}),x) | |
614 %!test x=struct([]); | |
615 %!assert(size(x),[0,0]); | |
616 %!assert(isstruct(x)); | |
617 %!assert(isempty(fieldnames(x))); | |
618 %!fail("struct('a',{1,2},'b',{1,2,3})","dimensions of parameter 2 do not match those of parameter 4") | |
5582 | 619 %!fail("struct(1,2,3,4)","struct expects alternating \"field\", VALUE pairs"); |
620 %!fail("struct('1',2,'3')","struct expects alternating \"field\", VALUE pairs"); | |
4744 | 621 */ |
622 | |
623 DEFUN (struct, args, , | |
624 "-*- texinfo -*-\n\ | |
625 @deftypefn {Built-in Function} {} struct (\"field\", @var{value}, \"field\", @var{value}, @dots{})\n\ | |
626 \n\ | |
627 Create a structure and initialize its value.\n\ | |
628 \n\ | |
629 If the values are cell arrays, create a structure array and initialize\n\ | |
630 its values. The dimensions of each cell array of values must match.\n\ | |
631 Singleton cells and non-cell values are repeated so that they fill\n\ | |
632 the entire array. If the cells are empty, create an empty structure\n\ | |
4911 | 633 array with the specified field names.\n\ |
634 @end deftypefn") | |
4744 | 635 { |
6946 | 636 octave_value retval; |
4744 | 637 |
638 int nargin = args.length (); | |
639 | |
5444 | 640 // struct ([]) returns an empty struct. |
641 | |
642 // struct (empty_matrix) returns an empty struct with the same | |
643 // dimensions as the empty matrix. | |
644 | |
645 // Note that struct () creates a 1x1 struct with no fields for | |
646 // compatibility with Matlab. | |
4744 | 647 |
6946 | 648 if ((nargin == 1 || nargin == 2) |
649 && args(0).is_empty () && args(0).is_real_matrix ()) | |
650 { | |
651 Cell fields; | |
652 | |
653 if (nargin == 2) | |
654 { | |
655 if (args(1).is_cellstr ()) | |
656 retval = Octave_map (args(0).dims (), args(1).cell_value ()); | |
657 else | |
658 error ("struct: expecting cell array of field names as second argument"); | |
659 } | |
660 else | |
661 retval = Octave_map (args(0).dims ()); | |
662 | |
663 return retval; | |
664 } | |
4744 | 665 |
666 // Check for "field", VALUE pairs. | |
667 | |
668 for (int i = 0; i < nargin; i += 2) | |
669 { | |
670 if (! args(i).is_string () || i + 1 >= nargin) | |
671 { | |
672 error ("struct expects alternating \"field\", VALUE pairs"); | |
673 return retval; | |
674 } | |
675 } | |
676 | |
677 // Check that the dimensions of the values correspond. | |
678 | |
679 dim_vector dims (1, 1); | |
680 | |
681 int first_dimensioned_value = 0; | |
682 | |
683 for (int i = 1; i < nargin; i += 2) | |
684 { | |
685 if (args(i).is_cell ()) | |
686 { | |
687 dim_vector argdims (args(i).dims ()); | |
688 | |
689 if (! scalar (argdims)) | |
690 { | |
691 if (! first_dimensioned_value) | |
692 { | |
693 dims = argdims; | |
694 first_dimensioned_value = i + 1; | |
695 } | |
696 else if (dims != argdims) | |
697 { | |
698 error ("struct: dimensions of parameter %d do not match those of parameter %d", | |
699 first_dimensioned_value, i+1); | |
700 return retval; | |
701 } | |
702 } | |
703 } | |
704 } | |
705 | |
706 // Create the return value. | |
707 | |
708 Octave_map map (dims); | |
709 | |
710 for (int i = 0; i < nargin; i+= 2) | |
711 { | |
712 // Get key. | |
713 | |
714 std::string key (args(i).string_value ()); | |
715 | |
716 if (error_state) | |
717 return retval; | |
718 | |
6811 | 719 if (! valid_identifier (key)) |
720 { | |
721 error ("struct: invalid structure field name `%s'", key.c_str ()); | |
722 return retval; | |
723 } | |
724 | |
4744 | 725 // Value may be v, { v }, or { v1, v2, ... } |
726 // In the first two cases, we need to create a cell array of | |
727 // the appropriate dimensions filled with v. In the last case, | |
728 // the cell array has already been determined to be of the | |
729 // correct dimensions. | |
730 | |
731 if (args(i+1).is_cell ()) | |
732 { | |
733 const Cell c (args(i+1).cell_value ()); | |
734 | |
735 if (error_state) | |
736 return retval; | |
737 | |
738 if (scalar (c.dims ())) | |
739 map.assign (key, Cell (dims, c(0))); | |
740 else | |
741 map.assign (key, c); | |
742 } | |
743 else | |
744 map.assign (key, Cell (dims, args(i+1))); | |
745 | |
746 if (error_state) | |
747 return retval; | |
748 } | |
6946 | 749 |
4744 | 750 return octave_value (map); |
751 } | |
752 | |
4358 | 753 DEFUN (isstruct, args, , |
754 "-*- texinfo -*-\n\ | |
755 @deftypefn {Built-in Function} {} isstruct (@var{expr})\n\ | |
756 Return 1 if the value of the expression @var{expr} is a structure.\n\ | |
757 @end deftypefn") | |
758 { | |
759 octave_value retval; | |
760 | |
761 if (args.length () == 1) | |
762 retval = args(0).is_map (); | |
763 else | |
5823 | 764 print_usage (); |
4358 | 765 |
766 return retval; | |
767 } | |
768 | |
769 DEFUN (fieldnames, args, , | |
770 "-*- texinfo -*-\n\ | |
771 @deftypefn {Built-in Function} {} fieldnames (@var{struct})\n\ | |
772 Return a cell array of strings naming the elements of the structure\n\ | |
773 @var{struct}. It is an error to call @code{fieldnames} with an\n\ | |
774 argument that is not a structure.\n\ | |
775 @end deftypefn") | |
776 { | |
777 octave_value retval; | |
778 | |
779 int nargin = args.length (); | |
780 | |
781 if (nargin == 1) | |
782 { | |
783 if (args(0).is_map ()) | |
784 { | |
785 Octave_map m = args(0).map_value (); | |
4744 | 786 string_vector keys = m.keys (); |
787 if (keys.length () == 0) | |
788 retval = Cell (0, 1); | |
789 else | |
790 retval = Cell (m.keys ()); | |
4358 | 791 } |
792 else | |
793 gripe_wrong_type_arg ("fieldnames", args(0)); | |
794 } | |
795 else | |
5823 | 796 print_usage (); |
4358 | 797 |
798 return retval; | |
799 } | |
800 | |
801 DEFUN (isfield, args, , | |
802 "-*- texinfo -*-\n\ | |
803 @deftypefn {Built-in Function} {} isfield (@var{expr}, @var{name})\n\ | |
804 Return true if the expression @var{expr} is a structure and it includes an\n\ | |
805 element named @var{name}. The first argument must be a structure and\n\ | |
806 the second must be a string.\n\ | |
807 @end deftypefn") | |
808 { | |
809 octave_value retval; | |
810 | |
811 int nargin = args.length (); | |
812 | |
813 if (nargin == 2) | |
814 { | |
815 retval = false; | |
816 | |
5775 | 817 // FIXME -- should this work for all types that can do |
4358 | 818 // structure reference operations? |
819 | |
820 if (args(0).is_map () && args(1).is_string ()) | |
821 { | |
822 std::string key = args(1).string_value (); | |
823 | |
824 Octave_map m = args(0).map_value (); | |
825 | |
826 retval = m.contains (key) != 0; | |
827 } | |
828 } | |
829 else | |
5823 | 830 print_usage (); |
4358 | 831 |
832 return retval; | |
833 } | |
834 | |
4750 | 835 // Check that the dimensions of the input arguments are correct. |
836 | |
837 static bool | |
838 cell2struct_check_args (const dim_vector& c_dv, const dim_vector& f_dv, | |
839 bool is_cell, int dim) | |
840 { | |
4751 | 841 bool retval = true; |
4750 | 842 |
843 if (dim >= 0 && dim < c_dv.length ()) | |
844 { | |
845 if (is_cell) | |
846 { | |
4752 | 847 if (f_dv.numel () != c_dv(dim)) |
4750 | 848 { |
4751 | 849 error ("cell2struct: numel (FIELD) != size (CELL, DIM)"); |
4750 | 850 |
851 retval = false; | |
852 } | |
853 } | |
854 else | |
855 { | |
856 if (f_dv.length () > 2) | |
857 { | |
4751 | 858 error ("cell2struct: field array must be a 2-d matrix"); |
4750 | 859 |
860 retval = false; | |
861 } | |
862 else if (f_dv(0) != c_dv(dim)) | |
863 { | |
4751 | 864 error ("cell2struct: size (FIELD, 1) != length (C, DIM)"); |
4750 | 865 |
866 retval = false; | |
867 } | |
868 } | |
869 } | |
870 else | |
871 { | |
872 error ("cell2struct: DIM out of range"); | |
873 | |
874 retval = false; | |
875 } | |
876 | |
877 return retval; | |
878 } | |
879 | |
880 static void | |
5275 | 881 cell2struct_construct_idx (Array<octave_idx_type>& ra_idx1, |
882 const Array<octave_idx_type>& ra_idx2, | |
883 octave_idx_type dim, octave_idx_type fill_value) | |
4750 | 884 { |
5275 | 885 octave_idx_type iidx = 0; |
4750 | 886 |
5275 | 887 for (octave_idx_type idx = 0; idx < ra_idx1.length (); idx++) |
4750 | 888 { |
889 if (idx == dim) | |
890 ra_idx1.elem (idx) = fill_value; | |
891 else | |
892 ra_idx1.elem (idx) = ra_idx2(iidx++); | |
893 } | |
894 } | |
895 | |
896 DEFUN (cell2struct, args, , | |
897 "-*- texinfo -*-\n\ | |
4817 | 898 @deftypefn {Built-in Function} {} cell2struct (@var{cell}, @var{fields}, @var{dim})\n\ |
899 Convert @var{cell} to a structure. The number of fields in @var{fields}\n\ | |
900 must match the number of elements in @var{cell} along dimension @var{dim},\n\ | |
901 that is @code{numel (@var{fields}) == size (@var{cell}, @var{dim})}.\n\ | |
4750 | 902 \n\ |
903 @example\n\ | |
904 @group\n\ | |
7031 | 905 A = cell2struct (@{'Peter', 'Hannah', 'Robert';\n\ |
906 185, 170, 168@},\n\ | |
6519 | 907 @{'Name','Height'@}, 1);\n\ |
4750 | 908 A(1)\n\ |
909 @result{} ans =\n\ | |
4780 | 910 @{\n\ |
911 Height = 185\n\ | |
912 Name = Peter\n\ | |
913 @}\n\ | |
4750 | 914 \n\ |
915 @end group\n\ | |
916 @end example\n\ | |
917 @end deftypefn") | |
918 { | |
919 octave_value retval; | |
920 | |
4751 | 921 if (args.length () == 3) |
4750 | 922 { |
4751 | 923 Cell c = args(0).cell_value (); |
4750 | 924 |
4751 | 925 if (! error_state) |
4750 | 926 { |
4751 | 927 octave_value field = args(1); |
4750 | 928 |
4751 | 929 // Field is either cell or character matrix. |
4750 | 930 |
5775 | 931 // FIXME -- this could be simplified if we had |
4752 | 932 // cellstr and iscellstr functions available. |
933 | |
4751 | 934 bool field_is_cell = field.is_cell (); |
4750 | 935 |
4751 | 936 Cell field_cell; |
937 charMatrix field_char; | |
4750 | 938 |
939 if (field_is_cell) | |
4751 | 940 field_cell = field.cell_value (); |
941 else | |
942 field_char = field.char_matrix_value (); | |
943 | |
944 if (! error_state) | |
4750 | 945 { |
4751 | 946 // Retrieve the dimension value. |
947 | |
5775 | 948 // FIXME -- int_value () should print out the |
4751 | 949 // conversions it does to be Matlab compatible. |
950 | |
5275 | 951 octave_idx_type dim = args(2).int_value () - 1; |
4751 | 952 |
953 if (! error_state) | |
954 { | |
955 dim_vector c_dv = c.dims (); | |
956 dim_vector field_dv = field.dims (); | |
957 | |
958 if (cell2struct_check_args (c_dv, field_dv, field_is_cell, | |
959 dim)) | |
960 { | |
5275 | 961 octave_idx_type c_dv_length = c_dv.length (); |
4751 | 962 |
963 // Dimension vector for the Cell arrays to be | |
964 // put into the structure. | |
965 | |
966 dim_vector value_dv; | |
967 | |
968 // Initialize c_value_dv. | |
4750 | 969 |
4751 | 970 if (c_dv_length == 2) |
971 value_dv = dim_vector (1, 1); | |
972 else | |
973 value_dv.resize (c_dv_length - 1); | |
974 | |
5275 | 975 octave_idx_type idx_tmp = 0; |
4751 | 976 |
5275 | 977 for (octave_idx_type i = 0; i < c_dv_length; i++) |
4751 | 978 { |
979 if (i != dim) | |
980 value_dv.elem (idx_tmp++) = c_dv.elem (i); | |
981 } | |
982 | |
983 // All initializing is done, we can start moving | |
984 // values. | |
985 | |
986 Octave_map map; | |
987 | |
988 // If field is a cell array then we use all | |
989 // elements in array, on the other hand when | |
990 // field is a character array the number of | |
991 // elements is equals the number of rows. | |
992 | |
5275 | 993 octave_idx_type field_numel |
4751 | 994 = field_is_cell ? field_dv.numel (): field_dv(0); |
995 | |
996 // For matlab compatibility. | |
997 | |
998 if (field_numel == 0) | |
999 map.reshape (dim_vector (0, 1)); | |
4750 | 1000 |
5275 | 1001 for (octave_idx_type i = 0; i < field_numel; i++) |
4751 | 1002 { |
1003 // Construct cell array which goes into the | |
1004 // structure together with the appropriate | |
1005 // field name. | |
1006 | |
1007 Cell c_value (value_dv); | |
1008 | |
5275 | 1009 Array<octave_idx_type> value_idx (value_dv.length (), 0); |
1010 Array<octave_idx_type> c_idx (c_dv_length, 0); | |
4751 | 1011 |
5275 | 1012 for (octave_idx_type j = 0; j < value_dv.numel (); j++) |
4751 | 1013 { |
1014 // Need to do this to construct the | |
1015 // appropriate idx for getting elements | |
1016 // from the original cell array. | |
1017 | |
1018 cell2struct_construct_idx (c_idx, value_idx, | |
1019 dim, i); | |
1020 | |
1021 c_value.elem (value_idx) = c.elem (c_idx); | |
1022 | |
1023 increment_index (value_idx, value_dv); | |
1024 } | |
1025 | |
1026 std::string field_str; | |
4750 | 1027 |
4751 | 1028 if (field_is_cell) |
1029 { | |
1030 // Matlab retrieves the field values | |
1031 // column by column. | |
1032 | |
1033 octave_value field_tmp = field_cell.elem (i); | |
1034 | |
1035 field_str = field_tmp.string_value (); | |
1036 | |
1037 if (error_state) | |
1038 { | |
1039 error ("cell2struct: fields have to be of type string"); | |
1040 break; | |
1041 } | |
1042 } | |
1043 else | |
1044 { | |
1045 field_str = field_char.row_as_string (i); | |
1046 | |
1047 if (error_state) | |
1048 return retval; | |
1049 } | |
1050 | |
6811 | 1051 if (! valid_identifier (field_str)) |
1052 { | |
1053 error ("cell2struct: invalid field name `%s'", | |
1054 field_str.c_str ()); | |
1055 break; | |
1056 } | |
1057 | |
4751 | 1058 map.reshape (value_dv); |
1059 | |
1060 map.assign (field_str, c_value); | |
1061 } | |
1062 | |
1063 if (! error_state) | |
1064 retval = map; | |
1065 } | |
4750 | 1066 } |
4751 | 1067 else |
1068 error ("cell2struct: expecting third argument to be an integer"); | |
4750 | 1069 } |
1070 else | |
4751 | 1071 error ("cell2struct: expecting second argument to be a cell or character array"); |
4750 | 1072 } |
4751 | 1073 else |
1074 error ("cell2struct: expecting first argument to be a cell array"); | |
4750 | 1075 } |
4751 | 1076 else |
5823 | 1077 print_usage (); |
4750 | 1078 |
1079 return retval; | |
1080 } | |
1081 | |
4817 | 1082 // So we can call Fcellstr directly. |
1083 extern octave_value_list Fcellstr (const octave_value_list& args, int); | |
1084 | |
1085 DEFUN (rmfield, args, , | |
1086 "-*- texinfo -*-\n\ | |
1087 @deftypefn {Built-in Function} {} rmfield (@var{s}, @var{f})\n\ | |
1088 Remove field @var{f} from the structure @var{s}. If @var{f} is a\n\ | |
1089 cell array of character strings or a character array, remove the\n\ | |
1090 named fields.\n\ | |
5642 | 1091 @seealso{cellstr, iscellstr, setfield}\n\ |
1092 @end deftypefn") | |
4817 | 1093 { |
1094 octave_value retval; | |
1095 | |
1096 int nargin = args.length (); | |
1097 | |
1098 if (nargin == 2) | |
1099 { | |
1100 Octave_map m = args(0).map_value (); | |
1101 | |
1102 octave_value_list fval = Fcellstr (args(1), 1); | |
1103 | |
1104 if (! error_state) | |
1105 { | |
1106 Cell fcell = fval(0).cell_value (); | |
1107 | |
1108 for (int i = 0; i < fcell.numel (); i++) | |
1109 { | |
1110 std::string key = fcell(i).string_value (); | |
1111 | |
1112 if (m.contains (key)) | |
1113 m.del (key); | |
1114 else | |
1115 { | |
1116 error ("rmfield: structure does not contain field %s", | |
1117 key.c_str ()); | |
1118 | |
1119 break; | |
1120 } | |
1121 } | |
1122 | |
1123 if (! error_state) | |
1124 retval = m; | |
1125 } | |
1126 } | |
1127 else | |
5823 | 1128 print_usage (); |
4817 | 1129 |
1130 return retval; | |
1131 } | |
1132 | |
1133 bool | |
6974 | 1134 octave_struct::save_ascii (std::ostream& os) |
4817 | 1135 { |
1136 Octave_map m = map_value (); | |
6639 | 1137 os << "# length: " << m.nfields () << "\n"; |
4817 | 1138 |
1139 Octave_map::iterator i = m.begin (); | |
1140 while (i != m.end ()) | |
1141 { | |
5341 | 1142 octave_value val = map.contents (i); |
4817 | 1143 |
6974 | 1144 bool b = save_ascii_data (os, val, m.key (i), false, 0); |
4817 | 1145 |
1146 if (! b) | |
1147 return os; | |
1148 | |
1149 i++; | |
1150 } | |
1151 | |
1152 return true; | |
1153 } | |
1154 | |
1155 bool | |
1156 octave_struct::load_ascii (std::istream& is) | |
1157 { | |
5275 | 1158 octave_idx_type len = 0; |
4817 | 1159 bool success = true; |
1160 | |
1161 if (extract_keyword (is, "length", len) && len >= 0) | |
1162 { | |
1163 if (len > 0) | |
1164 { | |
1165 Octave_map m (map); | |
1166 | |
5275 | 1167 for (octave_idx_type j = 0; j < len; j++) |
4817 | 1168 { |
1169 octave_value t2; | |
1170 bool dummy; | |
1171 | |
1172 // recurse to read cell elements | |
1173 std::string nm | |
5756 | 1174 = read_ascii_data (is, std::string (), dummy, t2, j); |
4817 | 1175 |
1176 if (!is) | |
1177 break; | |
1178 | |
6293 | 1179 Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); |
5433 | 1180 |
6293 | 1181 if (error_state) |
1182 { | |
1183 error ("load: internal error loading struct elements"); | |
1184 return false; | |
1185 } | |
5433 | 1186 |
6293 | 1187 m.assign (nm, tcell); |
4817 | 1188 } |
1189 | |
1190 if (is) | |
1191 map = m; | |
1192 else | |
1193 { | |
1194 error ("load: failed to load structure"); | |
1195 success = false; | |
1196 } | |
1197 } | |
1198 else if (len == 0 ) | |
6292 | 1199 map = Octave_map (dim_vector (1, 1)); |
4817 | 1200 else |
1201 panic_impossible (); | |
1202 } | |
1203 else { | |
1204 error ("load: failed to extract number of elements in structure"); | |
1205 success = false; | |
1206 } | |
1207 | |
1208 return success; | |
1209 } | |
1210 | |
1211 bool | |
1212 octave_struct::save_binary (std::ostream& os, bool& save_as_floats) | |
1213 { | |
1214 Octave_map m = map_value (); | |
1215 | |
6639 | 1216 int32_t len = m.nfields (); |
5760 | 1217 os.write (reinterpret_cast<char *> (&len), 4); |
4817 | 1218 |
1219 Octave_map::iterator i = m.begin (); | |
1220 while (i != m.end ()) | |
1221 { | |
5341 | 1222 octave_value val = map.contents (i); |
4817 | 1223 |
5341 | 1224 bool b = save_binary_data (os, val, m.key (i), "", 0, save_as_floats); |
4817 | 1225 |
1226 if (! b) | |
1227 return os; | |
1228 | |
1229 i++; | |
1230 } | |
1231 | |
1232 return true; | |
1233 } | |
1234 | |
1235 bool | |
1236 octave_struct::load_binary (std::istream& is, bool swap, | |
5760 | 1237 oct_mach_info::float_format fmt) |
4817 | 1238 { |
1239 bool success = true; | |
5828 | 1240 int32_t len; |
5760 | 1241 if (! is.read (reinterpret_cast<char *> (&len), 4)) |
4817 | 1242 return false; |
1243 if (swap) | |
4944 | 1244 swap_bytes<4> (&len); |
4817 | 1245 |
1246 if (len > 0) | |
1247 { | |
1248 Octave_map m (map); | |
1249 | |
5275 | 1250 for (octave_idx_type j = 0; j < len; j++) |
4817 | 1251 { |
1252 octave_value t2; | |
1253 bool dummy; | |
1254 std::string doc; | |
1255 | |
1256 // recurse to read cell elements | |
1257 std::string nm = read_binary_data (is, swap, fmt, std::string (), | |
1258 dummy, t2, doc); | |
1259 | |
1260 if (!is) | |
1261 break; | |
1262 | |
6293 | 1263 Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); |
5433 | 1264 |
6293 | 1265 if (error_state) |
1266 { | |
1267 error ("load: internal error loading struct elements"); | |
1268 return false; | |
1269 } | |
5433 | 1270 |
6293 | 1271 m.assign (nm, tcell); |
4817 | 1272 } |
1273 | |
1274 if (is) | |
1275 map = m; | |
1276 else | |
1277 { | |
1278 error ("load: failed to load structure"); | |
1279 success = false; | |
1280 } | |
1281 } | |
1282 else if (len == 0 ) | |
6292 | 1283 map = Octave_map (dim_vector (1, 1)); |
4817 | 1284 else |
1285 panic_impossible (); | |
1286 | |
1287 return success; | |
1288 } | |
1289 | |
1290 #if defined (HAVE_HDF5) | |
1291 | |
1292 bool | |
1293 octave_struct::save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) | |
1294 { | |
1295 hid_t data_hid = -1; | |
1296 | |
1297 data_hid = H5Gcreate (loc_id, name, 0); | |
1298 if (data_hid < 0) return false; | |
1299 | |
1300 // recursively add each element of the structure to this group | |
1301 Octave_map m = map_value (); | |
1302 Octave_map::iterator i = m.begin (); | |
1303 while (i != m.end ()) | |
1304 { | |
5341 | 1305 octave_value val = map.contents (i); |
4817 | 1306 |
5341 | 1307 bool retval2 = add_hdf5_data (data_hid, val, m.key (i), "", false, |
4817 | 1308 save_as_floats); |
1309 | |
1310 if (! retval2) | |
1311 break; | |
1312 | |
1313 i++; | |
1314 } | |
1315 | |
1316 H5Gclose (data_hid); | |
4837 | 1317 |
4817 | 1318 return true; |
1319 } | |
1320 | |
1321 bool | |
1322 octave_struct::load_hdf5 (hid_t loc_id, const char *name, | |
1323 bool have_h5giterate_bug) | |
1324 { | |
1325 bool retval = false; | |
1326 | |
1327 hdf5_callback_data dsub; | |
1328 | |
1329 herr_t retval2 = 0; | |
6292 | 1330 Octave_map m (dim_vector (1, 1)); |
4817 | 1331 int current_item = 0; |
1332 #ifdef HAVE_H5GGET_NUM_OBJS | |
1333 hsize_t num_obj = 0; | |
5060 | 1334 hid_t group_id = H5Gopen (loc_id, name); |
1335 H5Gget_num_objs (group_id, &num_obj); | |
1336 H5Gclose (group_id); | |
4817 | 1337 |
1338 while (current_item < static_cast<int> (num_obj) | |
1339 && (retval2 = H5Giterate (loc_id, name, ¤t_item, | |
1340 hdf5_read_next_data, &dsub)) > 0) | |
1341 #else | |
1342 while ((retval2 = H5Giterate (loc_id, name, ¤t_item, | |
1343 hdf5_read_next_data, &dsub)) > 0) | |
1344 #endif | |
1345 { | |
5342 | 1346 octave_value t2 = dsub.tc; |
1347 | |
6293 | 1348 Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); |
5433 | 1349 |
6293 | 1350 if (error_state) |
1351 { | |
1352 error ("load: internal error loading struct elements"); | |
1353 return false; | |
1354 } | |
5433 | 1355 |
6293 | 1356 m.assign (dsub.name, tcell); |
5336 | 1357 |
4817 | 1358 if (have_h5giterate_bug) |
1359 current_item++; // H5Giterate returned the last index processed | |
1360 } | |
1361 | |
1362 if (retval2 >= 0) | |
1363 { | |
1364 map = m; | |
1365 retval = true; | |
1366 } | |
1367 | |
1368 return retval; | |
1369 } | |
1370 | |
4687 | 1371 #endif |
1372 | |
5900 | 1373 mxArray * |
1374 octave_struct::as_mxArray (void) const | |
1375 { | |
1376 int nf = nfields (); | |
1377 string_vector kv = map_keys (); | |
6065 | 1378 |
1379 OCTAVE_LOCAL_BUFFER (const char *, f, nf); | |
1380 | |
5900 | 1381 for (int i = 0; i < nf; i++) |
6065 | 1382 f[i] = kv[i].c_str (); |
5900 | 1383 |
1384 mxArray *retval = new mxArray (dims (), nf, f); | |
1385 | |
1386 mxArray **elts = static_cast<mxArray **> (retval->get_data ()); | |
1387 | |
6686 | 1388 mwSize nel = numel (); |
5900 | 1389 |
6686 | 1390 mwSize ntot = nf * nel; |
5900 | 1391 |
1392 for (int i = 0; i < nf; i++) | |
1393 { | |
1394 Cell c = map.contents (kv[i]); | |
1395 | |
1396 const octave_value *p = c.data (); | |
1397 | |
6686 | 1398 mwIndex k = 0; |
1399 for (mwIndex j = i; j < ntot; j += nf) | |
5900 | 1400 elts[j] = new mxArray (p[k++]); |
1401 } | |
1402 | |
1403 return retval; | |
1404 } | |
1405 | |
2376 | 1406 /* |
1407 ;;; Local Variables: *** | |
1408 ;;; mode: C++ *** | |
1409 ;;; End: *** | |
1410 */ |