source: trunk/lang/octave/rpLibPut.cc @ 1262

Last change on this file since 1262 was 1262, checked in by dkearney, 15 years ago

attempting to fix compiler warning for octave's print_usage function
this seems to work for octave3.0
also adding checks to configure for more header files

File size: 3.5 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Octave Rappture Library Source
4 *
5 *    [err] = rpLibPut(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] = rpLibPut (libHandle,path,value,id,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 * 'id' is used to set the identifier field for the tag at the
27 * tail of the path.  If the append flag is set to 1, then the
28 * value is appended to the current value.  Otherwise, the
29 * value specified in the function call replaces the current value.
30 *
31 */
32
33DEFUN_DLD (rpLibPut, args, ,
34"-*- texinfo -*-\n\
35[err] = rpLibPut(@var{libHandle},@var{path},@var{value},@var{append})\n\
36\n\
37Clients use this to set the value of a node.  If the @var{path}\n\
38is not specified (ie. empty string ""), it sets the value for the\n\
39root node.  Otherwise, it sets the value for the element specified\n\
40by the path.  The @var{value} is treated as the text within the \n\
41tag at the tail of the @var{path}.\n\
42\n\
43If the @var{append} flag is set to 1, then the \n\
44@var{value} is appended to the current value.  Otherwise, the \n\
45@var{value} specified in the function call replaces the current value.\n\
46Error Codes: err = 0 is success, anything else is failure.")
47{
48    static std::string who = "rpLibPut";
49
50    // The list of values to return.
51    octave_value_list retval;
52    int err           = 1;
53    int nargin        = args.length ();
54    int libHandle     = 0;
55    std::string path  = "";
56    std::string value = "";
57    std::string id    = ""; // not used, kept for compatibility dsk-20060131
58    int append        = 0;
59    RpLibrary* lib    = NULL;
60
61    if (nargin == 4) {
62
63        if ( args(0).is_real_scalar() &&
64             args(1).is_string()      &&
65             args(2).is_string()      &&
66             args(3).is_real_scalar()   ) {
67
68            libHandle = args(0).int_value ();
69            path      = args(1).string_value ();
70            value     = args(2).string_value ();
71            append    = args(3).int_value ();
72
73            /* Call the C subroutine. */
74            // the only input that has restrictions is libHandle
75            // all other inputs may be empty strings or any integer value
76            if ( (libHandle >= 0) ) {
77
78                lib = (RpLibrary*) getObject_Void(libHandle);
79                if (lib) {
80                    lib->put(path,value,id,append);
81                    err = 0;
82                }
83                else {
84                    // lib is NULL, not found in dictionary
85                }
86            }
87            else {
88                // libHandle is negative
89                _PRINT_USAGE (who.c_str());
90            }
91        }
92        else {
93            // wrong argument types
94            _PRINT_USAGE (who.c_str());
95        }
96    }
97    else {
98        // wrong number of arguments
99        _PRINT_USAGE (who.c_str());
100    }
101
102    retval(0) = err;
103    return retval;
104}
Note: See TracBrowser for help on using the repository browser.