Mercurial > hg > octave-lyh
annotate examples/structdemo.cc @ 11051:2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 29 Sep 2010 04:23:13 -0400 |
parents | 6cb30a539481 |
children | db1f49eaba6b |
rev | line source |
---|---|
6572 | 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 | |
11051
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
9 if (args.length () == 2) |
6572 | 10 { |
11051
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
11 octave_scalar_map arg0 = args(0).scalar_map_value (); |
6572 | 12 |
11051
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
13 if (! error_state) |
6572 | 14 { |
11051
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
15 std::string arg1 = args(1).string_value (); |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
16 |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
17 if (! error_state) |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
18 { |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
19 octave_value tmp = arg0.contents (arg1); |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
20 |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
21 if (tmp.is_defined ()) |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
22 { |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
23 octave_scalar_map st; |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
24 |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
25 st.assign ("selected", tmp); |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
26 |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
27 retval = octave_value (st); |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
28 } |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
29 else |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
30 error ("sruct does not contain field named '%s'\n", |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
31 arg1.c_str ()); |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
32 } |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
33 else |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
34 error ("expecting character string as second argument"); |
6572 | 35 } |
11051
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
36 else |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
37 error ("expecting struct as first argument"); |
6572 | 38 } |
11051
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
39 else |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
40 print_usage (); |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
41 |
6572 | 42 return retval; |
43 } | |
44 |