Mercurial > hg > octave-lyh
annotate examples/structdemo.cc @ 17532:578805a293e5
ellipj: Move numerical code into liboctave
* lo-specfun.cc, lo-specfun.h (ellipj): New functions, adapted from
Fellipj.
* ellipj.cc (Fellipj): Call ellipj. (do_ellipj): Delete.
author | Mike Miller <mtmiller@ieee.org> |
---|---|
date | Thu, 26 Sep 2013 21:34:26 -0400 |
parents | be41c30bcb44 |
children |
rev | line source |
---|---|
6572 | 1 #include <octave/oct.h> |
2 #include <octave/ov-struct.h> | |
3 | |
16867
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
12174
diff
changeset
|
4 DEFUN_DLD (structdemo, args, , "Struct Demo") |
6572 | 5 { |
16867
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
12174
diff
changeset
|
6 octave_value retval; |
6572 | 7 int nargin = args.length (); |
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 (); |
16867
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
12174
diff
changeset
|
12 //octave_map arg0 = args(0).map_value (); |
6572 | 13 |
11051
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
14 if (! error_state) |
6572 | 15 { |
11051
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
16 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
|
17 |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
18 if (! error_state) |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
19 { |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
20 octave_value tmp = arg0.contents (arg1); |
16867
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
12174
diff
changeset
|
21 //octave_value tmp = arg0.contents (arg1)(0); |
11051
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 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
|
24 { |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
25 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
|
26 |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
27 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
|
28 |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
29 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
|
30 } |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
31 else |
16867
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
12174
diff
changeset
|
32 error ("structdemo: struct does not have a field named '%s'\n", |
11051
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
33 arg1.c_str ()); |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
34 } |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
35 else |
16867
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
12174
diff
changeset
|
36 error ("structdemo: ARG2 must be a character string"); |
6572 | 37 } |
11051
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
38 else |
16867
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
12174
diff
changeset
|
39 error ("structdemo: ARG1 must be a struct"); |
6572 | 40 } |
11051
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
41 else |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
42 print_usage (); |
2204120e38d2
structdemo.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
9932
diff
changeset
|
43 |
12174 | 44 return retval; |
6572 | 45 } |