diff --git a/Fit/FitKernel/inc/AttLimits.h b/Core/Tools/inc/AttLimits.h similarity index 100% rename from Fit/FitKernel/inc/AttLimits.h rename to Core/Tools/inc/AttLimits.h diff --git a/Core/Tools/inc/RealParameterWrapper.h b/Core/Tools/inc/RealParameterWrapper.h index 747d4e1370a93e1141c6c5d273426b130747fc5f..7eb4dbb98794bcfa17471a37161da9b6140784cc 100644 --- a/Core/Tools/inc/RealParameterWrapper.h +++ b/Core/Tools/inc/RealParameterWrapper.h @@ -18,6 +18,7 @@ #include "WinDllMacros.h" #include "Exceptions.h" +#include "AttLimits.h" #include <ostream> @@ -28,40 +29,56 @@ class BA_CORE_API_ RealParameterWrapper { public: - explicit RealParameterWrapper(double *par) : m_data(par) {} - // explicit RealParameterWrapper(double *par) : m_data(par), m_signal() {} + explicit RealParameterWrapper(double *par, const AttLimits &limits = AttLimits::limitless()); RealParameterWrapper(const RealParameterWrapper& other ); RealParameterWrapper& operator=(const RealParameterWrapper& other); ~RealParameterWrapper(){} //! Sets value of wrapped parameter and emmit signal - void setValue(double value) - { - checkNull(); - if(value != *m_data) { - *m_data = value; - // m_signal(); - } - } + bool setValue(double value); //! Returns value of wrapped parameter - double getValue() const { checkNull(); return *m_data; } + double getValue() const; //! Returns true if wrapped parameter was not initialized with proper real value - bool isNull() const { return (m_data ? false : true); } + bool isNull() const; //! throw exception if parameter was not initialized with proper value - void checkNull() const { if(isNull()) throw NullPointerException("RealParameterWrapper::getValue() -> Attempt to access uninitialised pointer."); } + void checkNull() const; //! Prints the parameter's address to an output stream - friend std::ostream& operator<<(std::ostream& ostr, const RealParameterWrapper& p) { ostr << p.m_data; return ostr; } + friend std::ostream& operator<<(std::ostream& ostr, const RealParameterWrapper& p) + { + ostr << p.m_data; return ostr; + } + private: //! swap function void swapContent(RealParameterWrapper& other); volatile double *m_data; + AttLimits m_limits; }; +inline double RealParameterWrapper::getValue() const +{ + checkNull(); + return *m_data; +} + +inline bool RealParameterWrapper::isNull() const +{ + return (m_data ? false : true); +} + +inline void RealParameterWrapper::checkNull() const +{ + if(isNull()) + throw NullPointerException( + "RealParameterWrapper::getValue() -> Attempt to access uninitialised pointer."); +} + + #endif // REALPARAMETERPROXY_H diff --git a/Core/Tools/src/RealParameterWrapper.cpp b/Core/Tools/src/RealParameterWrapper.cpp index 11805213f85dba47dcebb95fc586df2c73e2bfda..3cbd1884d2fb1bdeb76f3e43da67b29279ede9e0 100644 --- a/Core/Tools/src/RealParameterWrapper.cpp +++ b/Core/Tools/src/RealParameterWrapper.cpp @@ -15,9 +15,17 @@ #include "RealParameterWrapper.h" +RealParameterWrapper::RealParameterWrapper(double *par, const AttLimits &limits) + : m_data(par) + , m_limits(limits) +{ + +} + RealParameterWrapper::RealParameterWrapper(const RealParameterWrapper& other ) { m_data = other.m_data; + m_limits = other.m_limits; } RealParameterWrapper& RealParameterWrapper::operator=(const RealParameterWrapper& other) @@ -29,9 +37,20 @@ RealParameterWrapper& RealParameterWrapper::operator=(const RealParameterWrapper return *this; } +bool RealParameterWrapper::setValue(double value) +{ + bool success(true); + checkNull(); + if(value != *m_data) { + *m_data = value; + } + return success; +} + void RealParameterWrapper::swapContent(RealParameterWrapper& other) { std::swap(this->m_data, other.m_data); + std::swap(this->m_limits, other.m_limits); } diff --git a/Tests/UnitTests/TestFit/AttLimitsTest.h b/Tests/UnitTests/TestCore/AttLimitsTest.h similarity index 100% rename from Tests/UnitTests/TestFit/AttLimitsTest.h rename to Tests/UnitTests/TestCore/AttLimitsTest.h diff --git a/Tests/UnitTests/TestCore/main.cpp b/Tests/UnitTests/TestCore/main.cpp index 8de161f5e498fdf4355a14cfa9324e7b0ea801f7..4eb957f2ce22592503e96f70ff6880a344e7e28f 100644 --- a/Tests/UnitTests/TestCore/main.cpp +++ b/Tests/UnitTests/TestCore/main.cpp @@ -3,6 +3,7 @@ #endif #include "gtest/gtest.h" +#include "AttLimitsTest.h" #include "BeamTest.h" #include "ChiSquaredModuleTest.h" #include "CVectorTest.h" diff --git a/Tests/UnitTests/TestFit/main.cpp b/Tests/UnitTests/TestFit/main.cpp index a2b45c939ea9ed15d8006f94f7e00efbb1ad126a..c86fe4689252e46d2de66c0c44ce07be2088b8c1 100644 --- a/Tests/UnitTests/TestFit/main.cpp +++ b/Tests/UnitTests/TestFit/main.cpp @@ -3,7 +3,6 @@ #endif #include "gtest/gtest.h" -#include "AttLimitsTest.h" #include "FitParameterTest.h" #include "FitParameterLinkedTest.h" #include "MinimizerOptionsTest.h"