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 "HexDump.h"
|
||||||
#include <sstream>
|
|
||||||
#include "Configuration.h"
|
#include "Configuration.h"
|
||||||
#include "Bridge.h"
|
#include "Bridge.h"
|
||||||
|
#include "StringUtil.h"
|
||||||
|
|
||||||
HexDump::HexDump(QWidget* parent) : AbstractTableView(parent)
|
HexDump::HexDump(QWidget* parent) : AbstractTableView(parent)
|
||||||
{
|
{
|
||||||
|
@ -568,8 +568,7 @@ QString HexDump::dwordToString(uint32 dword, DwordViewMode_e mode)
|
||||||
|
|
||||||
case FloatDword:
|
case FloatDword:
|
||||||
{
|
{
|
||||||
float* wPtr = (float*)&dword;
|
wStr = ToFloatString(&dword);
|
||||||
wStr = QString::number((double) * wPtr);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -609,8 +608,7 @@ QString HexDump::qwordToString(uint64 qword, QwordViewMode_e mode)
|
||||||
|
|
||||||
case DoubleQword:
|
case DoubleQword:
|
||||||
{
|
{
|
||||||
double* wPtr = (double*)&qword;
|
wStr = ToDoubleString(&qword);
|
||||||
wStr = QString::number((double) * wPtr);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -632,10 +630,7 @@ QString HexDump::twordToString(long double tword, TwordViewMode_e mode)
|
||||||
{
|
{
|
||||||
case FloatTword:
|
case FloatTword:
|
||||||
{
|
{
|
||||||
std::stringstream wlongDoubleStr;
|
wStr = ToLongDoubleString(&tword);
|
||||||
wlongDoubleStr << std::scientific << (long double)tword;
|
|
||||||
|
|
||||||
wStr = QString::fromStdString(wlongDoubleStr.str());
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef STRINGUTIL_H
|
#ifndef STRINGUTIL_H
|
||||||
#define STRINGUTIL_H
|
#define STRINGUTIL_H
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <iomanip>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include "Imports.h"
|
#include "Imports.h"
|
||||||
|
|
||||||
|
@ -50,4 +52,29 @@ static QString ToDecString(dsint Value)
|
||||||
return QString(temp);
|
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
|
#endif // STRINGUTIL_H
|
||||||
|
|
Loading…
Reference in New Issue