7019
|
1 /* |
|
2 |
|
3 Copyright (C) 2007 John W. Eaton |
|
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 3 of the License, or (at your |
|
10 option) any 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, see |
|
19 <http://www.gnu.org/licenses/>. |
|
20 |
|
21 */ |
|
22 |
6572
|
23 #include <octave/oct.h> |
|
24 #include <octave/ov-struct.h> |
|
25 |
|
26 DEFUN_DLD (structdemo, args, , "Struct demo.") |
|
27 { |
|
28 int nargin = args.length (); |
|
29 octave_value retval; |
|
30 |
|
31 if (nargin != 2) |
|
32 print_usage (); |
|
33 else |
|
34 { |
|
35 Octave_map arg0 = args(0).map_value (); |
|
36 std::string arg1 = args(1).string_value (); |
|
37 |
|
38 if (! error_state && arg0.contains (arg1)) |
|
39 { |
|
40 // The following two lines might be written as |
|
41 // octave_value tmp; |
|
42 // for (Octave_map::iterator p0 = arg0.begin() ; |
|
43 // p0 != arg0.end(); p0++ ) |
|
44 // if (arg0.key (p0) == arg1) |
|
45 // { |
|
46 // tmp = arg0.contents (p0) (0); |
|
47 // break; |
|
48 // } |
|
49 // though using seek is more concise. |
|
50 Octave_map::const_iterator p1 = arg0.seek (arg1); |
|
51 octave_value tmp = arg0.contents(p1)(0); |
|
52 Octave_map st; |
|
53 st.assign ("selected", tmp); |
|
54 retval = octave_value (st); |
|
55 } |
|
56 } |
|
57 return retval; |
|
58 } |
|
59 |