[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: newbie question on using octave structures in external C++ functions
From: |
David Bateman |
Subject: |
Re: newbie question on using octave structures in external C++ functions |
Date: |
Tue, 25 Sep 2007 00:44:12 +0200 |
User-agent: |
Thunderbird 1.5.0.7 (X11/20060921) |
Jim H wrote:
> Hi,
> I would like to know how to determine the data type of a field in an octave
> data structure passed to a c++ function. The manual and wiki provide some
> good examples, but my problem is to pass in a structure and assign values to
> c++ variables used by the external function. To assign those values, it
> seems I need to know if the field is an integer, string, etc. Here's a
> brief example where I could use some help.
>
> #include <octave/oct.h>
> #include <octave/ov-struct.h>
> int aval;
> DEFUN_DLD(shombs_defs,args, , "show mbs defaults")
> {
> int nargin = args.length ();
> octave_value_list retval;
>
> if (nargin != 2)
> print_usage ();
> else
> {
> Octave_map arg0 = args(0).map_value ();
> std::string arg1 = args(1).string_value ();
> for (Octave_map::iterator p0 = arg0.begin() ;
> p0 != arg0.end(); p0++ ) {
> // print keys and values
> std::cout << " key =>" << arg0.key( p0 ) << std::endl;
> octave_value( arg0.contents( p0 ) ).print( std::cout ,
> false );
> // how do I do the following?
> if ( arg0.key(p0) IS "foo" AND arg0.contents(p0) IS
> INTEGER ) {
> aval = arg0.contents(p0);
> }
> ...
>
> Thanks in advance for hints on this, and if there is good place to read
> about c++-callable methods that apply to structures, please direct me there.
>
> Jim
>
The 2.9.14 version of the manual has a full example of what you want.
See the file
http://velveeta.che.wisc.edu/cgi-bin/cvsweb.cgi/octave/examples/structdemo.cc?rev=HEAD
D.