Browse Source

Use numeric_limits instead of constants from C

In C++, using numeric_limits is more idiomatic compared to using constants.
adaptive-webui-19844
Chocobo1 5 years ago
parent
commit
0b1b3c1f84
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 1
      src/base/utils/random.cpp
  2. 3
      src/base/utils/random.h
  3. 6
      src/gui/advancedsettings.cpp
  4. 4
      src/webui/api/searchcontroller.cpp

1
src/base/utils/random.cpp

@ -28,7 +28,6 @@
#include "random.h" #include "random.h"
#include <limits>
#include <random> #include <random>
#include <QtGlobal> #include <QtGlobal>

3
src/base/utils/random.h

@ -30,12 +30,13 @@
#define UTILS_RANDOM_H #define UTILS_RANDOM_H
#include <cstdint> #include <cstdint>
#include <limits>
namespace Utils namespace Utils
{ {
namespace Random namespace Random
{ {
uint32_t rand(uint32_t min = 0, uint32_t max = UINT32_MAX); uint32_t rand(uint32_t min = 0, uint32_t max = std::numeric_limits<uint32_t>::max());
} }
} }

6
src/gui/advancedsettings.cpp

@ -377,19 +377,19 @@ void AdvancedSettings::loadAdvancedSettings()
, &checkBoxSuggestMode); , &checkBoxSuggestMode);
// Send buffer watermark // Send buffer watermark
spinBoxSendBufferWatermark.setMinimum(1); spinBoxSendBufferWatermark.setMinimum(1);
spinBoxSendBufferWatermark.setMaximum(INT_MAX); spinBoxSendBufferWatermark.setMaximum(std::numeric_limits<int>::max());
spinBoxSendBufferWatermark.setSuffix(tr(" KiB")); spinBoxSendBufferWatermark.setSuffix(tr(" KiB"));
spinBoxSendBufferWatermark.setValue(session->sendBufferWatermark()); spinBoxSendBufferWatermark.setValue(session->sendBufferWatermark());
addRow(SEND_BUF_WATERMARK, (tr("Send buffer watermark") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#send_buffer_watermark", "(?)")) addRow(SEND_BUF_WATERMARK, (tr("Send buffer watermark") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#send_buffer_watermark", "(?)"))
, &spinBoxSendBufferWatermark); , &spinBoxSendBufferWatermark);
spinBoxSendBufferLowWatermark.setMinimum(1); spinBoxSendBufferLowWatermark.setMinimum(1);
spinBoxSendBufferLowWatermark.setMaximum(INT_MAX); spinBoxSendBufferLowWatermark.setMaximum(std::numeric_limits<int>::max());
spinBoxSendBufferLowWatermark.setSuffix(tr(" KiB")); spinBoxSendBufferLowWatermark.setSuffix(tr(" KiB"));
spinBoxSendBufferLowWatermark.setValue(session->sendBufferLowWatermark()); spinBoxSendBufferLowWatermark.setValue(session->sendBufferLowWatermark());
addRow(SEND_BUF_LOW_WATERMARK, (tr("Send buffer low watermark") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#send_buffer_low_watermark", "(?)")) addRow(SEND_BUF_LOW_WATERMARK, (tr("Send buffer low watermark") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#send_buffer_low_watermark", "(?)"))
, &spinBoxSendBufferLowWatermark); , &spinBoxSendBufferLowWatermark);
spinBoxSendBufferWatermarkFactor.setMinimum(1); spinBoxSendBufferWatermarkFactor.setMinimum(1);
spinBoxSendBufferWatermarkFactor.setMaximum(INT_MAX); spinBoxSendBufferWatermarkFactor.setMaximum(std::numeric_limits<int>::max());
spinBoxSendBufferWatermarkFactor.setSuffix(" %"); spinBoxSendBufferWatermarkFactor.setSuffix(" %");
spinBoxSendBufferWatermarkFactor.setValue(session->sendBufferWatermarkFactor()); spinBoxSendBufferWatermarkFactor.setValue(session->sendBufferWatermarkFactor());
addRow(SEND_BUF_WATERMARK_FACTOR, (tr("Send buffer watermark factor") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#send_buffer_watermark_factor", "(?)")) addRow(SEND_BUF_WATERMARK_FACTOR, (tr("Send buffer watermark factor") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#send_buffer_watermark_factor", "(?)"))

4
src/webui/api/searchcontroller.cpp

@ -28,6 +28,8 @@
#include "searchcontroller.h" #include "searchcontroller.h"
#include <limits>
#include <QJsonArray> #include <QJsonArray>
#include <QJsonObject> #include <QJsonObject>
#include <QSharedPointer> #include <QSharedPointer>
@ -293,7 +295,7 @@ int SearchController::generateSearchId() const
while (true) while (true)
{ {
const auto id = Utils::Random::rand(1, INT_MAX); const int id = Utils::Random::rand(1, std::numeric_limits<int>::max());
if (!searchHandlers.contains(id)) if (!searchHandlers.contains(id))
return id; return id;
} }

Loading…
Cancel
Save