7019
|
1 /* |
|
2 |
7081
|
3 Copyright (C) 2006, 2007 John W. Eaton |
7019
|
4 |
|
5 This file is part of Octave. |
|
6 |
7081
|
7 Octave is free software; you can redistribute it and/or |
|
8 modify it under the terms of the GNU General Public License |
|
9 as published by the Free Software Foundation; either |
|
10 version 3 of the License, or (at your option) any later |
|
11 version. |
7019
|
12 |
7081
|
13 Octave is distributed in the hope that it will be useful, |
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty |
|
15 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
16 See the GNU General Public License for more details. |
7019
|
17 |
7081
|
18 You should have received a copy of the GNU General Public |
|
19 License along with Octave; see the file COPYING. If not, |
|
20 see <http://www.gnu.org/licenses/>. |
7019
|
21 |
|
22 */ |
|
23 |
6572
|
24 #include <octave/oct.h> |
|
25 #include <octave/ov-struct.h> |
|
26 |
|
27 DEFUN_DLD (structdemo, args, , "Struct demo.") |
|
28 { |
|
29 int nargin = args.length (); |
|
30 octave_value retval; |
|
31 |
|
32 if (nargin != 2) |
|
33 print_usage (); |
|
34 else |
|
35 { |
|
36 Octave_map arg0 = args(0).map_value (); |
|
37 std::string arg1 = args(1).string_value (); |
|
38 |
|
39 if (! error_state && arg0.contains (arg1)) |
|
40 { |
|
41 // The following two lines might be written as |
|
42 // octave_value tmp; |
7081
|
43 // for (Octave_map::iterator p0 = |
|
44 // arg0.begin(); |
6572
|
45 // p0 != arg0.end(); p0++ ) |
|
46 // if (arg0.key (p0) == arg1) |
|
47 // { |
|
48 // tmp = arg0.contents (p0) (0); |
|
49 // break; |
|
50 // } |
|
51 // though using seek is more concise. |
|
52 Octave_map::const_iterator p1 = arg0.seek (arg1); |
|
53 octave_value tmp = arg0.contents(p1)(0); |
|
54 Octave_map st; |
|
55 st.assign ("selected", tmp); |
|
56 retval = octave_value (st); |
|
57 } |
|
58 } |
|
59 return retval; |
|
60 } |
|
61 |