help-octave
[Top][All Lists]
Advanced

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

user-defined Octave C++ functions


From: John W. Eaton
Subject: user-defined Octave C++ functions
Date: Tue, 3 Oct 2000 20:38:33 -0500

On  4-Oct-2000, address@hidden <address@hidden> wrote:

| 
|   Hi.  I want to write a dynamically linked function for loading audio
| file, using an external library like libsnd, returning a structure with
| the format and relevant information.
| 
|    I've had problems creating such structures, though I think it may be my
| lack of familiarity causing it.
| 
| For example,
| #include <stdio.h>
| #include <sndfile.h>
| #include <octave/oct.h>
| #include <octave/ov-struct.h>
| #include <octave/oct-map.h>
| #include <string>
| 
| DEFUN_DLD (test_struct, args, ,"test_struct")
| {
|   ColumnVector in (args(0).vector_value());
|   Octave_map table ();
|   octave_struct test;
|   std::string field_name ("strfield");
|   octave_value tstr ("test this");
|   ColumnVector tmat (3);
|   int i = 0;
|   for (i=0;i<3;i++)
|     {
|       tmat(i) = i;
|     }
|   table[field_name] = tstr;
|   field_name = string("matfield");
|   table[field_name] = octave_value(tmat);
|   
|   test = octave_struct(table);
| 
|   return test;
| }

I would write this as

  #include <octave/oct.h>
  #include <octave/ov-struct.h>
  #include <octave/oct-map.h>

  DEFUN_DLD (test_struct, args, ,
    "test_struct")
  {
    ColumnVector tmat (3);

    for (int i = 0; i < 3; i++)
      tmat(i) = i;

    Octave_map table;

    table["strfield"] = "test this";

    table["matfield"] = tmat;

    return octave_value (table);
  }

(I should fix oct.h to include ov-struct.h and oct-map.h...).

Other examples of using structures in the (current) Octave sources are

  getgrent.cc
  getpwent.cc
  getrusage.cc
  time.cc


jwe



-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.che.wisc.edu/octave/octave.html
How to fund new projects:  http://www.che.wisc.edu/octave/funding.html
Subscription information:  http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------



reply via email to

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