Changeset 104 for trunk/src/core/RpUnits.cc
- Timestamp:
- Oct 14, 2005, 9:43:27 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/RpUnits.cc
r103 r104 23 23 ************************************************************************/ 24 24 25 RpUnits * RpUnits::define(const std::string units, RpUnits * basis) 26 { 25 RpUnits * 26 RpUnits::define(const std::string units, const RpUnits* basis) { 27 27 28 RpUnits * newRpUnit = NULL; 28 29 … … 187 188 ************************************************************************/ 188 189 189 RpUnits * RpUnits::defineCmplx ( const std::string units, RpUnits * basis ) 190 { 190 RpUnits * 191 RpUnits::defineCmplx ( const std::string units, const RpUnits* basis ) { 192 191 193 RpUnits * newRpUnit = NULL; 192 194 … … 427 429 * 428 430 ************************************************************************/ 429 RpUnits * RpUnits::define( RpUnits* from, 430 RpUnits* to, 431 double (*convForwFxnPtr)(double), 432 double (*convBackFxnPtr)(double)) 433 { 431 RpUnits * 432 RpUnits::define( const RpUnits* from, 433 const RpUnits* to, 434 double (*convForwFxnPtr)(double), 435 double (*convBackFxnPtr)(double)) { 436 434 437 RpUnits* conv = new RpUnits( from, 435 438 to, … … 442 445 } 443 446 444 RpUnits * RpUnits::define( RpUnits* from, 445 RpUnits* to, 446 double (*convForwFxnPtr)(double,double), 447 double (*convBackFxnPtr)(double,double)) 448 { 447 RpUnits * 448 RpUnits::define( const RpUnits* from, 449 const RpUnits* to, 450 double (*convForwFxnPtr)(double,double), 451 double (*convBackFxnPtr)(double,double)) { 452 449 453 RpUnits* conv = new RpUnits( from, 450 454 to, … … 457 461 } 458 462 459 RpUnits * RpUnits::define( RpUnits* from, 460 RpUnits* to, 461 void* (*convForwFxnPtr)(void*, void*), 462 void* convForwData, 463 void* (*convBackFxnPtr)(void*, void*), 464 void* convBackData) 465 { 463 RpUnits * 464 RpUnits::define( const RpUnits* from, 465 const RpUnits* to, 466 void* (*convForwFxnPtr)(void*, void*), 467 void* convForwData, 468 void* (*convBackFxnPtr)(void*, void*), 469 void* convBackData) { 470 466 471 RpUnits* conv = new RpUnits( from, 467 472 to, … … 480 485 * report the units this object represents back to the user 481 486 * 482 * **********************************************************************/ 483 std::string RpUnits::getUnits() 484 { 487 ************************************************************************/ 488 489 /**********************************************************************/ 490 // METHOD: getUnits() 491 // /// Report the text portion of the units of this object back to caller. 492 // /** 493 // * See Also getUnitsName(). 494 // */ 495 // 496 std::string 497 RpUnits::getUnits() const { 498 485 499 std::stringstream unitText; 486 500 unit* p = head; … … 498 512 * report the units this object represents back to the user 499 513 * 500 * **********************************************************************/ 501 std::string RpUnits::getUnitsName() 502 { 514 ************************************************************************/ 515 516 /**********************************************************************/ 517 // METHOD: getUnitsName() 518 // /// Report the full name of the units of this object back to caller. 519 // /** 520 // * Reports the full text and exponent of the units represented by this 521 // * object, back to the caller. Note that if the exponent == 1, no 522 // * exponent will be printed. 523 // */ 524 // 525 std::string 526 RpUnits::getUnitsName() const { 527 503 528 std::stringstream unitText; 504 529 unit* p = head; … … 527 552 * 528 553 * **********************************************************************/ 529 double RpUnits::getExponent() 530 { 554 /**********************************************************************/ 555 // METHOD: getExponent() 556 // /// Report the exponent of the units of this object back to caller. 557 // /** 558 // * Reports the exponent of the units represented by this 559 // * object, back to the caller. Note that if the exponent == 1, no 560 // * exponent will be printed. 561 // */ 562 // 563 double 564 RpUnits::getExponent() const { 565 531 566 return head->getExponent(); 532 567 } … … 537 572 * 538 573 * **********************************************************************/ 539 RpUnits * RpUnits::getBasis() 540 { 574 /**********************************************************************/ 575 // METHOD: getBasis() 576 // /// Retrieve the RpUnits object representing the basis of this object. 577 // /** 578 // * Returns a pointer to a RpUnits object which, on success, points to the 579 // * RpUnits object that is the basis of the calling object. 580 // */ 581 // 582 const RpUnits * 583 RpUnits::getBasis() const { 584 541 585 // check if head exists? 586 if (!head) { 587 // raise error for badly formed Rappture Units object 588 } 589 542 590 return head->getBasis(); 543 591 } … … 553 601 * 554 602 ************************************************************************/ 555 double RpUnits::makeBasis(double value, int* result)556 {557 558 RpUnits* basis = getBasis();603 double 604 RpUnits::makeBasis(double value, int* result) const { 605 606 const RpUnits* basis = getBasis(); 559 607 double retVal = value; 560 608 … … 567 615 // do nothing 568 616 569 if (result) {570 *result = 1;571 }617 // if (result) { 618 // *result = 1; 619 // } 572 620 } 573 621 else { … … 578 626 } 579 627 580 RpUnits& RpUnits::makeBasis(double* value, int* result) 581 {582 RpUnits* basis = getBasis();628 const RpUnits& 629 RpUnits::makeBasis(double* value, int* result) const { 630 const RpUnits* basis = getBasis(); 583 631 double retVal = *value; 584 632 int convResult = 0; … … 588 636 // do nothing 589 637 590 if (result) {591 *result = 1;592 }638 // if (result) { 639 // *result = 1; 640 // } 593 641 } 594 642 else { … … 603 651 *result = convResult; 604 652 } 605 606 607 653 608 654 return *this; … … 616 662 * 617 663 * **********************************************************************/ 618 /* 619 int RpUnits::makeMetric(RpUnits * basis) { 664 665 int 666 RpUnits::makeMetric(const RpUnits * basis) { 620 667 621 668 if (!basis) { … … 623 670 } 624 671 625 std::string basisName = basis->getUnits ();672 std::string basisName = basis->getUnitsName(); 626 673 std::string name; 627 674 std::string forw, back; … … 677 724 return (1); 678 725 } 679 */ 680 681 int RpUnits::makeMetric(RpUnits * basis) { 682 683 if (!basis) { 684 return 0; 685 } 686 687 std::string basisName = basis->getUnitsName(); 688 std::string name; 689 std::string forw, back; 690 691 name = "c" + basisName; 692 RpUnits * centi = RpUnits::define(name, basis); 693 RpUnits::define(centi, basis, centi2base, base2centi); 694 695 name = "m" + basisName; 696 RpUnits * milli = RpUnits::define(name, basis); 697 RpUnits::define(milli, basis, milli2base, base2milli); 698 699 name = "u" + basisName; 700 RpUnits * micro = RpUnits::define(name, basis); 701 RpUnits::define(micro, basis, micro2base, base2micro); 702 703 name = "n" + basisName; 704 RpUnits * nano = RpUnits::define(name, basis); 705 RpUnits::define(nano, basis, nano2base, base2nano); 706 707 name = "p" + basisName; 708 RpUnits * pico = RpUnits::define(name, basis); 709 RpUnits::define(pico, basis, pico2base, base2pico); 710 711 name = "f" + basisName; 712 RpUnits * femto = RpUnits::define(name, basis); 713 RpUnits::define(femto, basis, femto2base, base2femto); 714 715 name = "a" + basisName; 716 RpUnits * atto = RpUnits::define(name, basis); 717 RpUnits::define(atto, basis, atto2base, base2atto); 718 719 name = "k" + basisName; 720 RpUnits * kilo = RpUnits::define(name, basis); 721 RpUnits::define(kilo, basis, kilo2base, base2kilo); 722 723 name = "M" + basisName; 724 RpUnits * mega = RpUnits::define(name, basis); 725 RpUnits::define(mega, basis, mega2base, base2mega); 726 727 name = "G" + basisName; 728 RpUnits * giga = RpUnits::define(name, basis); 729 RpUnits::define(giga, basis, giga2base, base2giga); 730 731 name = "T" + basisName; 732 RpUnits * tera = RpUnits::define(name, basis); 733 RpUnits::define(tera, basis, tera2base, base2tera); 734 735 name = "P" + basisName; 736 RpUnits * peta = RpUnits::define(name, basis); 737 RpUnits::define(peta, basis, peta2base, base2peta); 738 739 return (1); 740 } 741 742 743 RpUnits* 744 RpUnits::find(std::string key) 745 { 726 727 728 const RpUnits* 729 RpUnits::find(std::string key) { 730 746 731 // dict.find seems to return a (RpUnits* const) so i had to 747 732 // cast it as a (RpUnits*) 748 733 749 734 // dict pointer 750 RpUnits* unitEntry = (RpUnits*)*(dict->find(key).getValue());735 const RpUnits* unitEntry = *(dict->find(key).getValue()); 751 736 752 737 // dict pointer 753 if (unitEntry == (RpUnits*)dict->getNullEntry().getValue()) {738 if (unitEntry == *(dict->getNullEntry().getValue()) ) { 754 739 unitEntry = NULL; 755 740 } … … 768 753 int* result ) { 769 754 770 RpUnits* toUnits = NULL;771 RpUnits* fromUnits = NULL;755 const RpUnits* toUnits = NULL; 756 const RpUnits* fromUnits = NULL; 772 757 std::string tmpNumVal = ""; 773 758 std::string fromUnitsName = ""; … … 849 834 if ( (result) && (*result == 0) ) { 850 835 *result = convResult; 851 }836 } 852 837 853 838 return convVal; … … 855 840 } 856 841 857 std::string RpUnits::convert ( RpUnits* toUnits, 858 double val, 859 int showUnits, 860 int* result ) 861 { 842 std::string 843 RpUnits::convert ( const RpUnits* toUnits, 844 double val, 845 int showUnits, 846 int* result ) const { 847 862 848 double retVal = convert(toUnits,val,result); 863 849 std::stringstream unitText; … … 880 866 // cm.convert(meter,10) 881 867 // cm.convert(angstrum,100) 882 double RpUnits::convert(RpUnits* toUnit, double val, int* result)883 {868 double 869 RpUnits::convert(const RpUnits* toUnit, double val, int* result) const { 884 870 885 871 // currently we convert this object to its basis and look for the … … 887 873 888 874 double value = val; 889 RpUnits* basis = this->getBasis();890 RpUnits* toBasis = toUnit->getBasis();891 RpUnits* fromUnit = this;892 RpUnits* dictToUnit = NULL;875 const RpUnits* basis = this->getBasis(); 876 const RpUnits* toBasis = toUnit->getBasis(); 877 const RpUnits* fromUnit = this; 878 const RpUnits* dictToUnit = NULL; 893 879 convEntry *p; 894 880 int my_result = 0; … … 1061 1047 1062 1048 1063 void* RpUnits::convert(RpUnits* toUnit, void* val, int* result)1064 {1049 void* 1050 RpUnits::convert(const RpUnits* toUnit, void* val, int* result) const { 1065 1051 1066 1052 // currently we convert this object to its basis and look for the … … 1068 1054 1069 1055 void* value = val; 1070 RpUnits* basis = this->getBasis();1071 RpUnits* toBasis = toUnit->getBasis();1072 RpUnits* fromUnit = this;1073 RpUnits* dictToUnit = NULL;1056 const RpUnits* basis = this->getBasis(); 1057 const RpUnits* toBasis = toUnit->getBasis(); 1058 const RpUnits* fromUnit = this; 1059 const RpUnits* dictToUnit = NULL; 1074 1060 convEntry *p; 1075 1061 int my_result = 0; … … 1211 1197 } 1212 1198 1213 void RpUnits::addUnit( const std::string& units,1214 double& exponent,1215 RpUnits* basis1216 )1217 { 1199 void 1200 RpUnits::addUnit( const std::string& units, 1201 double& exponent, 1202 const RpUnits* basis) { 1203 1218 1204 unit* p = NULL; 1219 1205 … … 1231 1217 } 1232 1218 1233 int RpUnits::insert(std::string key) 1234 { 1219 int 1220 RpUnits::insert(std::string key) { 1221 1235 1222 int newRecord = 0; 1236 1223 RpUnits* val = this; … … 1241 1228 1242 1229 1243 int RpUnits::pre_compare( std::string& units, RpUnits* basis )1244 {1230 int 1231 RpUnits::pre_compare( std::string& units, const RpUnits* basis ) { 1245 1232 1246 1233 // compare the incomming units with the previously defined units. … … 1356 1343 1357 1344 1358 void RpUnits::connectConversion(RpUnits* myRpUnit) 1359 { 1345 void 1346 RpUnits::connectConversion(const RpUnits* myRpUnit) { 1347 1360 1348 convEntry* p = myRpUnit->convList; 1361 1349 … … 1392 1380 retVal = addPresetTime(); 1393 1381 } 1382 else if (group.compare("volume") == 0) { 1383 retVal = addPresetTime(); 1384 } 1394 1385 1395 1386 return retVal;
Note: See TracChangeset
for help on using the changeset viewer.