Changeset 116 for trunk/include/core
- Timestamp:
- Oct 26, 2005, 11:32:52 PM (19 years ago)
- Location:
- trunk/include/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/core/RpUnits.h
r115 r116 15 15 #include <iostream> 16 16 #include <string> 17 #include <list> 17 18 #include <sstream> 18 19 #include <stdlib.h> 19 20 #include <errno.h> 20 21 #ifndef _RpDICT_H 22 #include "RpDict.h" 23 #endif 24 21 #include <math.h> 22 23 #include "RpDict.h" 25 24 #include "RpUnitsStd.h" 26 25 … … 28 27 #define _RpUNITS_H 29 28 29 #define LIST_TEMPLATE RpUnitsListEntry 30 31 // should the define function: 32 // 1. compare portions of inStr to unit names that have previously 33 // been defined (you must parse in order for this option to work) 34 #define COMPARE_MASK 1 35 // 2. create a unit if no unit by the name exists. 36 #define CREATE_MASK 2 37 // 3. parse the unit name to try to find previously defined units. 38 #define PARSE_MASK 4 39 30 40 class RpUnits; 31 41 32 class unit 33 { 34 42 class RpUnitsPreset { 35 43 public: 36 37 const std::string getUnits(){ return units; }; 38 double getExponent() {return exponent;}; 39 const RpUnits * getBasis() {return basis;}; 40 41 friend class RpUnits; 42 43 private: 44 const std::string units; 45 double exponent; 46 const RpUnits* basis; 47 48 unit* prev; 49 unit* next; 50 51 // private constructor 52 unit ( 53 const std::string& units, 54 double& exponent, 55 const RpUnits* basis, 56 unit* prev, 57 unit* next 58 ) 59 : units (units), 60 exponent (exponent), 61 basis (basis), 62 prev (prev), 63 next (next) 64 {}; 65 66 /* 67 // private copy constructor 68 unit ( const unit& other ) 69 : units other.units, 70 exponent other.exponent, 71 basis other.basis, 72 prev unit(other.prev), 73 next unit(other.next) 74 {}; 75 76 // copy assignment operator 77 unit& operator= (unit& other) 78 : units other.units, 79 exponent other.exponent, 80 basis RpUnits(other.basis), 81 prev unit(other.prev), 82 next unit(other.next) 83 {} 84 */ 85 86 /* 87 // destructor (its not virtual yet, still testing) 88 ~unit () { 89 90 } 91 */ 92 93 void newExponent(double newExponent) {exponent = newExponent;}; 94 95 44 RpUnitsPreset () { 45 addPresetAll(); 46 }; 47 48 static int addPresetAll(); 49 static int addPresetEnergy(); 50 static int addPresetLength(); 51 static int addPresetTemp(); 52 static int addPresetTime(); 53 static int addPresetVolume(); 96 54 }; 97 55 … … 256 214 }; 257 215 216 class RpUnitsListEntry 217 { 218 219 public: 220 221 // constructor 222 RpUnitsListEntry (const RpUnits* unit, double exponent) 223 : unit (unit), 224 exponent (exponent) 225 {}; 226 227 // copy constructor 228 RpUnitsListEntry (const RpUnitsListEntry& other) 229 : unit (other.unit), 230 exponent (other.exponent) 231 {}; 232 233 // copy assignment operator 234 RpUnitsListEntry& operator= (const RpUnitsListEntry& other) { 235 unit = other.unit; 236 exponent = other.exponent; 237 return *this; 238 } 239 240 // negate the exponent 241 void negateExponent() const; 242 243 // print the name of the object 244 std::string name() const; 245 246 // report the basis of the RpUnits object being stored. 247 const RpUnits* getBasis() const; 248 249 // return the RpUnits* 250 const RpUnits* getUnitsObj() const; 251 252 // return the exponent 253 double getExponent() const; 254 255 // destructor 256 virtual ~RpUnitsListEntry () 257 {} 258 259 private: 260 261 const RpUnits* unit; 262 mutable double exponent; 263 }; 264 258 265 class RpUnits 259 266 { … … 261 268 * helpful units site 262 269 * http://aurora.regenstrief.org/~gunther/units.html 270 * http://www.nodc.noaa.gov/dsdt/ucg/ 271 * http://www.cellml.org/meeting_minutes/archive/ 272 * 20010110_meeting_minutes.html 263 273 */ 264 274 … … 272 282 273 283 // convert from one RpUnits to another if the conversion is defined 274 double convert( const RpUnits* toUnits, 275 double val, 284 double convert( const RpUnits* toUnits, 285 double val, 276 286 int* result=NULL ) const; 277 287 // convert from one RpUnits to another if the conversion is defined … … 292 302 int* result = NULL ); 293 303 304 /* 305 static std::string convert ( std::string val, 306 std::string toUnits, 307 int showUnits, 308 int* result = NULL ); 309 */ 310 294 311 // dictionary to store the units. 295 312 // static RpDict<std::string,RpUnits> dict; … … 312 329 // add RpUnits Object 313 330 static RpUnits * define(const std::string units, 314 const RpUnits* basis); 315 // unsigned int create=0); 316 static RpUnits * defineCmplx( const std::string units, 317 const RpUnits* basis); 331 const RpUnits* basis=NULL ); 332 // static RpUnits * defineCmplx( const std::string units, 333 // const RpUnits* basis); 318 334 // 319 335 // add relation rule … … 357 373 friend class RpDictEntry<std::string,RpUnits*>; 358 374 375 friend int insert(std::string key,RpUnits* val); 376 377 359 378 // copy constructor 360 379 RpUnits (RpUnits &other) 361 : head (NULL), 380 : units (other.units), 381 exponent (other.exponent), 382 basis (other.basis), 362 383 convList (NULL) 363 384 { 364 unit* p = NULL;365 unit* current = NULL;366 385 convEntry* q = NULL; 367 convEntry* curr 2= NULL;386 convEntry* curr = NULL; 368 387 369 388 dict = other.dict; 370 389 371 if (other.head) {372 p = other.head;373 head = new unit(p->units, p->exponent, p->basis, NULL, NULL);374 current = head;375 376 while (p->next) {377 p = p->next;378 current->next = new unit( p->units,379 p->exponent,380 p->basis,381 current,382 NULL );383 current = current->next;384 }385 }386 390 if (other.convList) { 387 391 q = other.convList; 388 392 convList = new convEntry (q->conv,NULL,NULL); 389 curr 2= convList;393 curr = convList; 390 394 while (q->next) { 391 395 q = q->next; 392 curr 2->next = new convEntry (q->conv,curr2,NULL);393 curr 2 = curr2->next;396 curr->next = new convEntry (q->conv,curr,NULL); 397 curr = curr->next; 394 398 } 395 399 } … … 399 403 RpUnits& operator= (const RpUnits& other) { 400 404 401 unit* p = NULL;402 unit* current = NULL;403 405 convEntry* q = NULL; 404 convEntry* curr 2= NULL;406 convEntry* curr = NULL; 405 407 406 408 if ( this != &other ) { 407 delete head;408 409 delete convList; 409 410 } 410 411 411 412 dict = other.dict; 412 413 if (other.head) { 414 p = other.head; 415 head = new unit(p->units, p->exponent, p->basis, NULL, NULL); 416 current = head; 417 418 while (p->next) { 419 p = p->next; 420 current->next = new unit( p->units, 421 p->exponent, 422 p->basis, 423 current, 424 NULL ); 425 current = current->next; 426 } 427 } 413 units = other.units; 414 exponent = other.exponent; 415 basis = other.basis; 416 428 417 if (other.convList) { 429 418 q = other.convList; 430 419 convList = new convEntry (q->conv,NULL,NULL); 431 curr 2= convList;420 curr = convList; 432 421 while (q->next) { 433 422 q = q->next; 434 curr 2->next = new convEntry (q->conv,curr2,NULL);435 curr 2 = curr2->next;423 curr->next = new convEntry (q->conv,curr,NULL); 424 curr = curr->next; 436 425 } 437 426 } … … 446 435 // clean up dynamic memory 447 436 448 unit* p = head; 449 unit* tmp = p; 450 convEntry* p2 = convList; 451 convEntry* tmp2 = p2; 437 convEntry* p = convList; 438 convEntry* tmp = p; 452 439 453 440 while (p != NULL) { … … 455 442 p = p->next; 456 443 delete tmp; 457 }458 459 while (p2 != NULL) {460 tmp2 = p2;461 p2 = p2->next;462 delete tmp2;463 444 } 464 445 } … … 480 461 // 481 462 482 // used by the RpUnits when defining units elements 483 unit* head; 463 std::string units; 464 double exponent; 465 const RpUnits* basis; 484 466 485 467 // linked list of units this RpUnit can convert to … … 501 483 // 502 484 503 504 505 485 RpUnits ( 506 486 const std::string& units, … … 508 488 const RpUnits* basis 509 489 ) 510 : head ( new unit( units, exponent, basis, NULL, NULL) ), 490 : units (units), 491 exponent (exponent), 492 basis (basis), 511 493 convList (NULL) 512 494 {}; 513 514 void RpUnits::connectConversion(conversion* conv) const;515 495 516 496 // insert new RpUnits object into RpUnitsTable 517 497 // returns 0 on success (object inserted or already exists) 518 498 // returns !0 on failure (object cannot be inserted or dne) 519 int RpUnits::insert(std::string key); 520 521 // link two RpUnits objects that already exist in RpUnitsTable 522 // returns 0 on success (linking within table was successful) 523 // returns !0 on failure (linking was not successful) 524 // int RpUnits::link(RpUnits * unitA); 525 526 527 static int pre_compare( std::string& units, 528 const RpUnits* basis = NULL); 529 530 void addUnit( const std::string& units, 531 double & exponent, 532 const RpUnits * basis 533 ); 534 535 static int addPresetAll(); 536 static int addPresetEnergy(); 537 static int addPresetLength(); 538 static int addPresetTemp(); 539 static int addPresetTime(); 540 static int addPresetVolume(); 541 499 // int RpUnits::insert(std::string key) const; 500 501 typedef std::list<LIST_TEMPLATE> RpUnitsList; 502 typedef RpUnitsList::iterator RpUnitsListIter; 503 504 void newExponent(double newExponent) {exponent = newExponent;}; 505 506 static int units2list( const std::string& inUnits, 507 RpUnitsList& outList ); 508 static int grabExponent(const std::string& inStr, double* exp); 509 static int grabUnitString( const std::string& inStr); 510 static const RpUnits* grabUnits (std::string inStr, int* offset); 511 static int negateListExponents(RpUnitsList& unitsList); 512 static int RpUnits::printList(RpUnitsList& unitsList); 513 514 static int RpUnits::compareListEntryBasis( RpUnitsList& fromList, 515 RpUnitsListIter& fromIter, 516 RpUnitsListIter& toIter); 517 518 static int RpUnits::compareListEntrySearch( RpUnitsList& fromList, 519 RpUnitsListIter& fromIter, 520 RpUnitsListIter& toIter); 521 522 void RpUnits::connectConversion(conversion* conv) const; 542 523 543 524 }; -
trunk/include/core/RpUnitsStd.h
r115 r116 12 12 #endif 13 13 14 double centi2base (double centi , double power);15 double milli2base (double milli , double power);16 double micro2base (double micro , double power);17 double nano2base (double nano , double power);18 double pico2base (double pico , double power);19 double femto2base (double femto , double power);20 double atto2base (double atto , double power);21 double kilo2base (double kilo , double power);22 double mega2base (double mega , double power);23 double giga2base (double giga , double power);24 double tera2base (double tera , double power);25 double peta2base (double peta , double power);14 double centi2base (double centi); 15 double milli2base (double milli); 16 double micro2base (double micro); 17 double nano2base (double nano); 18 double pico2base (double pico); 19 double femto2base (double femto); 20 double atto2base (double atto); 21 double kilo2base (double kilo); 22 double mega2base (double mega); 23 double giga2base (double giga); 24 double tera2base (double tera); 25 double peta2base (double peta); 26 26 27 27 28 28 29 double base2centi (double base , double power);30 double base2milli (double base , double power);31 double base2micro (double base , double power);32 double base2nano (double base , double power);33 double base2pico (double base , double power);34 double base2femto (double base , double power);35 double base2atto (double base , double power);36 double base2kilo (double base , double power);37 double base2mega (double base , double power);38 double base2giga (double base , double power);39 double base2tera (double base , double power);40 double base2peta (double base , double power);29 double base2centi (double base); 30 double base2milli (double base); 31 double base2micro (double base); 32 double base2nano (double base); 33 double base2pico (double base); 34 double base2femto (double base); 35 double base2atto (double base); 36 double base2kilo (double base); 37 double base2mega (double base); 38 double base2giga (double base); 39 double base2tera (double base); 40 double base2peta (double base); 41 41 42 42 43 43 44 double angstrom2meter (double angstrom , double power);45 double meter2angstrom (double meter s, double power);46 double meter2inch (double m , double power);47 double inch2meter (double in , double power);48 double meter2feet (double m , double power);49 double feet2meter (double ft , double power);50 double meter2yard (double m , double power);51 double yard2meter (double yd , double power);44 double angstrom2meter (double angstrom); 45 double meter2angstrom (double meter); 46 double meter2inch (double meter); 47 double inch2meter (double in); 48 double meter2feet (double meter); 49 double feet2meter (double ft); 50 double meter2yard (double meter); 51 double yard2meter (double yd); 52 52 53 53 … … 71 71 72 72 73 double cubicMeter2usGallon (double m3 , double none);74 double usGallon2cubicMeter (double g , double none);75 double cubicFeet2usGallon (double ft3 , double none);76 double usGallon2cubicFeet (double g , double none);73 double cubicMeter2usGallon (double m3); 74 double usGallon2cubicMeter (double gal); 75 double cubicFeet2usGallon (double ft3); 76 double usGallon2cubicFeet (double gal); 77 77 78 78
Note: See TracChangeset
for help on using the changeset viewer.