Ignore:
Timestamp:
Oct 14, 2005, 9:43:27 AM (19 years ago)
Author:
dkearney
Message:

This update brings us one step closer to being const correct in the RpUnits
class. Added a few more comments. All other files touched were made to
comply with the new const correct RpUnits.[h,cc]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/RpUnits.cc

    r103 r104  
    2323 ************************************************************************/
    2424
    25 RpUnits * RpUnits::define(const std::string units, RpUnits * basis)
    26 {
     25RpUnits *
     26RpUnits::define(const std::string units, const RpUnits* basis) {
     27
    2728    RpUnits * newRpUnit = NULL;
    2829
     
    187188 ************************************************************************/
    188189
    189 RpUnits * RpUnits::defineCmplx ( const std::string units, RpUnits * basis )
    190 {
     190RpUnits *
     191RpUnits::defineCmplx ( const std::string units, const RpUnits* basis ) {
     192
    191193    RpUnits * newRpUnit = NULL;
    192194
     
    427429 *
    428430 ************************************************************************/
    429 RpUnits * RpUnits::define(  RpUnits* from,
    430                             RpUnits* to,
    431                             double (*convForwFxnPtr)(double),
    432                             double (*convBackFxnPtr)(double))
    433 {
     431RpUnits *
     432RpUnits::define(  const RpUnits* from,
     433                  const RpUnits* to,
     434                  double (*convForwFxnPtr)(double),
     435                  double (*convBackFxnPtr)(double)) {
     436
    434437    RpUnits* conv = new RpUnits(    from,
    435438                                    to,
     
    442445}
    443446
    444 RpUnits * RpUnits::define(  RpUnits* from,
    445                             RpUnits* to,
    446                             double (*convForwFxnPtr)(double,double),
    447                             double (*convBackFxnPtr)(double,double))
    448 {
     447RpUnits *
     448RpUnits::define(  const RpUnits* from,
     449                  const RpUnits* to,
     450                  double (*convForwFxnPtr)(double,double),
     451                  double (*convBackFxnPtr)(double,double)) {
     452
    449453    RpUnits* conv = new RpUnits(    from,
    450454                                    to,
     
    457461}
    458462
    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 {
     463RpUnits *
     464RpUnits::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
    466471    RpUnits* conv = new RpUnits(    from,
    467472                                    to,
     
    480485 * report the units this object represents back to the user
    481486 *
    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//
     496std::string
     497RpUnits::getUnits() const {
     498
    485499    std::stringstream unitText;
    486500    unit* p = head;
     
    498512 * report the units this object represents back to the user
    499513 *
    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//
     525std::string
     526RpUnits::getUnitsName() const {
     527
    503528    std::stringstream unitText;
    504529    unit* p = head;
     
    527552 *
    528553 * **********************************************************************/
    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//
     563double
     564RpUnits::getExponent() const {
     565
    531566    return head->getExponent();
    532567}
     
    537572 *
    538573 * **********************************************************************/
    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//
     582const RpUnits *
     583RpUnits::getBasis() const {
     584
    541585    // check if head exists?
     586    if (!head) {
     587        // raise error for badly formed Rappture Units object
     588    }
     589
    542590    return head->getBasis();
    543591}
     
    553601 *
    554602 ************************************************************************/
    555 double RpUnits::makeBasis(double value, int* result)
    556 {
    557 
    558     RpUnits* basis = getBasis();
     603double
     604RpUnits::makeBasis(double value, int* result) const {
     605
     606    const RpUnits* basis = getBasis();
    559607    double retVal = value;
    560608
     
    567615        // do nothing
    568616
    569         if (result) {
    570             *result = 1;
    571         }
     617        // if (result) {
     618        //     *result = 1;
     619        // }
    572620    }
    573621    else {
     
    578626}
    579627
    580 RpUnits& RpUnits::makeBasis(double* value, int* result)
    581 {
    582     RpUnits* basis = getBasis();
     628const RpUnits&
     629RpUnits::makeBasis(double* value, int* result) const {
     630    const RpUnits* basis = getBasis();
    583631    double retVal = *value;
    584632    int convResult = 0;
     
    588636        // do nothing
    589637
    590         if (result) {
    591             *result = 1;
    592         }
     638        // if (result) {
     639        //     *result = 1;
     640        // }
    593641    }
    594642    else {
     
    603651        *result = convResult;
    604652    }
    605 
    606 
    607653
    608654    return *this;
     
    616662 *
    617663 * **********************************************************************/
    618 /*
    619 int RpUnits::makeMetric(RpUnits * basis) {
     664
     665int
     666RpUnits::makeMetric(const RpUnits * basis) {
    620667
    621668    if (!basis) {
     
    623670    }
    624671
    625     std::string basisName = basis->getUnits();
     672    std::string basisName = basis->getUnitsName();
    626673    std::string name;
    627674    std::string forw, back;
     
    677724    return (1);
    678725}
    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
     728const RpUnits*
     729RpUnits::find(std::string key) {
     730
    746731    // dict.find seems to return a (RpUnits* const) so i had to
    747732    // cast it as a (RpUnits*)
    748733
    749734    // dict pointer
    750     RpUnits* unitEntry = (RpUnits*) *(dict->find(key).getValue());
     735    const RpUnits* unitEntry = *(dict->find(key).getValue());
    751736
    752737    // dict pointer
    753     if (unitEntry == (RpUnits*)dict->getNullEntry().getValue()) {
     738    if (unitEntry == *(dict->getNullEntry().getValue()) ) {
    754739        unitEntry = NULL;
    755740    }
     
    768753                    int* result ) {
    769754
    770     RpUnits* toUnits = NULL;
    771     RpUnits* fromUnits = NULL;
     755    const RpUnits* toUnits = NULL;
     756    const RpUnits* fromUnits = NULL;
    772757    std::string tmpNumVal = "";
    773758    std::string fromUnitsName = "";
     
    849834    if ( (result) && (*result == 0) ) {
    850835        *result = convResult;
    851    }
     836    }
    852837
    853838    return convVal;
     
    855840}
    856841
    857 std::string RpUnits::convert (   RpUnits* toUnits,
    858                         double val,
    859                         int showUnits,
    860                         int* result )
    861 {
     842std::string
     843RpUnits::convert ( const  RpUnits* toUnits,
     844                   double val,
     845                   int showUnits,
     846                   int* result )  const {
     847
    862848    double retVal = convert(toUnits,val,result);
    863849    std::stringstream unitText;
     
    880866//      cm.convert(meter,10)
    881867//      cm.convert(angstrum,100)
    882 double RpUnits::convert(RpUnits* toUnit, double val, int* result)
    883 {
     868double
     869RpUnits::convert(const RpUnits* toUnit, double val, int* result) const {
    884870
    885871    // currently we convert this object to its basis and look for the
     
    887873
    888874    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;
    893879    convEntry *p;
    894880    int my_result = 0;
     
    10611047
    10621048
    1063 void* RpUnits::convert(RpUnits* toUnit, void* val, int* result)
    1064 {
     1049void*
     1050RpUnits::convert(const RpUnits* toUnit, void* val, int* result) const {
    10651051
    10661052    // currently we convert this object to its basis and look for the
     
    10681054
    10691055    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;
    10741060    convEntry *p;
    10751061    int my_result = 0;
     
    12111197}
    12121198
    1213 void RpUnits::addUnit( const std::string& units,
    1214                        double&  exponent,
    1215                        RpUnits* basis
    1216                       )
    1217 {
     1199void
     1200RpUnits::addUnit( const std::string& units,
     1201                  double&  exponent,
     1202                  const RpUnits* basis) {
     1203
    12181204    unit* p = NULL;
    12191205
     
    12311217}
    12321218
    1233 int RpUnits::insert(std::string key)
    1234 {
     1219int
     1220RpUnits::insert(std::string key) {
     1221
    12351222    int newRecord = 0;
    12361223    RpUnits* val = this;
     
    12411228
    12421229
    1243 int RpUnits::pre_compare( std::string& units, RpUnits* basis )
    1244 {
     1230int
     1231RpUnits::pre_compare( std::string& units, const RpUnits* basis ) {
    12451232
    12461233    // compare the incomming units with the previously defined units.
     
    13561343
    13571344
    1358 void RpUnits::connectConversion(RpUnits* myRpUnit)
    1359 {
     1345void
     1346RpUnits::connectConversion(const RpUnits* myRpUnit) {
     1347
    13601348    convEntry* p = myRpUnit->convList;
    13611349
     
    13921380        retVal = addPresetTime();
    13931381    }
     1382    else if (group.compare("volume") == 0) {
     1383        retVal = addPresetTime();
     1384    }
    13941385
    13951386    return retVal;
Note: See TracChangeset for help on using the changeset viewer.