00001 /******************************************************************************* 00002 * Copyright (c) 2006 International Business Machines Corporation 00003 * All rights reserved. This program and the accompanying materials 00004 * are made available under the terms of the Common Public License v1.0 00005 * which accompanies this distribution, and is available at 00006 * http://www.opensource.org/licenses/cpl1.0.php 00007 * 00008 * Contributors: 00009 * Douglas Sprague, Joel Wheeler - initial API and implementation 00010 * 00011 *****************************************************************************/ 00012 00013 #ifndef STILNUMBER_H 00014 #define STILNUMBER_H 00015 00016 #include "stilcom.h" 00017 #include "stilcomstr.h" 00018 #include <math.h> 00019 00020 00021 //--------------------------------------------------------------------------- 00031 //--------------------------------------------------------------------------- 00032 class STILNumber { 00033 00034 // - Friend Classes 00035 // - Overload the insertion operator with an std::ostream and STILNumber object 00036 friend std::ostream& operator<<(std::ostream &ostr,const STILNumber&); 00037 00038 // - Overload the '+' operator for a double value 00039 friend double operator+(double &val,const STILNumber &obj); 00040 00041 // - Overload the '+=' operator for a double value 00042 friend double operator+=(double &val,const STILNumber &obj); 00043 00044 // - Overload the '-' operator for a double value 00045 friend double operator-(double &val,const STILNumber &); 00046 00047 // - Overload the '-=' operator for a double value 00048 friend double operator-=(double &val,const STILNumber &obj); 00049 00050 // - Overload the '*' operator for a double value 00051 friend double operator*(double &val,const STILNumber &); 00052 00053 // - Overload the '*=' operator for a double value 00054 friend double operator*=(double &val,const STILNumber &); 00055 00056 // - Overload the '/' operator for a double value 00057 friend double operator/(double &val,const STILNumber &); 00058 00059 // - Overload the '/=' operator for a double value 00060 friend double operator/=(double &val,const STILNumber &); 00061 00062 // - Overload the '>' operator for a double value 00063 friend BOOLEAN operator>(double val,const STILNumber &); 00064 00065 // - Overload the '>=' operator for a double value 00066 friend BOOLEAN operator>=(double val,const STILNumber &); 00067 00068 // - Overload the '<' operator for a double value 00069 friend BOOLEAN operator<(double val,const STILNumber &); 00070 00071 // - Overload the '<=' operator for a double value 00072 friend BOOLEAN operator<=(double val,const STILNumber &); 00073 00074 // - Overload the '==' operator for a double value 00075 friend BOOLEAN operator==(double val,const STILNumber &); 00076 00077 00078 public: 00079 00080 // - Default Constructor 00081 STILNumber(); 00082 00083 // - Constructor with a character 00084 STILNumber(const char *); 00085 00086 // - Constructor with an sstring object 00087 STILNumber(const sstring &); 00088 00089 // - Copy Constructor 00090 STILNumber(const STILNumber &); 00091 00092 // - Destructor 00093 ~STILNumber(); 00094 00095 // - Overload the assignment operator with a character 00096 STILNumber &operator=(const char *); 00097 00098 // - Overload the assignment operator with a character 00099 STILNumber &operator=(const sstring &); 00100 00101 // - Overload the assignment operator with a STILNumber object 00102 STILNumber & operator=(const STILNumber &); 00103 00104 // - Overload the '+' operator with a character 00105 //STILNumber operator+(const char *); 00106 00107 // - Overload the '+' operator with a STILNumber object 00108 //STILNumber operator+(const STILNumber &); 00109 00110 // - Overload the '*' operator with a character 00111 //STILNumber operator*(const char *); 00112 00113 // - Overload the '*' operator with a type double 00114 //STILNumber operator*(double); 00115 00116 // - Overload the '*' operator with a type LONG 00117 //STILNumber operator*(LONG); 00118 00119 // - Overload the '*' operator with a STILNumber object 00120 //STILNumber operator*(const STILNumber &); 00121 00122 // - Overload the '*=' operator with a STILNumber object 00123 STILNumber & operator*=(const STILNumber &); 00124 00125 // - Overload the '*=' operator with a double value 00126 STILNumber & operator*=(double val); 00127 00128 // - Overload the '-' operator with a STILNumber object 00129 //STILNumber operator-(const STILNumber &); 00130 00131 // - Overload the '-' operator with a character 00132 //STILNumber operator-(const char *); 00133 00134 // - Overload the '-=' operator with a STILNumber object 00135 STILNumber & operator-=(const STILNumber &); 00136 00137 // - Overload the '+=' operator with a STILNumber object 00138 STILNumber & operator+=(const STILNumber &); 00139 00140 // - Overload the '/' operator with a character 00141 //STILNumber operator/(const char *); 00142 00143 // - Overload the '/' operator with a STILNumber object 00144 //STILNumber operator/(const STILNumber &); 00145 00146 // - Overload the '/=' operator with a STILNumber object 00147 STILNumber & operator/=(const STILNumber &); 00148 00149 // - Overload the '<' operator with a character 00150 //BOOLEAN operator<(const char*) const; 00151 00152 // - Overload the '<' operator with a STILNumber object 00153 BOOLEAN operator<(const STILNumber &n) const; 00154 00155 // - Overload the '<=' operator with a character 00156 //BOOLEAN operator<=(const char * val) const; 00157 00158 // - Overload the '<=' operator with a STILNumber object 00159 BOOLEAN operator<=(const STILNumber &) const; 00160 00161 // - Overload the '>' operator with a character 00162 //BOOLEAN operator>(const char*) const; 00163 00164 // - Overload the '>' operator with a STILNumber object 00165 BOOLEAN operator>(const STILNumber &) const; 00166 00167 // - Overload the '>=' operator with a character 00168 //BOOLEAN operator>=(const char* val) const; 00169 00170 // - Overload the '>=' operator with a STILNumber object 00171 BOOLEAN operator>=(const STILNumber &) const; 00172 00173 // - Overload the '==' operator with a STILNumber object 00174 BOOLEAN operator==(const STILNumber &) const; 00175 00176 // - Overload the '==' operator with a type integer 00177 //BOOLEAN operator==(int) const; 00178 00179 // - Overload the '!=' operator with a STILNumber object 00180 //BOOLEAN operator!=(const STILNumber &) const; 00181 00182 // - Overload the '!=' operator with a type integer 00183 //BOOLEAN operator!=(const int &) const; 00184 00185 // - Return the representation as a sstring object 00186 sstring getText() const; 00187 00188 // - Return the representation as a double 00189 double asDouble() const; 00190 00191 // - Determine if an object has been defined 00192 BOOLEAN isDefined() const; 00193 00194 //others: ?? 00195 //getUnits(), getunitprefix() 00196 00197 // - Print this objects values (for debug) 00198 void print(void); 00199 00200 // - Initialize this object 00201 void init(void); 00202 00203 private: 00204 double m_value; // Objects value 00205 sstring m_unit; // (A)mps, (V)olts, ... 00206 00207 int m_modifier; // (-3) mV, (-6) uS 00208 00209 sstring m_text; // string representation 00210 }; 00211 00212 //inlines: 00213 00214 //-------------------------------------------------------------------------- 00222 //-------------------------------------------------------------------------- 00223 // - Destructor 00224 inline STILNumber::~STILNumber() { }; 00225 00226 //-------------------------------------------------------------------------- 00234 //-------------------------------------------------------------------------- 00235 // - Return the representation as a sstring object 00236 inline sstring STILNumber::getText() const { return m_text; } //was asString- use getText to stick with conventions used elsewhere in STIL 00237 00238 //-------------------------------------------------------------------------- 00246 //-------------------------------------------------------------------------- 00247 // - Return the representation as a double 00248 inline double STILNumber::asDouble() const { return (m_value*(pow(10.0,m_modifier))); }//need to multipy value*m_modifier 00249 00250 //-------------------------------------------------------------------------- 00258 //-------------------------------------------------------------------------- 00259 // - Determine if an object has been defined 00260 inline BOOLEAN STILNumber::isDefined() const { return (m_text!=""); } 00261 00262 00263 //-------------------------------------------------------------------------- 00271 //-------------------------------------------------------------------------- 00272 inline BOOLEAN STILNumber::operator<(const STILNumber &n) const { return (asDouble() < n.asDouble()); } 00273 00274 //-------------------------------------------------------------------------- 00282 //-------------------------------------------------------------------------- 00283 inline BOOLEAN STILNumber::operator<=(const STILNumber &n) const 00284 { return ( (asDouble() < n.asDouble()) || (asDouble() == n.asDouble()) ); } 00285 00286 //-------------------------------------------------------------------------- 00294 //-------------------------------------------------------------------------- 00295 inline BOOLEAN STILNumber::operator>(const STILNumber &n) const 00296 { return (asDouble() > n.asDouble()); } 00297 00298 //-------------------------------------------------------------------------- 00306 //-------------------------------------------------------------------------- 00307 inline BOOLEAN STILNumber::operator>=(const STILNumber &n) const 00308 { return ( (asDouble() > n.asDouble()) || (asDouble() == n.asDouble()) ); } 00309 00310 #endif