Skip to content

Commit

Permalink
Remove constness of Unit in UnitConversion. Refs #5624
Browse files Browse the repository at this point in the history
Makes it explicit that the object is modified.
  • Loading branch information
martyngigg committed Jul 17, 2012
1 parent ca31bd6 commit 80b9868
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace Mantid
const double l1, const double l2,
const double twoTheta, const DeltaEMode::Type emode, const double efixed);
/// Convert a single value between the given units
static double run(const Unit & srcUnit, const Unit & destUnit,
static double run(Unit & srcUnit, Unit & destUnit,
const double srcValue,
const double l1, const double l2,
const double twoTheta, const DeltaEMode::Type emode, const double efixed);
Expand All @@ -55,7 +55,7 @@ namespace Mantid
/// Perform a quick conversion
static double convertQuickly(const double srcValue, const double factor, const double power);
/// Convert through TOF
static double convertViaTOF(const Unit & srcUnit, const Unit & destUnit,
static double convertViaTOF(Unit & srcUnit, Unit & destUnit,
const double srcValue,
const double l1, const double l2,
const double twoTheta, const DeltaEMode::Type emode, const double efixed);
Expand Down
15 changes: 6 additions & 9 deletions Code/Mantid/Framework/Kernel/src/UnitConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace Mantid
const double l1, const double l2,
const double twoTheta, const DeltaEMode::Type emode, const double efixed)
{
Unit_const_sptr srcUnit = UnitFactory::Instance().create(src);
Unit_const_sptr destUnit = UnitFactory::Instance().create(dest);
Unit_sptr srcUnit = UnitFactory::Instance().create(src);
Unit_sptr destUnit = UnitFactory::Instance().create(dest);
return UnitConversion::run(*srcUnit, *destUnit, srcValue, l1, l2, twoTheta, emode, efixed);
}

Expand All @@ -44,7 +44,7 @@ namespace Mantid
* @param efixed :: Value of fixed energy: EI (emode=1) or EF (emode=2) (in meV)
* @return The value converted to the destination unit
*/
double UnitConversion::run(const Unit & srcUnit, const Unit & destUnit,
double UnitConversion::run(Unit & srcUnit, Unit & destUnit,
const double srcValue,
const double l1, const double l2,
const double twoTheta, const DeltaEMode::Type emode, const double efixed)
Expand Down Expand Up @@ -88,7 +88,7 @@ namespace Mantid
* @param efixed :: Value of fixed energy: EI (emode=1) or EF (emode=2) (in meV)
* @return The value converted to the destination unit
*/
double UnitConversion::convertViaTOF(const Unit & srcUnit, const Unit & destUnit,
double UnitConversion::convertViaTOF(Unit & srcUnit, Unit & destUnit,
const double srcValue,
const double l1, const double l2,
const double twoTheta, const DeltaEMode::Type emode,
Expand All @@ -108,11 +108,8 @@ namespace Mantid
};

const double unused(0.0);
// The unit API requires a non-const input unit but it doesn't make sense for this method to accept a non-const value
Unit & nonConstSrc = const_cast<Unit&>(srcUnit);
const double tof = nonConstSrc.convertSingleToTOF(srcValue, l1, l2, twoTheta, emodeAsInt, efixed, unused);
Unit & nonConstDest = const_cast<Unit&>(destUnit);
return nonConstDest.convertSingleFromTOF(tof, l1, l2, twoTheta, emodeAsInt, efixed, unused);
const double tof = srcUnit.convertSingleToTOF(srcValue, l1, l2, twoTheta, emodeAsInt, efixed, unused);
return destUnit.convertSingleFromTOF(tof, l1, l2, twoTheta, emodeAsInt, efixed, unused);
}


Expand Down

0 comments on commit 80b9868

Please sign in to comment.