Skip to content

Commit

Permalink
Merge pull request happycube#877 from oyvindln/json_fix
Browse files Browse the repository at this point in the history
fix data types for fileLoc and diskLoc in tools code and fix reading of json floats on non-US locales
  • Loading branch information
happycube authored Jan 15, 2024
2 parents c71ae28 + aad4190 commit c85594a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
1 change: 1 addition & 0 deletions tools/ld-disc-stacker/stackingpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
************************************************************************/

#include "stackingpool.h"
#include "vbidecoder.h"

StackingPool::StackingPool(QString _outputFilename, QString _outputJsonFilename,
qint32 _maxThreads, QVector<LdDecodeMetaData *> &_ldDecodeMetaData, QVector<SourceVideo *> &_sourceVideos,
Expand Down
1 change: 1 addition & 0 deletions tools/ld-dropout-correct/correctorpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
************************************************************************/

#include "correctorpool.h"
#include "vbidecoder.h"

CorrectorPool::CorrectorPool(QString _outputFilename, QString _outputJsonFilename,
qint32 _maxThreads, QVector<LdDecodeMetaData *> &_ldDecodeMetaData, QVector<SourceVideo *> &_sourceVideos,
Expand Down
30 changes: 23 additions & 7 deletions tools/library/tbc/jsonio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@

#include "jsonio.h"

#include <cmath>
#include <limits>
#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
#include <charconv>
#else
#include <sstream>
#endif

// Recognise JSON space characters
static bool isAsciiSpace(char c)
Expand All @@ -46,10 +50,12 @@ JsonReader::JsonReader(std::istream &_input)

void JsonReader::read(int &value)
{
// Round to the nearest integer
double d;
readNumber(d);
value = static_cast<int>(std::lround(d));
readSignedInteger(value);
}

void JsonReader::read(qint64 &value)
{
readSignedInteger(value);
}

void JsonReader::read(double &value)
Expand Down Expand Up @@ -331,8 +337,13 @@ void JsonReader::readNumber(double &value)
}
}

// XXX In C++17 we could use std::from_chars instead, which is slightly more efficient
value = std::stod(buf);
#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
// Use the faster C++17 method if available.
std::from_chars(buf.data(), buf.data() + buf.size(), value);
#else
std::istringstream(buf) >> value;
#endif


// We've read one character beyond the end of the number (there's no way to
// tell where the end is otherwise), so we must unget the last char
Expand All @@ -351,6 +362,11 @@ void JsonWriter::write(int value)
output << value;
}

void JsonWriter::write(qint64 value)
{
output << value;
}

void JsonWriter::write(double value)
{
output << value;
Expand Down
9 changes: 9 additions & 0 deletions tools/library/tbc/jsonio.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <stdexcept>
#include <string>
#include <stack>
#include <cmath>

class JsonReader
{
Expand All @@ -51,6 +52,7 @@ class JsonReader
}

// Numbers
void read(qint64 &value);
void read(int &value);
void read(double &value);

Expand Down Expand Up @@ -81,6 +83,12 @@ class JsonReader

void readString(std::string &value);
void readNumber(double &value);
template <typename T> void readSignedInteger(T& value) {
// Round to the nearest integer
double d;
readNumber(d);
value = static_cast<T>(std::llround(d));
}

// The input stream
std::istream &input;
Expand All @@ -101,6 +109,7 @@ class JsonWriter

// Numbers
void write(int value);
void write(qint64 value);
void write(double value);

// Booleans
Expand Down
5 changes: 2 additions & 3 deletions tools/library/tbc/lddecodemetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include <QDebug>
#include <array>

#include "vbidecoder.h"
#include "dropouts.h"

class JsonReader;
Expand Down Expand Up @@ -202,8 +201,8 @@ class LdDecodeMetaData
DropOuts dropOuts;
bool pad = false;

qint32 diskLoc = -1;
qint32 fileLoc = -1;
double diskLoc = -1;
qint64 fileLoc = -1;
qint32 decodeFaults = -1;
qint32 efmTValues = -1;

Expand Down

0 comments on commit c85594a

Please sign in to comment.