1 | #include <iostream> |
---|
2 | #include <string> |
---|
3 | #include <sstream> |
---|
4 | #include <stdlib.h> |
---|
5 | #include <errno.h> |
---|
6 | |
---|
7 | |
---|
8 | // #include "RpLibrary.h" |
---|
9 | |
---|
10 | #ifndef _RpVARIABLE_H |
---|
11 | #include "RpVariable.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #ifndef _RpUNITS_H |
---|
15 | #include "RpUnits.h" |
---|
16 | #endif |
---|
17 | |
---|
18 | #ifndef _RpNUMBER_H |
---|
19 | #define _RpNUMBER_H |
---|
20 | |
---|
21 | class RpNumber : public RpVariable |
---|
22 | { |
---|
23 | public: |
---|
24 | |
---|
25 | // users member fxns |
---|
26 | |
---|
27 | /* |
---|
28 | virtual RpNumber& setUnits(std::string newUnits); |
---|
29 | */ |
---|
30 | |
---|
31 | virtual RpNumber& setDefaultValue(double newDefaultVal); |
---|
32 | virtual RpNumber& setCurrentValue(double newCurrentVal); |
---|
33 | virtual RpNumber& setMin(double newMin); |
---|
34 | virtual RpNumber& setMax(double newMax); |
---|
35 | |
---|
36 | std::string getUnits() const; |
---|
37 | // changed from "Value" to "Val" because base class makes |
---|
38 | // these functions virtual and derived class has a different |
---|
39 | // return type. compiler doesnt like this. need to find another |
---|
40 | // way around this |
---|
41 | // |
---|
42 | // if we keep the null_val=NULL will that give us undefined behavior? |
---|
43 | // |
---|
44 | double getDefaultValue(void* null_val=NULL) const; |
---|
45 | double getCurrentValue(void* null_val=NULL) const; |
---|
46 | double getMin() const; |
---|
47 | double getMax() const; |
---|
48 | |
---|
49 | double convert( std::string toUnitStr, |
---|
50 | int storeResult, |
---|
51 | int* result = NULL ); |
---|
52 | double convert(std::string toUnitStr, int* result = NULL); |
---|
53 | double convert(RpUnits* toUnit, int* result = NULL); |
---|
54 | |
---|
55 | // place the information from this object into the xml library 'lib' |
---|
56 | // virtual RpNumber& put(RpLibrary lib); |
---|
57 | // RpNumber& put() const; |
---|
58 | |
---|
59 | |
---|
60 | |
---|
61 | /* |
---|
62 | * user provides a 'path' for where this object lives in xml file |
---|
63 | * user calls define with standard hints as described in Number docs |
---|
64 | * 'units' - string providing units of the number |
---|
65 | * 'defaultVal' - numeric value to be used if user provides no value |
---|
66 | * 'min' - (optional) minimum allowed value |
---|
67 | * 'max' - (optional) maximum allowed value |
---|
68 | * 'label' - (optional) name of the input for a gui field |
---|
69 | * 'desc' - (optional) description of the input for the gui |
---|
70 | * |
---|
71 | * Notes: |
---|
72 | * if the user sets a min or max value the following applies: |
---|
73 | * if the value of min is greater than the value of default, |
---|
74 | * then min will be set to default |
---|
75 | * |
---|
76 | * if the value of max is less than the value of default, |
---|
77 | * then max will be set to default. |
---|
78 | * |
---|
79 | * |
---|
80 | * |
---|
81 | */ |
---|
82 | |
---|
83 | /* what about unit-less numbers */ |
---|
84 | RpNumber ( |
---|
85 | std::string path, |
---|
86 | std::string units, |
---|
87 | double defaultVal |
---|
88 | ) |
---|
89 | : RpVariable (path, new double (defaultVal) ), |
---|
90 | // units (units), |
---|
91 | min (0), |
---|
92 | max (0), |
---|
93 | minmaxSet (0) |
---|
94 | { |
---|
95 | this->units = RpUnits::find(units); |
---|
96 | if (! this->units) { |
---|
97 | this->units = RpUnits::define(units,NULL); |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | RpNumber ( |
---|
102 | std::string path, |
---|
103 | std::string units, |
---|
104 | double defaultVal, |
---|
105 | double min, |
---|
106 | double max, |
---|
107 | std::string label, |
---|
108 | std::string desc |
---|
109 | ) |
---|
110 | : RpVariable (path, new double (defaultVal), label, desc), |
---|
111 | // units (units), |
---|
112 | min (min), |
---|
113 | max (max), |
---|
114 | minmaxSet (0) |
---|
115 | { |
---|
116 | |
---|
117 | this->units = RpUnits::find(units); |
---|
118 | if (! this->units) { |
---|
119 | this->units = RpUnits::define(units,NULL); |
---|
120 | } |
---|
121 | |
---|
122 | if ((min == 0) && (max == 0)) { |
---|
123 | minmaxSet = 0; |
---|
124 | } |
---|
125 | else { |
---|
126 | |
---|
127 | if (min > defaultVal) { |
---|
128 | this->min = defaultVal; |
---|
129 | } |
---|
130 | |
---|
131 | if (max < defaultVal) { |
---|
132 | this->max = defaultVal; |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | } |
---|
137 | |
---|
138 | // copy constructor |
---|
139 | RpNumber ( const RpNumber& myRpNumber ) |
---|
140 | : RpVariable(myRpNumber), |
---|
141 | units (myRpNumber.units), |
---|
142 | min (myRpNumber.min), |
---|
143 | max (myRpNumber.max), |
---|
144 | minmaxSet (myRpNumber.minmaxSet) |
---|
145 | {} |
---|
146 | |
---|
147 | // default destructor |
---|
148 | // virtual ~RpNumber () |
---|
149 | virtual ~RpNumber () |
---|
150 | { |
---|
151 | // clean up dynamic memory |
---|
152 | |
---|
153 | } |
---|
154 | private: |
---|
155 | |
---|
156 | // std::string units; |
---|
157 | RpUnits* units; |
---|
158 | double min; |
---|
159 | double max; |
---|
160 | |
---|
161 | // flag to tell if the user specified the min and max values |
---|
162 | int minmaxSet; |
---|
163 | |
---|
164 | }; |
---|
165 | |
---|
166 | /*--------------------------------------------------------------------------*/ |
---|
167 | /*--------------------------------------------------------------------------*/ |
---|
168 | |
---|
169 | #endif |
---|