source: trunk/lang/octave/rpLibPutData.cc @ 1722

Last change on this file since 1722 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: 4.0 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Octave Rappture Library Source
4 *
5 *    [err] = rpLibPutData(libHandle,path,bytes,nbytes,append)
6 *
7 * ======================================================================
8 *  AUTHOR:  Derrick Kearney, Purdue University
9 *  Copyright (c) 2005-2007
10 *  Purdue Research Foundation, West Lafayette, IN
11 * ======================================================================
12 */
13
14#include "RpOctaveInterface.h"
15
16/**********************************************************************/
17// METHOD: [err] = rpLibPutFile (libHandle,path,bytes,nbytes,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 * Bytes is the data to be added to the rappture library object in the
27 * form of a string.
28 * NBytes is an integer telling the size of Bytes in bytes.
29 * Append is an integer telling if this new data should overwrite
30 * (use 0) or be appended (use 1) to previous data in this node.
31 *
32 */
33
34DEFUN_DLD (rpLibPutString, args, ,
35"-*- texinfo -*-\n\
36[err] = rpLibPutData(@var{libHandle},@var{path},@var{bytes},@var{nbytes},@var{append})\n\
37\n\
38Clients use this to set the value of a node.  If the @var{path}\n\
39is not specified (ie. empty string ""), it sets the value for the\n\
40root node.  Otherwise, it sets the value for the element specified\n\
41by the path.  The added data is treated as the text within the \n\
42tag at the tail of the @var{path}.\n\
43\n\
44@var{bytes} is the name of the file to import into the rappture object\n\
45@var{nbytes} is an integer telling the size of bytes in bytes.\n\
46@var{append} is an integer telling if this new data should overwrite\n\
47(use 0) or be appended (use 1) to previous data in this node.\n\
48\n\
49Error Codes: err = 0 is success, anything else is failure.")
50{
51    static std::string who = "rpLibPutData";
52
53    // The list of values to return.
54    octave_value_list retval;
55    int err               = 1;
56    int nargin            = args.length ();
57    int libHandle         = 0;
58    std::string path      = "";
59    const char* bytes     = NULL;
60    unsigned int nbytes   = 0;
61    unsigned int append   = 0;
62    unsigned int bufferSize = 0;
63    RpLibrary* lib        = NULL;
64
65    if (nargin == 5) {
66
67        if ( args(0).is_real_scalar() &&
68             args(1).is_string()      &&
69             args(2).is_string()      &&
70             args(3).is_real_scalar() &&
71             args(4).is_real_scalar()   ) {
72
73            libHandle = args(0).int_value();
74            path      = args(1).string_value();
75            bytes     = args(2).string_value().data();
76            nbytes    = (unsigned int) args(3).int_value();
77            append    = (unsigned int) args(4).int_value();
78
79            if (args(2).string_value().length() < nbytes) {
80                bufferSize = (unsigned int) args(2).string_value().length();
81            }
82            else {
83                bufferSize = nbytes;
84            }
85
86            /* Call the C subroutine. */
87            // the only input that has restrictions is libHandle
88            // all other inputs may be empty strings or any integer value
89            if ( (libHandle >= 0) ) {
90
91                lib = (RpLibrary*) getObject_Void(libHandle);
92                if (lib) {
93                    lib->putData(path,bytes,nbytes,append);
94                    err = 0;
95                }
96                else {
97                    // lib is NULL, not found in dictionary
98                }
99            }
100            else {
101                // libHandle is negative
102                _PRINT_USAGE (who.c_str());
103            }
104        }
105        else {
106            // wrong argument types
107            _PRINT_USAGE (who.c_str());
108        }
109    }
110    else {
111        // wrong number of arguments
112        _PRINT_USAGE (who.c_str());
113    }
114
115    retval(0) = err;
116    return retval;
117}
Note: See TracBrowser for help on using the repository browser.