Mercurial > hg > octave-thorsten
comparison examples/structdemo.cc @ 6572:8e7148b84b59
[project @ 2007-04-25 04:13:44 by jwe]
author | jwe |
---|---|
date | Wed, 25 Apr 2007 04:14:49 +0000 |
parents | |
children | 4270ded9ddc6 |
comparison
equal
deleted
inserted
replaced
6571:24d9e0799603 | 6572:8e7148b84b59 |
---|---|
1 #include <octave/oct.h> | |
2 #include <octave/ov-struct.h> | |
3 | |
4 DEFUN_DLD (structdemo, args, , "Struct demo.") | |
5 { | |
6 int nargin = args.length (); | |
7 octave_value retval; | |
8 | |
9 if (nargin != 2) | |
10 print_usage (); | |
11 else | |
12 { | |
13 Octave_map arg0 = args(0).map_value (); | |
14 std::string arg1 = args(1).string_value (); | |
15 | |
16 if (! error_state && arg0.contains (arg1)) | |
17 { | |
18 // The following two lines might be written as | |
19 // octave_value tmp; | |
20 // for (Octave_map::iterator p0 = arg0.begin() ; | |
21 // p0 != arg0.end(); p0++ ) | |
22 // if (arg0.key (p0) == arg1) | |
23 // { | |
24 // tmp = arg0.contents (p0) (0); | |
25 // break; | |
26 // } | |
27 // though using seek is more concise. | |
28 Octave_map::const_iterator p1 = arg0.seek (arg1); | |
29 octave_value tmp = arg0.contents(p1)(0); | |
30 Octave_map st; | |
31 st.assign ("selected", tmp); | |
32 retval = octave_value (st); | |
33 } | |
34 } | |
35 return retval; | |
36 } | |
37 |