From 5c5c25163d25ccc3576ca07a0c6b61db9d225a05 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Fri, 24 Jul 2015 19:20:52 -0400 Subject: [PATCH] Debugger: Tweaks for float values. FloatValue: - Store value as variant rather than double so as to be able to later differentiate between float vs double. PrimitiveValueNode: - Construct float nodes with variant value. --- .../value/value_nodes/PrimitiveValueNode.cpp | 2 +- src/apps/debugger/value/values/FloatValue.cpp | 18 ++++++++++++++++-- src/apps/debugger/value/values/FloatValue.h | 8 ++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/apps/debugger/value/value_nodes/PrimitiveValueNode.cpp b/src/apps/debugger/value/value_nodes/PrimitiveValueNode.cpp index 106c653aeb..82d3d65fdb 100644 --- a/src/apps/debugger/value/value_nodes/PrimitiveValueNode.cpp +++ b/src/apps/debugger/value/value_nodes/PrimitiveValueNode.cpp @@ -77,7 +77,7 @@ PrimitiveValueNode::ResolvedLocationAndValue(ValueLoader* valueLoader, else if (BVariant::TypeIsInteger(valueType)) value = new(std::nothrow) IntegerValue(valueData); else if (BVariant::TypeIsFloat(valueType)) - value = new(std::nothrow) FloatValue(valueData.ToDouble()); + value = new(std::nothrow) FloatValue(valueData); else return B_UNSUPPORTED; diff --git a/src/apps/debugger/value/values/FloatValue.cpp b/src/apps/debugger/value/values/FloatValue.cpp index aba19862ea..eb308b39e9 100644 --- a/src/apps/debugger/value/values/FloatValue.cpp +++ b/src/apps/debugger/value/values/FloatValue.cpp @@ -9,7 +9,7 @@ #include -FloatValue::FloatValue(double value) +FloatValue::FloatValue(const BVariant& value) : fValue(value) { @@ -25,7 +25,21 @@ bool FloatValue::ToString(BString& _string) const { char buffer[128]; - snprintf(buffer, sizeof(buffer), "%g", fValue); + + switch (fValue.Type()) { + case B_FLOAT_TYPE: + { + snprintf(buffer, sizeof(buffer), "%f", fValue.ToFloat()); + break; + } + case B_DOUBLE_TYPE: + { + snprintf(buffer, sizeof(buffer), "%g", fValue.ToDouble()); + break; + } + default: + return false; + } BString string(buffer); if (string.Length() == 0) diff --git a/src/apps/debugger/value/values/FloatValue.h b/src/apps/debugger/value/values/FloatValue.h index a974e98edd..5f72f8ba46 100644 --- a/src/apps/debugger/value/values/FloatValue.h +++ b/src/apps/debugger/value/values/FloatValue.h @@ -1,4 +1,4 @@ -/* + /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. * Distributed under the terms of the MIT License. */ @@ -11,10 +11,10 @@ class FloatValue : public Value { public: - FloatValue(double value); + FloatValue(const BVariant& value); virtual ~FloatValue(); - double GetValue() const + BVariant GetValue() const { return fValue; } virtual bool ToString(BString& _string) const; @@ -23,7 +23,7 @@ public: virtual bool operator==(const Value& other) const; private: - double fValue; + BVariant fValue; };