Switch to C++17

This commit is contained in:
badaix 2021-06-27 13:07:07 +02:00
parent 3120a18326
commit 2cc9567847
11 changed files with 74 additions and 75 deletions

View file

@ -8,7 +8,7 @@
* This project loosely follows the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html)
* For better compatibility with embedded toolchains, the used C++ standard should be limited to C++14
* For better compatibility with embedded toolchains, the used C++ standard should be limited to C++17
* Code should be formatted by running `make reformat`

View file

@ -127,7 +127,7 @@ if(NOT ANDROID)
endif()
# Configure compiler options
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
# Get arch
include(${CMAKE_SOURCE_DIR}/cmake/TargetArch.cmake)

View file

@ -46,7 +46,7 @@ The following rule governs code contributions:
* This project loosely follows the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html)
* For better compatibility with embedded toolchains, the used C++ standard should be limited to C++14
* For better compatibility with embedded toolchains, the used C++ standard should be limited to C++17
* Code should be formatted by running `make reformat`

View file

@ -42,7 +42,7 @@ ifneq ($(SANITIZE), )
LDFLAGS += -fsanitize=$(SANITIZE)
endif
CXXFLAGS += $(ADD_CFLAGS) -std=c++14 -Wall -Wextra -Wpedantic -Wno-unused-function -DBOOST_ERROR_CODE_HEADER_ONLY -DHAS_FLAC -DHAS_OGG -DHAS_OPUS -DHAS_SOXR -DVERSION=\"$(VERSION)\" -I. -I.. -I../common
CXXFLAGS += $(ADD_CFLAGS) -std=c++17 -Wall -Wextra -Wpedantic -Wno-unused-function -DBOOST_ERROR_CODE_HEADER_ONLY -DHAS_FLAC -DHAS_OGG -DHAS_OPUS -DHAS_SOXR -DVERSION=\"$(VERSION)\" -I. -I.. -I../common
LDFLAGS += $(ADD_LDFLAGS) -logg -lFLAC -lopus -lsoxr
OBJ = snapclient.o stream.o client_connection.o time_provider.o player/player.o player/file_player.o decoder/pcm_decoder.o decoder/ogg_decoder.o decoder/flac_decoder.o decoder/opus_decoder.o controller.o ../common/sample_format.o ../common/resampler.o

View file

@ -22,8 +22,8 @@
#include "player.hpp"
#include <alsa/asoundlib.h>
#include <boost/optional.hpp>
#include <chrono>
#include <optional>
namespace player
@ -83,8 +83,8 @@ private:
std::recursive_mutex mutex_;
boost::asio::steady_timer timer_;
boost::optional<std::chrono::microseconds> buffer_time_;
boost::optional<uint32_t> periods_;
std::optional<std::chrono::microseconds> buffer_time_;
std::optional<uint32_t> periods_;
};
} // namespace player

View file

@ -136,7 +136,7 @@ vector<PcmDevice> PulsePlayer::pcm_list(const std::string& parameter)
PulsePlayer::PulsePlayer(boost::asio::io_context& io_context, const ClientSettings::Player& settings, std::shared_ptr<Stream> stream)
: Player(io_context, settings, stream), latency_(BUFFER_TIME), pa_ml_(nullptr), pa_ctx_(nullptr), playstream_(nullptr), proplist_(nullptr),
server_(boost::none)
server_(std::nullopt)
{
auto params = utils::string::split_pairs_to_container<std::vector<std::string>>(settings.parameter, ',', '=');
if (params.find("buffer_time") != params.end())

View file

@ -22,9 +22,9 @@
#include "player.hpp"
#include <atomic>
#include <boost/optional.hpp>
#include <cstdio>
#include <memory>
#include <optional>
#include <pulse/pulseaudio.h>
@ -74,7 +74,7 @@ protected:
pa_context* pa_ctx_;
pa_stream* playstream_;
pa_proplist* proplist_;
boost::optional<std::string> server_;
std::optional<std::string> server_;
std::map<std::string, std::string> properties_;
// cache of the last volume change

View file

@ -19,7 +19,7 @@
#ifndef METATAGS_HPP
#define METATAGS_HPP
#include <boost/optional.hpp>
#include <optional>
#include <set>
#include <string>
@ -41,92 +41,92 @@ public:
/// https://www.musicpd.org/doc/html/protocol.html#tags
/// the duration of the song
boost::optional<float> duration;
std::optional<float> duration;
/// the artist name. Its meaning is not well-defined; see “composer” and “performer” for more specific tags.
boost::optional<std::vector<std::string>> artist;
std::optional<std::vector<std::string>> artist;
/// same as artist, but for sorting. This usually omits prefixes such as “The”.
boost::optional<std::vector<std::string>> artist_sort;
std::optional<std::vector<std::string>> artist_sort;
/// the album name.
boost::optional<std::string> album;
std::optional<std::string> album;
/// same as album, but for sorting.
boost::optional<std::string> album_sort;
std::optional<std::string> album_sort;
/// on multi-artist albums, this is the artist name which shall be used for the whole album. The exact meaning of this tag is not well-defined.
boost::optional<std::vector<std::string>> album_artist;
std::optional<std::vector<std::string>> album_artist;
/// same as albumartist, but for sorting.
boost::optional<std::vector<std::string>> album_artist_sort;
std::optional<std::vector<std::string>> album_artist_sort;
/// a name for this song. This is not the song title. The exact meaning of this tag is not well-defined. It is often used by badly configured internet radio
/// stations with broken tags to squeeze both the artist name and the song title in one tag.
boost::optional<std::string> name;
std::optional<std::string> name;
/// the songs release date. This is usually a 4-digit year.
boost::optional<std::string> date;
std::optional<std::string> date;
/// the songs original release date.
boost::optional<std::string> original_date;
std::optional<std::string> original_date;
/// the artist who performed the song.
boost::optional<std::string> performer;
std::optional<std::string> performer;
/// the conductor who conducted the song.
boost::optional<std::string> conductor;
std::optional<std::string> conductor;
/// “a work is a distinct intellectual or artistic creation, which can be expressed in the form of one or more audio recordings”
boost::optional<std::string> work;
std::optional<std::string> work;
/// “used if the sound belongs to a larger category of sounds/music” (from the IDv2.4.0 TIT1 description).
boost::optional<std::string> grouping;
std::optional<std::string> grouping;
/// the name of the label or publisher.
boost::optional<std::string> label;
std::optional<std::string> label;
/// the artist id in the MusicBrainz database.
boost::optional<std::string> musicbrainz_artist_id;
std::optional<std::string> musicbrainz_artist_id;
/// the album id in the MusicBrainz database.
boost::optional<std::string> musicbrainz_album_id;
std::optional<std::string> musicbrainz_album_id;
/// the album artist id in the MusicBrainz database.
boost::optional<std::string> musicbrainz_album_artist_id;
std::optional<std::string> musicbrainz_album_artist_id;
/// the track id in the MusicBrainz database.
boost::optional<std::string> musicbrainz_track_id;
std::optional<std::string> musicbrainz_track_id;
/// the release track id in the MusicBrainz database.
boost::optional<std::string> musicbrainz_release_track_id;
std::optional<std::string> musicbrainz_release_track_id;
/// the work id in the MusicBrainz database.
boost::optional<std::string> musicbrainz_work_id;
std::optional<std::string> musicbrainz_work_id;
/// https://www.freedesktop.org/wiki/Specifications/mpris-spec/metadata/
/// A unique identity for this track within the context of an MPRIS object (eg: tracklist).
boost::optional<std::string> track_id;
std::optional<std::string> track_id;
/// URI: The location of an image representing the track or album. Clients should not assume this will continue to exist when the media player stops giving
/// out the URL
boost::optional<std::string> art_url;
std::optional<std::string> art_url;
/// The track lyrics
boost::optional<std::string> lyrics;
std::optional<std::string> lyrics;
/// The speed of the music, in beats per minute
boost::optional<uint16_t> bpm;
std::optional<uint16_t> bpm;
/// Float: An automatically-generated rating, based on things such as how often it has been played. This should be in the range 0.0 to 1.0
boost::optional<float> auto_rating;
std::optional<float> auto_rating;
/// A (list of) freeform comment(s)
boost::optional<std::vector<std::string>> comment;
std::optional<std::vector<std::string>> comment;
/// The composer(s) of the track
boost::optional<std::vector<std::string>> composer;
std::optional<std::vector<std::string>> composer;
/// Date/Time: When the track was created. Usually only the year component will be useful
boost::optional<std::string> content_created;
std::optional<std::string> content_created;
/// Integer: The disc number on the album that this track is from
boost::optional<uint16_t> disc_number;
std::optional<uint16_t> disc_number;
/// Date/Time: When the track was first played
boost::optional<std::string> first_used;
std::optional<std::string> first_used;
/// List of Strings: The genre(s) of the track
boost::optional<std::vector<std::string>> genre;
std::optional<std::vector<std::string>> genre;
/// Date/Time: When the track was last played
boost::optional<std::string> last_used;
std::optional<std::string> last_used;
/// List of Strings: The lyricist(s) of the track
boost::optional<std::vector<std::string>> lyricist;
std::optional<std::vector<std::string>> lyricist;
/// String: The track title
boost::optional<std::string> title;
std::optional<std::string> title;
/// Integer: The track number on the album disc
boost::optional<uint16_t> track_number;
std::optional<uint16_t> track_number;
/// URI: The location of the media file.
boost::optional<std::string> url;
std::optional<std::string> url;
/// Integer: The number of times the track has been played.
boost::optional<uint16_t> use_count;
std::optional<uint16_t> use_count;
/// Float: A user-specified rating. This should be in the range 0.0 to 1.0.
boost::optional<float> user_rating;
std::optional<float> user_rating;
/// Spotify artist id
boost::optional<std::string> spotify_artist_id;
std::optional<std::string> spotify_artist_id;
/// Spotify track id
boost::optional<std::string> spotify_track_id;
std::optional<std::string> spotify_track_id;
json toJson() const
{
@ -275,12 +275,12 @@ public:
private:
template <typename T>
void readTag(const json& j, const std::string& tag, boost::optional<T>& dest) const
void readTag(const json& j, const std::string& tag, std::optional<T>& dest) const
{
try
{
if (!j.contains(tag))
dest = boost::none;
dest = std::nullopt;
else
dest = j[tag].get<T>();
}
@ -291,7 +291,7 @@ private:
}
template <typename T>
void addTag(json& j, const std::string& tag, const boost::optional<T>& source) const
void addTag(json& j, const std::string& tag, const std::optional<T>& source) const
{
try
{

View file

@ -22,7 +22,7 @@
#include <set>
#include <string>
#include <boost/optional.hpp>
#include <optional>
#include "common/aixlog.hpp"
#include "common/json.hpp"
@ -154,22 +154,22 @@ public:
/// https://www.musicpd.org/doc/html/protocol.html#tags
/// The current playback status
boost::optional<PlaybackStatus> playback_status;
std::optional<PlaybackStatus> playback_status;
/// The current loop / repeat status
boost::optional<LoopStatus> loop_status;
std::optional<LoopStatus> loop_status;
/// The current playback rate
boost::optional<float> rate;
std::optional<float> rate;
/// A value of false indicates that playback is progressing linearly through a playlist, while true means playback is progressing through a playlist in some
/// other order.
boost::optional<bool> shuffle;
std::optional<bool> shuffle;
/// The volume level between 0-100
boost::optional<int> volume;
std::optional<int> volume;
/// The current track position in seconds
boost::optional<float> position;
std::optional<float> position;
/// The minimum value which the Rate property can take. Clients should not attempt to set the Rate property below this value
boost::optional<float> minimum_rate;
std::optional<float> minimum_rate;
/// The maximum value which the Rate property can take. Clients should not attempt to set the Rate property above this value
boost::optional<float> maximum_rate;
std::optional<float> maximum_rate;
/// Whether the client can call the Next method on this interface and expect the current track to change
bool can_go_next = false;
/// Whether the client can call the Previous method on this interface and expect the current track to change
@ -187,9 +187,9 @@ public:
{
json j;
if (playback_status.has_value())
addTag(j, "playbackStatus", boost::optional<std::string>(to_string(playback_status.value())));
addTag(j, "playbackStatus", std::optional<std::string>(to_string(playback_status.value())));
if (loop_status.has_value())
addTag(j, "loopStatus", boost::optional<std::string>(to_string(loop_status.value())));
addTag(j, "loopStatus", std::optional<std::string>(to_string(loop_status.value())));
addTag(j, "rate", rate);
addTag(j, "shuffle", shuffle);
addTag(j, "volume", volume);
@ -218,19 +218,19 @@ public:
LOG(WARNING, LOG_TAG) << "Property not supoorted: " << element.key() << "\n";
}
boost::optional<std::string> opt;
std::optional<std::string> opt;
readTag(j, "playbackStatus", opt);
if (opt.has_value())
playback_status = playback_status_from_string(opt.value());
else
playback_status = boost::none;
playback_status = std::nullopt;
readTag(j, "loopStatus", opt);
if (opt.has_value())
loop_status = loop_status_from_string(opt.value());
else
loop_status = boost::none;
loop_status = std::nullopt;
readTag(j, "rate", rate);
readTag(j, "shuffle", shuffle);
readTag(j, "volume", volume);
@ -253,12 +253,12 @@ public:
private:
template <typename T>
void readTag(const json& j, const std::string& tag, boost::optional<T>& dest) const
void readTag(const json& j, const std::string& tag, std::optional<T>& dest) const
{
try
{
if (!j.contains(tag))
dest = boost::none;
dest = std::nullopt;
else
dest = j[tag].get<T>();
}
@ -271,7 +271,7 @@ private:
template <typename T>
void readTag(const json& j, const std::string& tag, T& dest, const T& def) const
{
boost::optional<T> val;
std::optional<T> val;
readTag(j, tag, val);
if (val.has_value())
dest = val.value();
@ -280,7 +280,7 @@ private:
}
template <typename T>
void addTag(json& j, const std::string& tag, const boost::optional<T>& source) const
void addTag(json& j, const std::string& tag, const std::optional<T>& source) const
{
if (!source.has_value())
{

View file

@ -42,7 +42,7 @@ ifneq ($(SANITIZE), )
LDFLAGS += -fsanitize=$(SANITIZE)
endif
CXXFLAGS += $(ADD_CFLAGS) -std=c++14 -Wall -Wextra -Wpedantic -Wno-unused-function -DBOOST_ERROR_CODE_HEADER_ONLY -DHAS_FLAC -DHAS_OGG -DHAS_VORBIS -DHAS_VORBIS_ENC -DHAS_OPUS -DHAS_SOXR -DVERSION=\"$(VERSION)\" -I. -I.. -I../common
CXXFLAGS += $(ADD_CFLAGS) -std=c++17 -Wall -Wextra -Wpedantic -Wno-unused-function -DBOOST_ERROR_CODE_HEADER_ONLY -DHAS_FLAC -DHAS_OGG -DHAS_VORBIS -DHAS_VORBIS_ENC -DHAS_OPUS -DHAS_SOXR -DVERSION=\"$(VERSION)\" -I. -I.. -I../common
LDFLAGS += $(ADD_LDFLAGS) -lvorbis -lvorbisenc -logg -lFLAC -lopus -lsoxr
OBJ = snapserver.o server.o config.o control_server.o control_session_tcp.o control_session_http.o control_session_ws.o stream_server.o stream_session.o stream_session_tcp.o stream_session_ws.o streamreader/stream_uri.o streamreader/base64.o streamreader/stream_manager.o streamreader/pcm_stream.o streamreader/posix_stream.o streamreader/pipe_stream.o streamreader/file_stream.o streamreader/tcp_stream.o streamreader/process_stream.o streamreader/airplay_stream.o streamreader/meta_stream.o streamreader/librespot_stream.o streamreader/watchdog.o encoder/encoder_factory.o encoder/flac_encoder.o encoder/opus_encoder.o encoder/pcm_encoder.o encoder/null_encoder.o encoder/ogg_encoder.o ../common/sample_format.o ../common/resampler.o

View file

@ -27,7 +27,6 @@
#include <boost/asio/io_context.hpp>
#include <boost/asio/read_until.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/optional.hpp>
#include "common/json.hpp"
#include "common/metatags.hpp"