diff --git a/Framework/Geometry/inc/MantidGeometry/Instrument/Parameter.h b/Framework/Geometry/inc/MantidGeometry/Instrument/Parameter.h index ad07be97ef72c75ccb2d68137bdc79c26a92d144..b7ca9aa319a86884c204822538027ef49b477844 100644 --- a/Framework/Geometry/inc/MantidGeometry/Instrument/Parameter.h +++ b/Framework/Geometry/inc/MantidGeometry/Instrument/Parameter.h @@ -5,11 +5,12 @@ #ifndef Q_MOC_RUN #include <boost/shared_ptr.hpp> #endif +#include <iomanip> #include <sstream> +#include <stdexcept> #include <string> #include <typeinfo> #include <vector> -#include <stdexcept> namespace Mantid { @@ -179,16 +180,6 @@ template <class T> void Parameter::set(const T &t) { // Template definitions - ParameterType class //-------------------------------------------------------------------------- -/** Return the value of the parameter as a string - * @tparam T The type of the parameter - * @returns A string representation of the parameter - */ -template <class Type> std::string ParameterType<Type>::asString() const { - std::ostringstream str; - str << m_value; - return str.str(); -} - /** * Set the value of the parameter from a string * @tparam T The type of the parameter diff --git a/Framework/Geometry/src/Instrument/Parameter.cpp b/Framework/Geometry/src/Instrument/Parameter.cpp index 15fd55ddf74b97991eff6ac389aab7633cb1184a..ff3fa12d74fa3e56a189bbde8c2b6104e90c31a8 100644 --- a/Framework/Geometry/src/Instrument/Parameter.cpp +++ b/Framework/Geometry/src/Instrument/Parameter.cpp @@ -20,6 +20,32 @@ namespace Mantid { namespace Geometry { +/** Return the value of the parameter as a string + * @tparam T The type of the parameter + * @returns A string representation of the parameter + */ +template <class Type> std::string ParameterType<Type>::asString() const { + std::ostringstream str; + str << m_value; + return str.str(); +} + +/// Specialization for doubles +template <> std::string ParameterType<double>::asString() const { + std::ostringstream str; + str << std::setprecision(std::numeric_limits<double>::digits10); + str << m_value; + return str.str(); +} + +/// Specialization for V3D +template <> std::string ParameterType<Kernel::V3D>::asString() const { + std::ostringstream str; + str << std::setprecision(std::numeric_limits<double>::digits10); + str << m_value; + return str.str(); +} + // Initialize the static map ParameterFactory::FactoryMap ParameterFactory::s_map; diff --git a/Framework/Geometry/test/ParameterMapTest.h b/Framework/Geometry/test/ParameterMapTest.h index cac00aafd7ec8ca66623aece35a6bea3c13fd7a1..ccb8378474c268b5a4045103fdb9967b8b0d7067 100644 --- a/Framework/Geometry/test/ParameterMapTest.h +++ b/Framework/Geometry/test/ParameterMapTest.h @@ -632,6 +632,18 @@ public: TS_ASSERT_EQUALS(oldA->value<bool>(), false); } + void test_asString_for_doubles() { + ParameterMap pmap; + auto comp = m_testInstrument.get(); + pmap.addDouble(comp, "d", 0.123456789012345); + pmap.addV3D(comp, "v", + Mantid::Kernel::V3D(0.123456789012345, 0.123456789012345, + 0.123456789012345)); + TS_ASSERT_EQUALS(pmap.get(comp, "d")->asString(), "0.123456789012345"); + TS_ASSERT_EQUALS(pmap.get(comp, "v")->asString(), + "[0.123456789012345,0.123456789012345,0.123456789012345]"); + } + private: template <typename ValueType> void doCopyAndUpdateTestUsingGenericAdd(const std::string &type,