[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 17:44:18 +0200 |
User-agent: |
Thunderbird 1.5.0.7 (X11/20060921) |
Jim H wrote:
> David Bateman-3 wrote:
>
>> 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.
>>
>> _______________________________________________
>> Help-octave mailing list
>> address@hidden
>> https://www.cae.wisc.edu/mailman/listinfo/help-octave
>>
>>
>>
>
> Thanks for the reply, but I guess I was not clear. I had read the fine
> manual and even better cookbook by Paul Thomas on the wiki, but their
> examples describe how to set a variable in the octave space, while I would
> like to learn how to determine a structure field's datatype in order to set
> a variable in the C++ space. I'd iike to do something like:
>
> // c++ code
> int bob;
> bob=arg0(p0).contents(); // or something similar, assuming "contents" is
> an integer
>
> -Jim
>
int bob = arg0.contents(p0)(0).int_value();
D.
--
David Bateman address@hidden
Motorola Labs - Paris +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob)
91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax)
The information contained in this communication has been classified as:
[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary