source: trunk/src/octave/rpPutString.cc @ 122

Last change on this file since 122 was 122, checked in by dkearney, 17 years ago

added initial version of octave language bindings.
1) no claiming language bindings work, but will happily take credit if they do.
2) bindings are untested
3) bindings happen to work with mystery example that happens to be located in examples/app-fermi/matlab/fermi_rp.m and happens to be invokable with examples/app-fermi/matlab/tool_rp.xml
4) bindings need octave2.1-headers installed (in debian: apt-get install octave2.1-headers) to get the mkoctfile program
5) binding function names might be changing to be more discriptive and more tightly bound to either the lib or units module.
6) adjusted Makefile to add octave bindings compilation.

File size: 3.3 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Octave Rappture Library Source
4 *
5 *    [err] = rpPutString(libHandle,path,value,append)
6 *
7 * ======================================================================
8 *  AUTHOR:  Derrick Kearney, Purdue University
9 *  Copyright (c) 2005
10 *  Purdue Research Foundation, West Lafayette, IN
11 * ======================================================================
12 */
13
14#include "RpOctaveInterface.h"
15
16/**********************************************************************/
17// METHOD: [err] = rpPutString (libHandle,path,value,append)
18/// Set the value of a node.
19/**
20 * Clients use this to set the value of a node.  If the path
21 * is not specified, it sets the value for the root node.
22 * Otherwise, it sets the value for the element specified
23 * by the path.  The value is treated as the text within the
24 * tag at the tail of the path.
25 *
26 * If the append flag is set to 1, then the
27 * value is appended to the current value.  Otherwise, the
28 * value specified in the function call replaces the current value.
29 *
30 */
31
32DEFUN_DLD (rpPutString, args, ,
33"-*- texinfo -*-\n\
34[err] = rpPutString(@var{libHandle},@var{path},@var{value},@var{append})\n\
35\n\
36Clients use this to set the value of a node.  If the @var{path}\n\
37is not specified (ie. empty string ""), it sets the value for the\n\
38root node.  Otherwise, it sets the value for the element specified\n\
39by the path.  The @var{value} is treated as the text within the \n\
40tag at the tail of the @var{path}.\n\
41\n\
42If the @var{append} flag is set to 1, then the \n\
43@var{value} is appended to the current value.  Otherwise, the \n\
44@var{value} specified in the function call replaces the current value.\n\
45Error Codes: err = 0 is success, anything else is failure.")
46{
47    static std::string who = "rpPutString";
48
49    // The list of values to return.
50    octave_value_list retval;
51    int err           = 1;
52    int nargin        = args.length ();
53    int libHandle     = 0;
54    std::string path  = "";
55    std::string value = "";
56    std::string id    = "";
57    int append        = 0;
58    RpLibrary* lib    = NULL;
59
60    if (nargin == 4) {
61
62        if ( args(0).is_real_scalar() &&
63             args(1).is_string()      &&
64             args(2).is_string()      &&
65             args(3).is_real_scalar()   ) {
66
67            libHandle = args(0).int_value ();
68            path      = args(1).string_value ();
69            value     = args(2).string_value ();
70            append    = args(3).int_value ();
71
72            /* Call the C subroutine. */
73            // the only input that has restrictions is libHandle
74            // all other inputs may be empty strings or any integer value
75            if ( (libHandle >= 0) ) {
76
77                lib = getObject_Lib(libHandle);
78                if (lib) {
79                    lib->put(path,value,id,append);
80                    err = 0;
81                }
82                else {
83                    // lib is NULL, not found in dictionary
84                }
85            }
86            else {
87                // libHandle is negative
88                print_usage (who.c_str());
89            }
90        }
91        else {
92            // wrong argument types
93            print_usage (who.c_str());
94        }
95    }
96    else {
97        // wrong number of arguments
98        print_usage (who.c_str());
99    }
100
101    retval(0) = err;
102    return retval;
103}
Note: See TracBrowser for help on using the repository browser.