annotate examples/structdemo.cc @ 7019:4270ded9ddc6

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