source: trunk/src/objects/RpNumber.h @ 1615

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

updates for the rappture objects, object examples, and object apis. small fix for rpunits c interface to check string length. there should probably be more of these checks in the c interface, but units should also be rewritten. added folders to separate out octave2 and octave3 app-fermi examples

File size: 2.9 KB
Line 
1/*
2 * ======================================================================
3 *  AUTHOR:  Derrick Kearney, Purdue University
4 *  Copyright (c) 2005-2009  Purdue Research Foundation
5 *
6 *  See the file "license.terms" for information on usage and
7 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
8 * ======================================================================
9 */
10#include <errno.h>
11#include "RpObject.h"
12#include "RpChain.h"
13
14#ifndef RAPPTURE_NUMBER_H
15#define RAPPTURE_NUMBER_H
16
17namespace Rappture {
18
19class Number : public Object
20{
21    public:
22
23        Number();
24        Number(const char *name, const char *units, double val);
25
26        Number(const char *name, const char *units, double val,
27               double min, double max, const char *label,
28               const char *desc);
29
30        Number( const Number& o );
31        virtual ~Number ();
32
33        Accessor<double> def;
34        Accessor<double> cur;
35        Accessor<double> min;
36        Accessor<double> max;
37
38        const char *units(void) const;
39        void units(const char *p);
40
41        int minset() const;
42        int maxset() const;
43        int defset() const;
44        int curset() const;
45
46        // convert the value stored in this object to specified units
47        // does not return the converted value
48        // error code is returned
49        Outcome& convert(const char *to);
50
51        // get the value of this object converted to specified units
52        // does not change the value of the object
53        // error code is returned
54        double value(const char *units) const;
55        void vvalue(void *storage, size_t numHints, va_list arg) const;
56
57        Number& addPreset(const char *label, const char *desc,
58                          double val, const char *units);
59
60        Number& addPreset(const char *label, const char *desc,
61                          const char *val);
62
63        Number& delPreset(const char *label);
64
65
66        const int is() const;
67
68        void minFromStr(const char *val);
69        void maxFromStr(const char *val);
70        void defFromStr(const char *val);
71        void curFromStr(const char *val);
72
73    private:
74
75        // flag tells if user specified min and max values
76        int _minSet;
77        int _maxSet;
78        int _defSet;
79        int _curSet;
80
81        // hash or linked list of preset values
82        Rp_Chain *_presets;
83
84        struct preset{
85            Accessor<const char *> label;
86            Accessor<const char *> desc;
87            Accessor<const char *> units;
88            Accessor<double> val;
89        };
90
91        void __configureFromTree(ClientData c);
92        void __dumpToTree(ClientData c);
93
94        void __convertFromString(const char *val, double *ret);
95        void __valUnitsSplit( const char *inStr, double *val,
96                const char **units);
97};
98
99} // namespace Rappture
100
101/*--------------------------------------------------------------------------*/
102/*--------------------------------------------------------------------------*/
103
104#endif
Note: See TracBrowser for help on using the repository browser.