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

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

adding configure/dump functions to plot object, creating simple test case for dumping xml
all objects should have "run" as their parent path if no parent path is provided.

File size: 2.7 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        // convert the value stored in this object to specified units
42        // does not return the converted value
43        // error code is returned
44        int convert(const char *to);
45
46        // get the value of this object converted to specified units
47        // does not change the value of the object
48        // error code is returned
49        int value(const char *units, double *value) const;
50
51        Number& addPreset(const char *label, const char *desc,
52                          double val, const char *units);
53
54        Number& addPreset(const char *label, const char *desc,
55                          const char *val);
56
57        Number& delPreset(const char *label);
58
59
60        void configure(size_t as, ClientData c);
61        void dump(size_t as, ClientData c);
62
63        const int is() const;
64
65        void minFromStr(const char *val);
66        void maxFromStr(const char *val);
67        void defFromStr(const char *val);
68        void curFromStr(const char *val);
69
70    private:
71
72        // flag tells if user specified min and max values
73        int _minSet;
74        int _maxSet;
75
76        // hash or linked list of preset values
77        Rp_Chain *_presets;
78
79        struct preset{
80            Accessor<const char *> label;
81            Accessor<const char *> desc;
82            Accessor<const char *> units;
83            Accessor<double> val;
84        };
85
86        void __configureFromXml(ClientData c);
87        void __configureFromTree(ClientData c);
88        void __dumpToXml(ClientData c);
89        void __dumpToTree(ClientData c);
90};
91
92} // namespace Rappture
93
94/*--------------------------------------------------------------------------*/
95/*--------------------------------------------------------------------------*/
96
97#endif
Note: See TracBrowser for help on using the repository browser.