help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: newbie question on using octave structures in external C++ functions


From: Jim H
Subject: Re: newbie question on using octave structures in external C++ functions
Date: Tue, 25 Sep 2007 08:16:08 -0700 (PDT)


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
-- 
View this message in context: 
http://www.nabble.com/newbie-question-on-using-octave-structures-in-external-C%2B%2B-functions-tf4512192.html#a12881868
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]