GUI: floating pointer to string conversion functions in StringUtil.h
This commit is contained in:
parent
fcbdf27c55
commit
5ffe220a8d
|
@ -1,7 +1,7 @@
|
|||
#include "HexDump.h"
|
||||
#include <sstream>
|
||||
#include "Configuration.h"
|
||||
#include "Bridge.h"
|
||||
#include "StringUtil.h"
|
||||
|
||||
HexDump::HexDump(QWidget* parent) : AbstractTableView(parent)
|
||||
{
|
||||
|
@ -568,8 +568,7 @@ QString HexDump::dwordToString(uint32 dword, DwordViewMode_e mode)
|
|||
|
||||
case FloatDword:
|
||||
{
|
||||
float* wPtr = (float*)&dword;
|
||||
wStr = QString::number((double) * wPtr);
|
||||
wStr = ToFloatString(&dword);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -609,8 +608,7 @@ QString HexDump::qwordToString(uint64 qword, QwordViewMode_e mode)
|
|||
|
||||
case DoubleQword:
|
||||
{
|
||||
double* wPtr = (double*)&qword;
|
||||
wStr = QString::number((double) * wPtr);
|
||||
wStr = ToDoubleString(&qword);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -632,10 +630,7 @@ QString HexDump::twordToString(long double tword, TwordViewMode_e mode)
|
|||
{
|
||||
case FloatTword:
|
||||
{
|
||||
std::stringstream wlongDoubleStr;
|
||||
wlongDoubleStr << std::scientific << (long double)tword;
|
||||
|
||||
wStr = QString::fromStdString(wlongDoubleStr.str());
|
||||
wStr = ToLongDoubleString(&tword);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef STRINGUTIL_H
|
||||
#define STRINGUTIL_H
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <QString>
|
||||
#include "Imports.h"
|
||||
|
||||
|
@ -50,4 +52,29 @@ static QString ToDecString(dsint Value)
|
|||
return QString(temp);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static QString ToFloatingString(void* buffer)
|
||||
{
|
||||
auto value = *(T*)buffer;
|
||||
std::stringstream wFloatingStr;
|
||||
wFloatingStr << std::setprecision(std::numeric_limits<T>::digits10) << value;
|
||||
return QString::fromStdString(wFloatingStr.str());
|
||||
}
|
||||
|
||||
static QString ToFloatString(void* buffer)
|
||||
{
|
||||
return ToFloatingString<float>(buffer);
|
||||
}
|
||||
|
||||
static QString ToDoubleString(void* buffer)
|
||||
{
|
||||
return ToFloatingString<double>(buffer);
|
||||
}
|
||||
|
||||
static QString ToLongDoubleString(void* buffer)
|
||||
{
|
||||
//TODO: properly implement this because VS doesn't support it.
|
||||
return ToDoubleString(buffer);
|
||||
}
|
||||
|
||||
#endif // STRINGUTIL_H
|
||||
|
|
Loading…
Reference in New Issue