Changeset 83 for trunk/include/core/RpUnits.h
- Timestamp:
- Oct 5, 2005, 8:17:26 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/core/RpUnits.h
r76 r83 1 /* 2 * ---------------------------------------------------------------------- 3 * RpUnits.h - Header file for Rappture Units 4 * 5 * RpUnits Class Declaration / Definition 6 * 7 * ====================================================================== 8 * AUTHOR: Derrick Kearney, Purdue University 9 * Copyright (c) 2004-2005 10 * Purdue Research Foundation, West Lafayette, IN 11 * ====================================================================== 12 */ 13 1 14 #include <iostream> 2 15 #include <string> … … 11 24 #include "RpUnitsStd.h" 12 25 13 #ifndef _RpUNITS_H 26 #ifndef _RpUNITS_H 14 27 #define _RpUNITS_H 15 28 16 class RpUnits; 29 class RpUnits; 17 30 18 31 class unit … … 30 43 const std::string units; 31 44 double exponent; 32 // RpUnits* basis[4]; 33 RpUnits* basis; 45 RpUnits* basis; 34 46 35 47 unit* prev; 36 48 unit* next; 37 49 38 unit (39 const std::string& units,40 double& exponent,41 // RpUnits** basis,42 RpUnits* basis, 50 // private constructor 51 unit ( 52 const std::string& units, 53 double& exponent, 54 RpUnits* basis, 43 55 unit* next 44 56 ) 45 : units (units), 46 exponent (exponent), 47 basis (basis), 57 : units (units), 58 exponent (exponent), 59 basis (basis), 48 60 prev (NULL), 49 61 next (next) 50 { }; 51 62 {}; 63 64 /* 65 // private copy constructor 66 unit ( unit& other ) 67 : units (other.units), 68 exponent (other.exponent), 69 basis (other.basis), 70 prev (other.prev), 71 next (other.next) 72 {}; 73 74 // copy assignment operator 75 unit& operator= (unit& other) { 76 units = other.units; 77 exponent = other.exponent; 78 basis = other.basis; 79 prev = other.prev; 80 next = other.next; 81 } 82 83 // destructor (its not virtual yet, still testing) 84 ~unit () { 85 86 } 87 */ 52 88 53 89 void newExponent(double newExponent) {exponent = newExponent;}; … … 61 97 // hold the pointer to a function to do the forward conversion (from->to) 62 98 // hold the pointer to a function to do the backward conversion (to->from) 63 // 99 // 64 100 class conversion 65 101 { … … 68 104 const RpUnits* getFrom() { return (const RpUnits*) fromPtr; }; 69 105 const RpUnits* getTo() { return (const RpUnits*) toPtr; }; 70 106 71 107 friend class RpUnits; 72 108 … … 86 122 87 123 // constructor 88 // private because i only want RpUnits to be able to 124 // private because i only want RpUnits to be able to 89 125 // create a conversion 90 conversion ( 91 RpUnits* fromPtr, 92 RpUnits* toPtr, 126 conversion ( 127 RpUnits* fromPtr, 128 RpUnits* toPtr, 93 129 double (*convForwFxnPtr)(double), 94 130 double (*convBackFxnPtr)(double), … … 97 133 ) 98 134 : fromPtr (fromPtr), 99 toPtr (toPtr), 135 toPtr (toPtr), 100 136 convForwFxnPtr (convForwFxnPtr), 101 137 convBackFxnPtr (convBackFxnPtr), … … 106 142 prev (prev), 107 143 next (next) 108 { 109 }; 110 111 conversion ( 144 {}; 145 146 conversion ( 112 147 RpUnits* fromPtr, 113 148 RpUnits* toPtr, … … 120 155 ) 121 156 : fromPtr (fromPtr), 122 toPtr (toPtr), 157 toPtr (toPtr), 123 158 convForwFxnPtr (NULL), 124 159 convBackFxnPtr (NULL), … … 129 164 prev (prev), 130 165 next (next) 131 { 132 }; 166 {}; 133 167 134 168 // copy constructor … … 139 173 // used by the RpUnits class to create a linked list of the conversions 140 174 // associated with the specific unit. 141 // 175 // 142 176 // we could templitize this and make a generic linked list 143 177 // or could use generic linked list class from book programming with objects … … 156 190 convEntry* next; 157 191 158 convEntry ( 159 conversion* conv, 192 convEntry ( 193 conversion* conv, 160 194 convEntry* prev, 161 195 convEntry* next 162 196 ) 163 : conv (conv), 197 : conv (conv), 164 198 prev (prev), 165 199 next (next) 166 { 200 {}; 167 201 168 202 /* … … 176 210 class RpUnits 177 211 { 178 /* 212 /* 179 213 * helpful units site 180 214 * http://aurora.regenstrief.org/~gunther/units.html … … 182 216 183 217 public: 184 218 185 219 // users member fxns 186 220 std::string getUnits(); … … 190 224 191 225 // convert from one RpUnits to another if the conversion is defined 192 double convert(RpUnits* toUnits, double val, int* result = NULL); 226 double convert(RpUnits* toUnits, double val, int* result = NULL); 193 227 // convert from one RpUnits to another if the conversion is defined 194 void* convert(RpUnits* toUnits, void* val, int* result = NULL); 228 void* convert(RpUnits* toUnits, void* val, int* result = NULL); 195 229 // convert from one RpUnits to another if the conversion is defined 196 double convert(std::string, double val); 230 double convert(std::string, double val); 197 231 // convert from one RpUnits to another if the conversion is defined 198 std::string convert ( RpUnits* toUnits, 199 double val, 200 int showUnits = 0, 201 int* result = NULL ); 232 std::string convert ( RpUnits* toUnits, 233 double val, 234 int showUnits = 0, 235 int* result = NULL ); 202 236 203 237 static std::string convert ( std::string val, … … 210 244 211 245 // turn the current unit to the metric system 212 // this should only be used for units that are part of the 246 // this should only be used for units that are part of the 213 247 // metric system. doesnt deal with exponents, just prefixes 214 248 double makeBasis(double value, int* result = NULL); 215 249 RpUnits & makeBasis(double* value, int* result = NULL); 216 250 217 251 static int makeMetric(RpUnits * basis); 218 252 … … 222 256 static RpUnits* find(std::string key) 223 257 { 224 // dict.find seems to return a (RpUnits* const) so i had to 258 // dict.find seems to return a (RpUnits* const) so i had to 225 259 // cast it as a (RpUnits*) 226 260 227 261 // dict pointer 228 // RpUnits* unitEntry = (RpUnits*) *(dict.find(key).getValue()); 229 RpUnits* unitEntry = (RpUnits*) *(dict->find(key).getValue()); 230 231 // RpUnits* unitEntry = (RpUnits*) dEntr.getValue(); 262 RpUnits* unitEntry = (RpUnits*) *(dict->find(key).getValue()); 232 263 233 264 // dict pointer 234 // if (unitEntry == (RpUnits*)dict.getNullEntry().getValue()) {235 265 if (unitEntry == (RpUnits*)dict->getNullEntry().getValue()) { 236 266 unitEntry = NULL; … … 246 276 static RpUnits * defineCmplx(const std::string units,RpUnits * basis); 247 277 // 248 // add relation rule 249 250 static RpUnits * define(RpUnits* from, 251 RpUnits* to, 278 // add relation rule 279 280 static RpUnits * define(RpUnits* from, 281 RpUnits* to, 252 282 double (*convForwFxnPtr)(double), 253 283 double (*convBackFxnPtr)(double)); 254 284 255 static RpUnits * define(RpUnits* from, 256 RpUnits* to, 285 static RpUnits * define(RpUnits* from, 286 RpUnits* to, 257 287 void* (*convForwFxnPtr)(void*, void*), 258 288 void* convForwData, … … 271 301 static int addPresets (std::string group); 272 302 273 // undefining a relation rule is probably not needed 303 // undefining a relation rule is probably not needed 274 304 // int undefine(); // delete a relation 275 305 … … 279 309 280 310 // why are these functions friends... 281 // probably need to find a better way to let RpUnits 311 // probably need to find a better way to let RpUnits 282 312 // use the RpDict and RpDictEntry fxns 283 313 friend class RpDict<std::string,RpUnits*>; … … 286 316 // copy constructor 287 317 RpUnits ( const RpUnits& myRpUnit ) 288 { 318 { 289 319 290 320 /* … … 295 325 */ 296 326 297 // copy constructor for unit 327 // copy constructor for unit 298 328 unit* tmp = NULL; 299 329 unit* newUnit = NULL; … … 319 349 320 350 head = tmp; 321 351 322 352 }; 323 353 324 354 /* 355 // copy assignment operator 325 356 RpUnits& operator= (const RpUnits& myRpUnit) { 326 357 … … 332 363 } 333 364 */ 334 365 335 366 private: 336 367 … … 348 379 // move through the linked list, only converting the metric elements. 349 380 // 350 381 351 382 // used by the RpUnits when defining units elements 352 383 unit* head; … … 371 402 372 403 373 RpUnits ( 374 const std::string& units, 375 double& exponent, 376 // RpUnits* basis[] 404 RpUnits ( 405 const std::string& units, 406 double& exponent, 377 407 RpUnits* basis 378 408 ) … … 386 416 387 417 388 389 RpUnits ( 418 419 RpUnits ( 390 420 RpUnits* from, 391 421 RpUnits* to, … … 397 427 : head (NULL), 398 428 convList (NULL), 399 conv (new conversion 429 conv (new conversion 400 430 (from,to,convForwFxnPtr,convBackFxnPtr,prev,next)) 401 { 431 { 402 432 connectConversion(from); 403 433 connectConversion(to); … … 407 437 408 438 409 410 RpUnits ( 439 440 RpUnits ( 411 441 RpUnits* from, 412 442 RpUnits* to, … … 426 456 ) 427 457 ) 428 { 458 { 429 459 connectConversion(from); 430 460 connectConversion(to); … … 457 487 // returns 0 on success (object inserted or already exists) 458 488 // returns !0 on failure (object cannot be inserted or dne) 459 int RpUnits::insert(std::string key); 489 int RpUnits::insert(std::string key); 460 490 461 491 // link two RpUnits objects that already exist in RpUnitsTable
Note: See TracChangeset
for help on using the changeset viewer.