Skip to content

Commit

Permalink
undo ColumnUtils::doubleToString* -> Utils::
Browse files Browse the repository at this point in the history
  • Loading branch information
JorisGoosen committed Jan 15, 2025
1 parent 73d75df commit 631bbb5
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Common/jaspColumnEncoder
Submodule jaspColumnEncoder updated 2 files
+0 −19 utils.cpp
+0 −3 utils.h
8 changes: 4 additions & 4 deletions CommonData/column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ stringvec Column::nonFilteredLevels()
levels.insert(label->label());
}
else if(!isEmptyValue(_dbls[r]))
levels.insert(Utils::doubleToString(_dbls[r]));
levels.insert(ColumnUtils::doubleToString(_dbls[r]));
}

// Use the right label order
Expand Down Expand Up @@ -1164,7 +1164,7 @@ std::string Column::doubleToDisplayString(double dbl, bool fancyEmptyValue, bool
ignoreEmptyValue = ignoreEmptyValue && !std::isnan(dbl);

if (isEmptyValue(dbl) && !ignoreEmptyValue) return fancyEmptyValue ? EmptyValues::displayString() : "";
else return Utils::doubleToString(dbl);
else return ColumnUtils::doubleToString(dbl);
}

std::string Column::operator[](size_t row)
Expand Down Expand Up @@ -1416,7 +1416,7 @@ bool Column::replaceDoubleLabelFromRowWithDouble(size_t row, double dbl)
dblsRef = dbl;

_labelsTempDbls[row] = dbl;
_labelsTemp[row] = Utils::doubleToString(dbl);
_labelsTemp[row] = ColumnUtils::doubleToString(dbl);

return true;
}
Expand Down Expand Up @@ -1580,7 +1580,7 @@ bool Column::setValue(size_t row, const std::string & value, const std::string &

if(justAValue && !newLabel && itsADouble)
{
const std::string valueDbl = Utils::doubleToString(newDoubleToSet);
const std::string valueDbl = ColumnUtils::doubleToString(newDoubleToSet);
newLabel = labelByValue(valueDbl);
newLabel = newLabel ? newLabel : labelByValueAndDisplay(valueDbl, valueDbl);
}
Expand Down
20 changes: 20 additions & 0 deletions CommonData/columnutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,26 @@ std::string ColumnUtils::deEuropeaniseForImport(std::string value)
return value;
}

std::string ColumnUtils::doubleToStringMaxPrec(double dbl)
{
constexpr auto max_precision{std::numeric_limits<long double>::digits10 + 1};
return doubleToString(dbl, max_precision);
}

std::string ColumnUtils::doubleToString(double dbl, int precision)
{
JASPTIMER_SCOPE(ColumnUtils::doubleToString);

if (dbl > std::numeric_limits<double>::max()) return "";
if (dbl < std::numeric_limits<double>::lowest()) return "-∞";

std::stringstream conv; //Use this instead of std::to_string to make sure there are no trailing zeroes (and to get full precision)
conv << std::setprecision(precision);
conv << dbl;
return conv.str();
}


// hex should be 4 hexadecimals characters
std::string ColumnUtils::_convertEscapedUnicodeToUTF8(std::string hex)
{
Expand Down
3 changes: 3 additions & 0 deletions CommonData/columnutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class ColumnUtils

static void convertEscapedUnicodeToUTF8( std::string & inputStr);
static std::string deEuropeaniseForImport( std::string value); //Convert a string to a double with a dot for a separator

static std::string doubleToString( double dbl, int precision = 10);
static std::string doubleToStringMaxPrec( double dbl);

static bool convertVecToInt( const stringvec & values, intvec & intValues, intset & uniqueValues);
static bool convertVecToDouble( const stringvec & values, doublevec & doubleValues);
Expand Down
2 changes: 1 addition & 1 deletion Desktop/data/importers/jaspimporterold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ void JASPImporterOld::loadDataArchive_1_00(const std::string &path, std::functio

if (isScalar)
{
values.push_back(Utils::doubleToString(*reinterpret_cast<double*>(buff)));
values.push_back(ColumnUtils::doubleToString(*reinterpret_cast<double*>(buff)));
labels.push_back(values.back());
}
else
Expand Down
6 changes: 3 additions & 3 deletions Desktop/data/importers/readstat/readstatimportcolumn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ std::string ReadStatImportColumn::readstatValueToString(const readstat_value_t &
case READSTAT_TYPE_INT8: return std::to_string (int( readstat_int8_value(value)) );
case READSTAT_TYPE_INT16: return std::to_string (int( readstat_int16_value(value)) );
case READSTAT_TYPE_INT32: return std::to_string (int( readstat_int32_value(value)) );
case READSTAT_TYPE_FLOAT: return Utils::doubleToStringMaxPrec ( readstat_float_value(value) );
case READSTAT_TYPE_DOUBLE: return Utils::doubleToStringMaxPrec ( readstat_double_value(value) );
case READSTAT_TYPE_FLOAT: return ColumnUtils::doubleToStringMaxPrec ( readstat_float_value(value) );
case READSTAT_TYPE_DOUBLE: return ColumnUtils::doubleToStringMaxPrec ( readstat_double_value(value) );
case READSTAT_TYPE_STRING_REF: throw std::runtime_error("File contains string references and we do not support this.");
}

Expand All @@ -69,7 +69,7 @@ const stringvec &ReadStatImportColumn::labels() const
void ReadStatImportColumn::addValue(const readstat_value_t & value)
{
bool setMiss = readstat_value_is_tagged_missing(value) || (_readstatVariable && readstat_value_is_defined_missing(value, _readstatVariable));
std::string valStr = Utils::doubleToString(EmptyValues::missingValueDouble);
std::string valStr = ColumnUtils::doubleToString(EmptyValues::missingValueDouble);

if(readstat_value_is_tagged_missing(value)) //This is from sas/stata and actual value is NaN but there is a tag. So we use that as a value, this will be converted to NaN later anyway
{
Expand Down
3 changes: 2 additions & 1 deletion QMLComponents/models/listmodelfiltereddataentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "controls/jaspcontrol.h"
#include "filter.h"
#include "dataset.h"
#include "columnutils.h"

ListModelFilteredDataEntry::ListModelFilteredDataEntry(TableViewBase * parent)
: ListModelTableViewBase(parent)
Expand Down Expand Up @@ -365,7 +366,7 @@ void ListModelFilteredDataEntry::informDataSetOfInitialValues()
QVariantList vals;
for(size_t i=0; i<_initialValues.size(); i++)
{
vals.append(_acceptedRows[i] ? tq(Utils::doubleToString(_initialValues[i])) : "");
vals.append(_acceptedRows[i] ? tq(ColumnUtils::doubleToString(_initialValues[i])) : "");
if(_acceptedRows[i])
somethingFilled = true;
}
Expand Down

0 comments on commit 631bbb5

Please sign in to comment.