Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REFAC(client,server): boost calls replaced with STL ones #6731

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ list(APPEND CMAKE_MODULE_PATH
)

if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say please use a separate, dedicated commit just to raise the C++ version

In this dedicated commit, also change this doc: https://github.com/mumble-voip/mumble/blob/master/docs/dev/build-instructions/README.md to include cpp20 instead of 17

endif()
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15)
Expand Down
4 changes: 2 additions & 2 deletions scripts/generate-ApplicationPalette-class.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
}
"""

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):
Expand Down
6 changes: 2 additions & 4 deletions scripts/generateIceWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -111,9 +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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should include <function> instead.


wrapperContent +="\n#include <functional>\n\n"

className = ""
for currentLine in generatedIceHeader.split("\n"):
Expand Down
82 changes: 2 additions & 80 deletions src/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,8 @@
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#include <boost/version.hpp>

// Not all Boost versions can use a header-only
// boost_system without build failures.
//
// See mumble-voip/mumble#2366.
//
// This was fixed in Boost 1.56.0.
//
// See:
// https://github.com/boostorg/system/blob/boost-1.56.0/include/boost/system/error_code.hpp#L514-L516
// vs.
// https://github.com/boostorg/system/blob/boost-1.55.0/include/boost/system/error_code.hpp#L515-L517
#if BOOST_VERSION >= 105600 && !defined(__MINGW32__)
# define USE_BOOST_CHRONO
#endif

#include "Timer.h"
#include <chrono>

Timer::Timer(bool start) {
uiStart = start ? now() : 0;
Expand Down Expand Up @@ -59,68 +43,6 @@ bool Timer::operator>(const Timer &other) const {
return uiStart < other.uiStart;
}

#ifdef USE_BOOST_CHRONO
// Ensure boost_system is header only.
# define BOOST_ERROR_CODE_HEADER_ONLY
// Ensure boost_chrono is header only.
# define BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
# define BOOST_CHRONO_HEADER_ONLY

# include <boost/chrono.hpp>

quint64 Timer::now() {
using namespace boost::chrono;
time_point< steady_clock > now = steady_clock::now();
time_point< steady_clock >::duration epochDuration = now.time_since_epoch();
microseconds epochDurationUsec = duration_cast< microseconds >(epochDuration);
return static_cast< quint64 >(epochDurationUsec.count());
}
#elif defined(Q_OS_WIN)
# include "win.h"

quint64 Timer::now() {
static double scale = 0;

if (scale == 0) {
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
scale = 1000000. / freq.QuadPart;
}

LARGE_INTEGER li;
QueryPerformanceCounter(&li);
quint64 e = li.QuadPart;

return static_cast< quint64 >(e * scale);
}
#elif defined(Q_OS_UNIX)
# include <errno.h>
# include <string.h>
# include <time.h>
# include <unistd.h>
# if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK)
quint64 Timer::now() {
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
qFatal("Timer: clock_gettime() failed: (%i) %s", errno, strerror(errno));
}
quint64 e = ts.tv_sec * 1000000LL;
e += ts.tv_nsec / 1000LL;
return e;
}
# else
quint64 Timer::now() {
struct timeval tv;
gettimeofday(&tv, nullptr);
quint64 e = tv.tv_sec * 1000000LL;
e += tv.tv_usec;
return e;
}
# endif
#else
quint64 Timer::now() {
static QTime ticker;
quint64 elapsed = ticker.elapsed();
return elapsed * 1000LL;
return static_cast<quint64>(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
}
#endif
8 changes: 3 additions & 5 deletions src/User.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
#ifndef MUMBLE_USER_H_
#define MUMBLE_USER_H_

#ifndef Q_MOC_RUN
# include <boost/optional.hpp>
#endif

#include <QtCore/QByteArray>
#include <QtCore/QDateTime>
#include <QtCore/QList>
#include <QtCore/QString>

#include <optional>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <optional>
#include <optional>

We (mostly) try to keep different headers in different include blocks. That is, different blocks per library.


class Channel;

class User {
Expand Down Expand Up @@ -46,7 +44,7 @@ class User {
struct UserInfo {
int user_id;
QString name;
boost::optional< int > last_channel;
std::optional< int > last_channel;
QDateTime last_active;

UserInfo() : user_id(-1) {}
Expand Down
3 changes: 0 additions & 3 deletions src/mumble/ApplicationPaletteTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

#include <QTimer>
#include <QWidget>
#ifndef Q_MOC_RUN
# include <boost/optional.hpp>
#endif
#include <QApplication>
#include <QDebug>

Expand Down
7 changes: 2 additions & 5 deletions src/mumble/AudioInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
#include <QObject>
#include <QThread>

#include <boost/array.hpp>
#include <boost/shared_ptr.hpp>

#include <cstdint>
#include <fstream>
#include <list>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to include <memory> and <array>

Expand All @@ -34,7 +31,7 @@
class AudioInput;
struct OpusEncoder;
struct ReNameNoiseDenoiseState;
typedef boost::shared_ptr< AudioInput > AudioInputPtr;
typedef std::shared_ptr< AudioInput > AudioInputPtr;

/**
* A chunk of audio data to process
Expand Down Expand Up @@ -195,7 +192,7 @@ class AudioInput : public QThread {
bool selectCodec();
void selectNoiseCancel();

typedef boost::array< unsigned char, 960 > EncodingOutputBuffer;
typedef std::array< unsigned char, 960 > EncodingOutputBuffer;

int encodeOpusFrame(short *source, int size, EncodingOutputBuffer &buffer);

Expand Down
8 changes: 4 additions & 4 deletions src/mumble/AudioOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ AudioOutputPtr AudioOutputRegistrar::newFromChoice(QString choice) {
}

AudioOutputRegistrar *r = nullptr;
foreach (AudioOutputRegistrar *aor, *qmNew)
for (AudioOutputRegistrar *aor : *qmNew)
if (!r || (aor->priority > r->priority))
r = aor;
if (r) {
Expand Down Expand Up @@ -508,9 +508,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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't do that already, we should add a <memory> include to this file

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();
}
Expand Down Expand Up @@ -654,7 +654,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);
}

Expand Down
5 changes: 3 additions & 2 deletions src/mumble/AudioOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

#include <QtCore/QObject>
#include <QtCore/QThread>
#include <boost/shared_ptr.hpp>

#include <memory>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate include blocks


#include "MumbleProtocol.h"

Expand Down Expand Up @@ -44,7 +45,7 @@ class ClientUser;
class AudioOutputBuffer;
class AudioOutputToken;

typedef boost::shared_ptr< AudioOutput > AudioOutputPtr;
typedef std::shared_ptr< AudioOutput > AudioOutputPtr;

class AudioOutputRegistrar {
private:
Expand Down
5 changes: 3 additions & 2 deletions src/mumble/ConnectDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
#include <QtXml/QDomDocument>

#include <boost/accumulators/statistics/extended_p_square.hpp>
#include <boost/array.hpp>

#include <array>

#ifdef Q_OS_WIN
# ifndef NOMINMAX
Expand Down Expand Up @@ -61,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;
Expand Down
11 changes: 5 additions & 6 deletions src/mumble/Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
#define MUMBLE_MUMBLE_GLOBAL_H_

#include <QtCore/QDir>
#include <boost/shared_ptr.hpp>

#include <memory>

#include "ACL.h"
#include "ChannelListenerManager.h"
#include "Settings.h"
#include "Timer.h"
#include "Version.h"

#include <memory>

// Global helper class to spread variables around across threads.

class MainWindow;
Expand Down Expand Up @@ -52,9 +51,9 @@ struct Global Q_DECL_FINAL {
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
*/
Expand Down
12 changes: 7 additions & 5 deletions src/mumble/LookConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <QtCore/QStack>
#include <QtCore/QTimer>

#include <optional>

const QString LookConfig::name = QLatin1String("LookConfig");

static ConfigWidget *LookConfigNew(Settings &st) {
Expand All @@ -39,7 +41,7 @@ LookConfig::LookConfig(Settings &st) : ConfigWidget(st) {

qcbLanguage->addItem(tr("System default"));
QDir d(QLatin1String(":"), QLatin1String("mumble_*.qm"), QDir::Name, QDir::Files);
foreach (const QString &key, d.entryList()) {
for (const QString &key : d.entryList()) {
QString cc = key.mid(7, key.indexOf(QLatin1Char('.')) - 7);
QLocale tmpLocale = QLocale(cc);

Expand Down Expand Up @@ -117,7 +119,7 @@ QIcon LookConfig::icon() const {
return QIcon(QLatin1String("skin:config_ui.png"));
}

void LookConfig::reloadThemes(const boost::optional< ThemeInfo::StyleInfo > configuredStyle) {
void LookConfig::reloadThemes(const std::optional< ThemeInfo::StyleInfo >& configuredStyle) {
const ThemeMap themes = Themes::getThemes();

int selectedThemeEntry = 0;
Expand Down Expand Up @@ -193,7 +195,7 @@ void LookConfig::load(const Settings &r) {
loadCheckBox(qcbChatBarUseSelection, r.bChatBarUseSelection);
loadCheckBox(qcbFilterHidesEmptyChannels, r.bFilterHidesEmptyChannels);

const boost::optional< ThemeInfo::StyleInfo > configuredStyle = Themes::getConfiguredStyle(r);
const std::optional< ThemeInfo::StyleInfo > configuredStyle = Themes::getConfiguredStyle(r);
reloadThemes(configuredStyle);

loadCheckBox(qcbUsersAlwaysVisible, r.talkingUI_UsersAlwaysVisible);
Expand Down Expand Up @@ -263,7 +265,7 @@ void LookConfig::save() const {

QVariant themeData = qcbTheme->itemData(qcbTheme->currentIndex());
if (themeData.isNull()) {
Themes::setConfiguredStyle(s, boost::none, s.requireRestartToApply);
Themes::setConfiguredStyle(s, std::nullopt, s.requireRestartToApply);
} else {
Themes::setConfiguredStyle(s, themeData.value< ThemeInfo::StyleInfo >(), s.requireRestartToApply);
}
Expand Down Expand Up @@ -297,7 +299,7 @@ void LookConfig::themeDirectoryChanged() {
qWarning() << "Theme directory changed";
QVariant themeData = qcbTheme->itemData(qcbTheme->currentIndex());
if (themeData.isNull()) {
reloadThemes(boost::none);
reloadThemes(std::nullopt);
} else {
reloadThemes(themeData.value< ThemeInfo::StyleInfo >());
}
Expand Down
2 changes: 1 addition & 1 deletion src/mumble/LookConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public slots:

private:
/// Reload themes combobox and select given configuredStyle in it
void reloadThemes(const boost::optional< ThemeInfo::StyleInfo > configuredStyle);
void reloadThemes(const std::optional< ThemeInfo::StyleInfo >& configuredStyle);

/// Timer to prevent change event floods from triggering theme reloads
QTimer *m_themeDirectoryDebouncer;
Expand Down
Loading
Loading