REFAC(client, server): Get rid of redundant Boost usages

Thanks to using a more modern C++ standard, many Boost usages can be and
have been replaced by STL functionality.
This commit is contained in:
Robert Adam 2025-08-04 17:05:43 +02:00
parent 6bda3baa92
commit 9b915f38a3
21 changed files with 76 additions and 85 deletions

View File

@ -60,10 +60,10 @@ paletteupdate_template ="""
}
"""
variable_template = """ boost::optional<QBrush> m_%(prop)s;
variable_template = """ std::optional<QBrush> m_%(prop)s;
"""
reset_template = """ m_%(prop)s = boost::none;
reset_template = """ m_%(prop)s = std::nullopt;
"""
def rolename(role):

View File

@ -64,7 +64,7 @@ def generateFunction(className, functionName, wrapArgs, callArgs):
function += "\t}\n"
function += "#endif // ACCESS_" + className + "_" + functionName + "_ALL\n"
function += "\n"
function += "\tExecEvent *ie = new ExecEvent(boost::bind(&impl_" + className + "_" + functionName + ", " + ", ".join(callArgs) + "));\n"
function += "\tExecEvent *ie = new ExecEvent(std::bind(&impl_" + className + "_" + functionName + ", " + ", ".join(callArgs) + "));\n"
function += "\tQCoreApplication::instance()->postEvent(mi, ie);\n"
function += "}\n"
@ -111,8 +111,7 @@ def main():
wrapperContent = create_disclaimerComment()
# Include boost-bind as we'll need it later
wrapperContent += "\n#include <boost/bind/bind.hpp>\n\n"
wrapperContent += "\n#include <functional>\n\n"
className = ""

View File

@ -7,8 +7,6 @@
#include <cassert>
#include <boost/algorithm/string.hpp>
namespace mumble {
namespace db {
@ -28,7 +26,7 @@ namespace db {
const std::string Column::getName() const { return m_name; }
void Column::setName(const std::string &name) {
assert(!boost::contains(name, " "));
assert(name.find(' ') == std::string::npos);
m_name = name;
}

View File

@ -416,7 +416,7 @@ namespace db {
THROW_FORMATERROR("Encountered non-string column type specification at position "
+ std::to_string(i + 1));
}
if (boost::contains(colNames[i].get< std::string >(), " ")) {
if (colNames[i].get< std::string >().find(' ') != std::string::npos) {
THROW_FORMATERROR("Invalid column name \"" + colNames[i].get< std::string >() + "\"");
}
try {
@ -621,15 +621,15 @@ namespace db {
void Table::performCtorAssertions() {
// Names with spaces are not allowed as these cause issues
assert(!boost::contains(m_name, " "));
assert(m_name.find(' ') == std::string::npos);
#ifndef NDEBUG
for (const Column &currentColumn : m_columns) {
assert(!boost::contains(currentColumn.getName(), " "));
assert(currentColumn.getName().find(' ') == std::string::npos);
}
#endif
// We reserve the name for a table's backup (needed during migrations) right from the start
assert(!boost::ends_with(m_name, Table::BACKUP_SUFFIX));
assert(m_name.find(Table::BACKUP_SUFFIX) == std::string::npos);
}
} // namespace db

View File

@ -18,11 +18,11 @@ namespace db {
const std::string &triggerBody, const std::string &condition)
: m_name(name), m_timing(timing), m_event(event), m_triggerBody(triggerBody), m_condition(condition) {
// Ensure trigger body always ends in semicolon
if (!boost::ends_with(m_triggerBody, ";") && !m_triggerBody.empty()) {
if (!m_triggerBody.empty() && m_triggerBody.back() != ';') {
m_triggerBody += ";";
}
// Ensure condition never ends in semicolon
if (boost::ends_with(m_condition, ";")) {
if (!m_condition.empty() && m_condition.back() == ';') {
m_condition.erase(m_condition.size() - 1);
}
}
@ -45,7 +45,7 @@ namespace db {
m_triggerBody = body;
// Ensure trigger body always ends in semicolon
if (!boost::ends_with(m_triggerBody, ";") && !m_triggerBody.empty()) {
if (!m_triggerBody.empty() && m_triggerBody.back() != ';') {
m_triggerBody += ";";
}
}
@ -56,7 +56,7 @@ namespace db {
m_condition = condition;
// Ensure condition never ends in semicolon
if (boost::ends_with(m_condition, ";")) {
if (!m_condition.empty() && m_condition.back() == ';') {
m_condition.erase(m_condition.size() - 1);
}
}

View File

@ -13,12 +13,11 @@
#include <QTimer>
#include <QWidget>
#ifndef Q_MOC_RUN
# include <boost/optional.hpp>
#endif
#include <QApplication>
#include <QDebug>
#include <optional>
///
/// Class enabling theming of QApplication::palette from stylesheets.
///

View File

@ -10,9 +10,7 @@
#include <QObject>
#include <QThread>
#include <boost/array.hpp>
#include <boost/shared_ptr.hpp>
#include <array>
#include <cstdint>
#include <fstream>
#include <list>
@ -34,7 +32,8 @@
class AudioInput;
struct OpusEncoder;
struct DenoiseState;
typedef boost::shared_ptr< AudioInput > AudioInputPtr;
using AudioInputPtr = std::shared_ptr< AudioInput >;
/**
* A chunk of audio data to process
@ -195,7 +194,7 @@ private:
bool selectCodec();
void selectNoiseCancel();
typedef boost::array< unsigned char, 960 > EncodingOutputBuffer;
using EncodingOutputBuffer = std::array< unsigned char, 960 >;
int encodeOpusFrame(short *source, int size, EncodingOutputBuffer &buffer);

View File

@ -22,6 +22,7 @@
#include <algorithm>
#include <cassert>
#include <cmath>
#include <memory>
// Remember that we cannot use static member classes that are not pointers, as the constructor
// for AudioOutputRegistrar() might be called before they are initialized, as the constructor
@ -521,9 +522,9 @@ bool AudioOutput::mix(void *outbuff, unsigned int frameCount) {
bool validListener = false;
// Initialize recorder if recording is enabled
boost::shared_array< float > recbuff;
std::shared_ptr< float[] > recbuff;
if (recorder) {
recbuff = boost::shared_array< float >(new float[frameCount]);
recbuff = std::make_shared< float[] >(frameCount);
memset(recbuff.get(), 0, sizeof(float) * frameCount);
recorder->prepareBufferAdds();
}
@ -699,7 +700,7 @@ bool AudioOutput::mix(void *outbuff, unsigned int frameCount) {
if (!recorder->isInMixDownMode()) {
recorder->addBuffer(speech->p, recbuff, static_cast< int >(frameCount));
recbuff = boost::shared_array< float >(new float[frameCount]);
recbuff = std::make_shared< float[] >(frameCount);
memset(recbuff.get(), 0, sizeof(float) * frameCount);
}

View File

@ -8,7 +8,6 @@
#include <QtCore/QObject>
#include <QtCore/QThread>
#include <boost/shared_ptr.hpp>
#include "MumbleProtocol.h"
@ -16,6 +15,8 @@
# include "ManualPlugin.h"
#endif
#include <memory>
#ifndef SPEAKER_FRONT_LEFT
# define SPEAKER_FRONT_LEFT 0x1
# define SPEAKER_FRONT_RIGHT 0x2
@ -44,7 +45,7 @@ class ClientUser;
class AudioOutputBuffer;
class AudioOutputToken;
typedef boost::shared_ptr< AudioOutput > AudioOutputPtr;
using AudioOutputPtr = std::shared_ptr< AudioOutput >;
class AudioOutputRegistrar {
private:

View File

@ -34,7 +34,6 @@
#include <QtXml/QDomDocument>
#include <boost/accumulators/statistics/extended_p_square.hpp>
#include <boost/array.hpp>
#ifdef Q_OS_WIN
# ifndef NOMINMAX
@ -46,6 +45,7 @@
#include <QRandomGenerator>
#include <algorithm>
#include <array>
QMap< QString, QIcon > ServerItem::qmIcons;
QList< PublicInfo > ConnectDialog::qlPublicServers;
@ -62,7 +62,7 @@ PingStats::~PingStats() {
}
void PingStats::init() {
boost::array< double, 3 > probs = { { 0.75, 0.80, 0.95 } };
std::array< double, 3 > probs = { 0.75, 0.80, 0.95 };
asQuantile = new asQuantileType(boost::accumulators::tag::extended_p_square::probabilities = probs);
dPing = 0.0;

View File

@ -7,7 +7,6 @@
#define MUMBLE_MUMBLE_GLOBAL_H_
#include <QtCore/QDir>
#include <boost/shared_ptr.hpp>
#include "ACL.h"
#include "ChannelListenerManager.h"
@ -52,9 +51,9 @@ public:
MainWindow *mw;
TrayIcon *trayIcon;
Settings s;
boost::shared_ptr< ServerHandler > sh;
boost::shared_ptr< AudioInput > ai;
boost::shared_ptr< AudioOutput > ao;
std::shared_ptr< ServerHandler > sh;
std::shared_ptr< AudioInput > ai;
std::shared_ptr< AudioOutput > ao;
/**
* @remark Must only be accessed from the main event loop
*/

View File

@ -17,7 +17,6 @@
# include <boost/accumulators/statistics/mean.hpp>
# include <boost/accumulators/statistics/stats.hpp>
# include <boost/accumulators/statistics/variance.hpp>
# include <boost/shared_ptr.hpp>
#endif
#include <QtCore/QEvent>
@ -37,6 +36,8 @@
#include "ServerAddress.h"
#include "Timer.h"
#include <memory>
class Connection;
class Database;
class PacketDataStream;
@ -52,7 +53,7 @@ public:
ServerHandlerMessageEvent(const QByteArray &msg, Mumble::Protocol::TCPMessageType type, bool flush = false);
};
typedef boost::shared_ptr< Connection > ConnectionPtr;
using ConnectionPtr = std::shared_ptr< Connection >;
class ServerHandler : public QThread {
private:
@ -102,7 +103,7 @@ public:
QSslCipher qscCipher;
ConnectionPtr cConnection;
QByteArray qbaDigest;
boost::shared_ptr< VoiceRecorder > recorder;
std::shared_ptr< VoiceRecorder > recorder;
QSslSocket *qtsSock;
QList< ServerAddress > qlAddresses;
QHash< ServerAddress, QString > qhHostnames;
@ -208,6 +209,6 @@ public slots:
void sendPing();
};
typedef boost::shared_ptr< ServerHandler > ServerHandlerPtr;
using ServerHandlerPtr = std::shared_ptr< ServerHandler >;
#endif

View File

@ -68,7 +68,7 @@ public:
/// Loads the theme description from a given directory
///
/// @param themeDirectory
/// @return Theme if description was correctly loaded. boost::none if not.
/// @return Theme if description was correctly loaded. std::nullopt if not.
static std::optional< ThemeInfo > load(const QDir &themeDirectory);
/// @return Style with given name or default

View File

@ -12,11 +12,11 @@
#include "../Timer.h"
#include <boost/make_shared.hpp>
#include <QRegularExpression>
VoiceRecorder::RecordBuffer::RecordBuffer(int recordInfoIndex_, boost::shared_array< float > buffer_, int samples_,
#include <memory>
VoiceRecorder::RecordBuffer::RecordBuffer(int recordInfoIndex_, std::shared_ptr< float[] > buffer_, int samples_,
quint64 absoluteStartSample_)
: recordInfoIndex(recordInfoIndex_), buffer(buffer_), samples(samples_), absoluteStartSample(absoluteStartSample_) {
@ -245,7 +245,7 @@ SF_INFO VoiceRecorder::createSoundFileInfo() const {
return sfinfo;
}
bool VoiceRecorder::ensureFileIsOpenedFor(SF_INFO &soundFileInfo, boost::shared_ptr< RecordInfo > &ri) {
bool VoiceRecorder::ensureFileIsOpenedFor(SF_INFO &soundFileInfo, std::shared_ptr< RecordInfo > &ri) {
if (ri->soundFile) {
// Nothing to do
return true;
@ -328,7 +328,7 @@ void VoiceRecorder::run() {
const bool shouldMixDown = m_config.mixDownMode && m_config.transportEnable;
while (!shouldMixDown && !m_abort && !m_recordBuffer.isEmpty()) {
boost::shared_ptr< RecordBuffer > rb;
std::shared_ptr< RecordBuffer > rb;
{
QMutexLocker l(&m_bufferLock);
rb = m_recordBuffer.takeFirst();
@ -337,7 +337,7 @@ void VoiceRecorder::run() {
// Create the file for this RecordInfo instance if it's not yet open.
Q_ASSERT(m_recordInfo.contains(rb->recordInfoIndex));
boost::shared_ptr< RecordInfo > ri = m_recordInfo.value(rb->recordInfoIndex);
std::shared_ptr< RecordInfo > ri = m_recordInfo.value(rb->recordInfoIndex);
if (!ensureFileIsOpenedFor(soundFileInfo, ri)) {
return;
@ -406,7 +406,7 @@ void VoiceRecorder::prepareBufferAdds() {
m_absoluteSampleEstimation = (m_timestamp->elapsed() / 1000) * (static_cast< quint64 >(m_config.sampleRate) / 1000);
}
void VoiceRecorder::addBuffer(const ClientUser *clientUser, boost::shared_array< float > buffer, int samples) {
void VoiceRecorder::addBuffer(const ClientUser *clientUser, std::shared_ptr< float[] > buffer, int samples) {
Q_ASSERT(!m_config.mixDownMode || !clientUser);
if (!m_recording)
@ -416,8 +416,8 @@ void VoiceRecorder::addBuffer(const ClientUser *clientUser, boost::shared_array<
const int index = indexForUser(clientUser);
if (!m_recordInfo.contains(index)) {
boost::shared_ptr< RecordInfo > ri =
boost::make_shared< RecordInfo >(m_config.mixDownMode ? QLatin1String("Mixdown") : clientUser->qsName);
std::shared_ptr< RecordInfo > ri =
std::make_shared< RecordInfo >(m_config.mixDownMode ? QLatin1String("Mixdown") : clientUser->qsName);
m_recordInfo.insert(index, ri);
}
@ -425,8 +425,8 @@ void VoiceRecorder::addBuffer(const ClientUser *clientUser, boost::shared_array<
{
// Save the buffer in |qlRecordBuffer|.
QMutexLocker l(&m_bufferLock);
boost::shared_ptr< RecordBuffer > rb =
boost::make_shared< RecordBuffer >(index, buffer, samples, m_absoluteSampleEstimation);
std::shared_ptr< RecordBuffer > rb =
std::make_shared< RecordBuffer >(index, buffer, samples, m_absoluteSampleEstimation);
m_recordBuffer << rb;
}

View File

@ -12,11 +12,6 @@
# include "win.h"
#endif
#ifndef Q_MOC_RUN
# include <boost/scoped_ptr.hpp>
# include <boost/shared_array.hpp>
#endif
#include <QtCore/QDateTime>
#include <QtCore/QHash>
#include <QtCore/QMutex>
@ -24,6 +19,8 @@
#include <QtCore/QThread>
#include <QtCore/QWaitCondition>
#include <memory>
#ifdef Q_OS_WIN
# define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1
#endif
@ -117,7 +114,7 @@ public:
/// The audio data will be assumed to be recorded at the time
/// prepareBufferAdds was last called.
/// @param clientUser User for which to add the audio data. nullptr in mixdown mode.
void addBuffer(const ClientUser *clientUser, boost::shared_array< float > buffer, int samples);
void addBuffer(const ClientUser *clientUser, std::shared_ptr< float[] > buffer, int samples);
/// Returns the elapsed time since the recording started.
quint64 getElapsedTime() const;
@ -144,14 +141,14 @@ private:
/// Stores information about a recording buffer.
struct RecordBuffer {
/// Constructs a new RecordBuffer object.
RecordBuffer(int recordInfoIndex_, boost::shared_array< float > buffer_, int samples_,
RecordBuffer(int recordInfoIndex_, std::shared_ptr< float[] > buffer_, int samples_,
quint64 absoluteStartSample_);
/// Hashmap index for the user
const int recordInfoIndex;
/// The buffer.
boost::shared_array< float > buffer;
std::shared_ptr< float[] > buffer;
/// The number of samples in the buffer.
int samples;
@ -175,7 +172,7 @@ private:
quint64 lastWrittenAbsoluteSample;
};
typedef QHash< int, boost::shared_ptr< RecordInfo > > RecordInfoMap;
using RecordInfoMap = QHash< int, std::shared_ptr< RecordInfo > >;
/// Removes invalid characters in a path component.
QString sanitizeFilenameOrPathComponent(const QString &str) const;
@ -191,20 +188,20 @@ private:
/// Opens the file for the given recording information
/// Helper function for run method. Will abort recording on failure.
bool ensureFileIsOpenedFor(SF_INFO &soundFileInfo, boost::shared_ptr< RecordInfo > &ri);
bool ensureFileIsOpenedFor(SF_INFO &soundFileInfo, std::shared_ptr< RecordInfo > &ri);
/// Hash which maps the |uiSession| of all users for which we have to keep a recording state to the corresponding
/// RecordInfo object.
RecordInfoMap m_recordInfo;
/// List containing all unprocessed RecordBuffer objects.
QList< boost::shared_ptr< RecordBuffer > > m_recordBuffer;
QList< std::shared_ptr< RecordBuffer > > m_recordBuffer;
/// The user which is used to record local audio.
boost::scoped_ptr< RecordUser > m_recordUser;
std::unique_ptr< RecordUser > m_recordUser;
/// High precision timer for buffer timestamps.
boost::scoped_ptr< Timer > m_timestamp;
std::unique_ptr< Timer > m_timestamp;
/// Protects the buffer list |qlRecordBuffer|.
QMutex m_bufferLock;
@ -229,6 +226,6 @@ private:
quint64 m_absoluteSampleEstimation;
};
typedef boost::shared_ptr< VoiceRecorder > VoiceRecorderPtr;
using VoiceRecorderPtr = std::shared_ptr< VoiceRecorder >;
#endif

View File

@ -9,7 +9,8 @@
#include "Global.h"
#include <QtCore/QMutexLocker>
#include <boost/thread/once.hpp>
#include <mutex>
HRESULT STDMETHODCALLTYPE WASAPINotificationClient::OnDefaultDeviceChanged(EDataFlow flow, ERole role,
LPCWSTR pwstrDefaultDevice) {
@ -159,11 +160,11 @@ WASAPINotificationClient &WASAPINotificationClient::doGet() {
return instance;
}
static boost::once_flag notification_client_init_once = BOOST_ONCE_INIT;
static std::once_flag notification_client_init_once;
WASAPINotificationClient &WASAPINotificationClient::get() {
// Hacky way of making sure we get a thread-safe yet lazy initialization of the static.
boost::call_once(&WASAPINotificationClient::doGetOnce, notification_client_init_once);
std::call_once(notification_client_init_once, &WASAPINotificationClient::doGetOnce);
return doGet();
}

View File

@ -52,6 +52,8 @@
#include <nlohmann/json.hpp>
#include <boost/algorithm/string.hpp>
#include <cassert>
#include <limits>
#include <optional>

View File

@ -42,8 +42,6 @@
#include <QtNetwork/QHostInfo>
#include <QtNetwork/QSslConfiguration>
#include <boost/bind/bind.hpp>
#include "TracyConstants.h"
#include <tracy/Tracy.hpp>
#include <tracy/TracyC.h>
@ -51,6 +49,7 @@
#include <algorithm>
#include <cassert>
#include <chrono>
#include <functional>
#include <optional>
#include <vector>
@ -62,7 +61,7 @@
# include <poll.h>
#endif
ExecEvent::ExecEvent(boost::function< void() > f) : QEvent(static_cast< QEvent::Type >(EXEC_QEVENT)) {
ExecEvent::ExecEvent(std::function< void() > f) : QEvent(static_cast< QEvent::Type >(EXEC_QEVENT)) {
func = f;
}
@ -1674,9 +1673,10 @@ void Server::connectionClosed(QAbstractSocket::SocketError err, const QString &r
old->removeUser(u);
}
if (old && old->bTemporary && old->qlUsers.isEmpty())
QCoreApplication::instance()->postEvent(this,
new ExecEvent(boost::bind(&Server::removeChannel, this, old->iId)));
if (old && old->bTemporary && old->qlUsers.isEmpty()) {
auto func_ptr = std::mem_fn< void(unsigned int) >(&Server::removeChannel);
QCoreApplication::instance()->postEvent(this, new ExecEvent(std::bind(func_ptr, this, old->iId)));
}
if (u->uiSession > 0 && u->uiSession < iMaxUsers * 2)
qqIds.enqueue(u->uiSession); // Reinsert session id into pool
@ -2055,8 +2055,8 @@ void Server::userEnterChannel(User *p, Channel *c, MumbleProto::UserState &mpus)
}
if (old && old->bTemporary && old->qlUsers.isEmpty()) {
QCoreApplication::instance()->postEvent(this,
new ExecEvent(boost::bind(&Server::removeChannel, this, old->iId)));
auto func_ptr = std::mem_fn< void(unsigned int) >(&Server::removeChannel);
QCoreApplication::instance()->postEvent(this, new ExecEvent(std::bind(func_ptr, this, old->iId)));
}
sendClientPermission(static_cast< ServerUser * >(p), c);

View File

@ -28,10 +28,6 @@
#include "database/ConnectionParameter.h"
#ifndef Q_MOC_RUN
# include <boost/function.hpp>
#endif
#include <QtCore/QEvent>
#include <QtCore/QMutex>
#include <QtCore/QQueue>
@ -54,6 +50,7 @@
# include <winsock2.h>
#endif
#include <functional>
#include <optional>
#include <vector>
@ -90,10 +87,10 @@ class ExecEvent : public QEvent {
Q_DISABLE_COPY(ExecEvent)
protected:
boost::function< void() > func;
std::function< void() > func;
public:
ExecEvent(boost::function< void() >);
ExecEvent(std::function< void() >);
void execute();
};

View File

@ -12,8 +12,6 @@
#include <optional>
#include <string>
#include <boost/algorithm/string.hpp>
namespace mumble {
namespace server {
namespace db {

View File

@ -17,7 +17,6 @@
#include "database/TransactionHolder.h"
#include "database/Utils.h"
#include <boost/optional/optional.hpp>
#include <soci/soci.h>
#include <cassert>