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