Verified Commit ebf0ba5b authored by Moritz Bunkus's avatar Moritz Bunkus
Browse files

source: use `std::optional` instead of `boost::optional`

parent a18fe530
......@@ -34,6 +34,10 @@
size of a field which in turn could have led to the slice's type being read
wrong. Patch by Torsten Hauska. Fixes #2710.
## Build system changes
* `std::optional` (C++17 feature) is now used instead of `boost::optional`.
# Version 41.0.0 "Smarra" 2019-12-06
......
......@@ -85,8 +85,9 @@ programs and libraries you absolutely need are:
`nullptr` keyword, tuples, alias declarations, `std::make_unique()`,
digit separators, binary literals, generic lambdas, user-defined
literals for `std::string`, `[[maybe_unused]]` attribute, nested
namespace definition, structured bindings. Others may be needed,
too. For GCC this means at least v7; for clang v4 or later.
namespace definition, structured bindings, `std::optional`. Others
may be needed, too. For GCC this means at least v7; for clang v4 or
later.
- [libOgg](http://downloads.xiph.org/releases/ogg/) and
[libVorbis](http://downloads.xiph.org/releases/vorbis/) for access to Ogg/OGM
......
......@@ -456,7 +456,34 @@ AC_DEFUN([AX_CXX17_NESTED_NAMESPACE_DEFINITION],[
fi
])
dnl AC_DEFUN([AX_CXX17_DEF_NAME],[
AC_DEFUN([AX_CXX17_STD_OPTIONAL],[
AC_CACHE_CHECK([for support for C++17 feature "std::optional"], [ax_cv_cxx17_std_optional],[
CXXFLAGS_SAVED=$CXXFLAGS
CXXFLAGS="$CXXFLAGS $STD_CXX"
export CXXFLAGS
AC_LANG_PUSH(C++)
AC_TRY_COMPILE(
[#include <optional>],
[
std::optional<int> moo;
moo = 42;
return moo.value_or(54);
],
[ax_cv_cxx17_std_optional="yes"],
[ax_cv_cxx17_std_optional="no"])
AC_LANG_POP
CXXFLAGS="$CXXFLAGS_SAVED"
])
if ! test x"$ax_cv_cxx17_std_optional" = xyes ; then
missing_cxx_features="$missing_cxx_features\n * std::optional (C++17)"
fi
])
AC_DEFUN([AX_CXX17_DEF_NAME],[
dnl AC_CACHE_CHECK([for support for C++17 feature "human"], [ax_cv_cxx17_def_name],[
dnl
dnl CXXFLAGS_SAVED=$CXXFLAGS
......@@ -496,10 +523,11 @@ AX_CXX14_USER_DEFINED_LITERALS_FOR_STD_STRING
AX_CXX17_ATTRIBUTE_MAYBE_UNUSED
AX_CXX17_NESTED_NAMESPACE_DEFINITION
AX_CXX17_STRUCTURED_BINDINGS
AX_CXX17_STD_OPTIONAL
if test x"$missing_cxx_features" != x ; then
printf "The following features of the C++11/C++14 standards are not supported by $CXX:$missing_cxx_features\n"
printf "The following features of the C++11/C++14/C++17 standards are not supported by $CXX:$missing_cxx_features\n"
printf "If you are using the GNU C compiler collection (gcc), you need\n"
printf "at least v5.x; for clang the 3.4 and newer should work.\n"
AC_MSG_ERROR([support for required C++11/C++14 features incomplete])
printf "at least v7; for clang v4 and newer should work.\n"
AC_MSG_ERROR([support for required C++11/C++14/C++17 features incomplete])
fi
......@@ -82,13 +82,13 @@ parse_codec_id(const std::string &codec_id,
return true;
}
boost::optional<audio_config_t>
std::optional<audio_config_t>
parse_audio_specific_config(unsigned char const *data,
std::size_t size) {
auto h = header_c::from_audio_specific_config(data, size);
if (h.is_valid)
return h.config;
return boost::none;
return std::nullopt;
}
memory_cptr
......
......@@ -59,7 +59,7 @@ struct audio_config_t {
unsigned int get_sampling_freq_idx(unsigned int sampling_freq);
bool parse_codec_id(const std::string &codec_id, int &id, int &profile);
boost::optional<audio_config_t> parse_audio_specific_config(unsigned char const *data, std::size_t size);
std::optional<audio_config_t> parse_audio_specific_config(unsigned char const *data, std::size_t size);
void copy_program_config_element(mtx::bits::reader_c &r, mtx::bits::writer_c &w);
memory_cptr create_audio_specific_config(audio_config_t const &audio_config);
......
......@@ -53,7 +53,7 @@ class frame_c {
public:
unsigned int m_sample_rate{}, m_bit_rate{}, m_channels{}, m_channel_layout{}, m_flags{}, m_bytes{}, m_bs_id{}, m_samples{}, m_frame_type{}, m_sub_stream_id{};
unsigned int m_dialog_normalization_gain{}, m_dialog_normalization_gain_bit_position{};
boost::optional<unsigned int> m_dialog_normalization_gain2, m_dialog_normalization_gain2_bit_position;
std::optional<unsigned int> m_dialog_normalization_gain2, m_dialog_normalization_gain2_bit_position;
uint64_t m_stream_position{}, m_garbage_size{};
bool m_valid{}, m_lfeon{};
memory_cptr m_data;
......
......@@ -35,7 +35,7 @@ class parser_private_c {
unsigned int obu_type{};
bool obu_extension_flag{}, obu_has_size_field{}, seen_frame_header{}, frame_id_numbers_present_flag{}, equal_picture_interval{}, high_bitdepth{}, twelve_bit{}, mono_chrome{}, seq_tier_0{};
bool chroma_subsampling_x{}, chroma_subsampling_y{}, current_frame_contains_sequence_header{};
boost::optional<unsigned int> temporal_id, spatial_id;
std::optional<unsigned int> temporal_id, spatial_id;
unsigned int operating_point_idc{}, seq_profile{}, seq_level_idx_0{}, max_frame_width{}, max_frame_height{}, buffer_delay_length{1}, chroma_sample_position{};
unsigned int color_primaries{}, transfer_characteristics{}, matrix_coefficients{};
......@@ -124,19 +124,19 @@ parser_c::read_uvlc(mtx::bits::reader_c &r) {
return value + (1llu << leading_zeros) - 1;
}
boost::optional<uint64_t>
std::optional<uint64_t>
parser_c::parse_obu_common_data(memory_c const &buffer) {
return parse_obu_common_data(buffer.get_buffer(), buffer.get_size());
}
boost::optional<uint64_t>
std::optional<uint64_t>
parser_c::parse_obu_common_data(unsigned char const *buffer,
uint64_t buffer_size) {
p->r.init(buffer, buffer_size);
return parse_obu_common_data();
}
boost::optional<uint64_t>
std::optional<uint64_t>
parser_c::parse_obu_common_data() {
auto &r = p->r;
......@@ -156,8 +156,8 @@ parser_c::parse_obu_common_data() {
r.skip_bits(3); // extension_header_reserved_3bits
} else {
p->temporal_id = boost::none;
p->spatial_id = boost::none;
p->temporal_id = std::nullopt;
p->spatial_id = std::nullopt;
}
if (p->obu_has_size_field)
......
......@@ -119,9 +119,9 @@ protected:
static uint64_t read_leb128(mtx::bits::reader_c &r);
static uint64_t read_uvlc(mtx::bits::reader_c &r);
boost::optional<uint64_t> parse_obu_common_data(unsigned char const *buffer, uint64_t buffer_size);
boost::optional<uint64_t> parse_obu_common_data(memory_c const &buffer);
boost::optional<uint64_t> parse_obu_common_data();
std::optional<uint64_t> parse_obu_common_data(unsigned char const *buffer, uint64_t buffer_size);
std::optional<uint64_t> parse_obu_common_data(memory_c const &buffer);
std::optional<uint64_t> parse_obu_common_data();
void parse_sequence_header_obu(mtx::bits::reader_c &r);
void parse_color_config(mtx::bits::reader_c &r);
void parse_timing_info(mtx::bits::reader_c &r);
......
......@@ -343,10 +343,10 @@ es_parser_c::handle_slice_nalu(memory_cptr const &nalu,
}
if (!si.field_pic_flag)
m_current_key_frame_bottom_field = boost::none;
m_current_key_frame_bottom_field = std::nullopt;
else if (m_current_key_frame_bottom_field && (*m_current_key_frame_bottom_field != si.bottom_field_flag))
m_current_key_frame_bottom_field = boost::none;
m_current_key_frame_bottom_field = std::nullopt;
else
m_current_key_frame_bottom_field = si.bottom_field_flag;
......
......@@ -82,7 +82,7 @@ protected:
int64_t m_stream_default_duration, m_forced_default_duration, m_container_default_duration;
int m_frame_number, m_num_skipped_frames;
bool m_first_keyframe_found, m_recovery_point_valid, m_b_frames_since_keyframe;
boost::optional<bool> m_current_key_frame_bottom_field;
std::optional<bool> m_current_key_frame_bottom_field;
bool m_par_found;
int64_rational_c m_par;
......
......@@ -25,7 +25,7 @@ namespace mtx::bluray::disc_library {
namespace {
debugging_option_c debug{"disc_library|bdmt"};
boost::optional<info_t>
std::optional<info_t>
parse_bdmt_xml(bfs::path const &file_name) {
try {
auto doc = mtx::xml::load_file(file_name.string());
......@@ -123,7 +123,7 @@ disc_library_t::dump()
// ------------------------------------------------------------
boost::optional<disc_library_t>
std::optional<disc_library_t>
locate_and_parse(bfs::path const &location) {
auto base_dir = mtx::bluray::find_base_dir(location);
if (base_dir.empty())
......@@ -159,7 +159,7 @@ locate_and_parse(bfs::path const &location) {
return lib;
}
boost::optional<info_t>
std::optional<info_t>
locate_and_parse_for_language(bfs::path const &location,
std::string const &language) {
auto base_dir = mtx::bluray::find_base_dir(location);
......
......@@ -35,7 +35,7 @@ struct disc_library_t {
void dump() const;
};
boost::optional<disc_library_t> locate_and_parse(bfs::path const &location);
boost::optional<info_t> locate_and_parse_for_language(bfs::path const &location, std::string const &language);
std::optional<disc_library_t> locate_and_parse(bfs::path const &location);
std::optional<info_t> locate_and_parse_for_language(bfs::path const &location, std::string const &language);
} // namespace mtx::bluray::disc_library
......@@ -70,7 +70,7 @@ extern translatable_string_c g_chapter_generation_name_template;
bool probe_cue(mm_text_io_c *in);
mtx::chapters::kax_cptr parse_cue(mm_text_io_c *in, int64_t min_ts, int64_t max_ts, int64_t offset, const std::string &language, const std::string &charset, std::unique_ptr<libmatroska::KaxTags> *tags = nullptr);
std::size_t write_simple(libmatroska::KaxChapters &chapters, mm_io_c &out, boost::optional<std::string> const &language_to_extract);
std::size_t write_simple(libmatroska::KaxChapters &chapters, mm_io_c &out, std::optional<std::string> const &language_to_extract);
bool select_in_timeframe(libmatroska::KaxChapters *chapters, int64_t min_ts, int64_t max_ts, int64_t offset);
......
......@@ -30,7 +30,7 @@ using chapter_entry_storage_c = std::vector<chapter_entry_c>;
static void
handle_atom(KaxChapterAtom const &atom,
chapter_entry_storage_c &chapter_entries,
boost::optional<std::string> const &language_to_extract) {
std::optional<std::string> const &language_to_extract) {
if (FindChildValue<KaxChapterFlagHidden>(atom) != 0)
return;
......@@ -62,7 +62,7 @@ handle_atom(KaxChapterAtom const &atom,
std::size_t
write_simple(KaxChapters &chapters,
mm_io_c &out,
boost::optional<std::string> const &language_to_extract) {
std::optional<std::string> const &language_to_extract) {
auto chapter_entries = chapter_entry_storage_c{};
for (auto const &chapters_child : chapters) {
......
......@@ -23,6 +23,7 @@
#include <algorithm>
#include <functional>
#include <memory>
#include <optional>
#include <stdexcept>
#include <string>
#include <vector>
......@@ -51,7 +52,6 @@
#include <boost/filesystem.hpp>
#include <boost/function.hpp>
#include <boost/logic/tribool.hpp>
#include <boost/optional.hpp>
#include <boost/range.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/indexed.hpp>
......
......@@ -142,14 +142,14 @@ debugging_c::hexdump(const void *buffer_to_dump,
void
debugging_c::hexdump(memory_cptr const &buffer_to_dump,
boost::optional<std::size_t> max_length) {
std::optional<std::size_t> max_length) {
if (buffer_to_dump)
hexdump(*buffer_to_dump, max_length);
}
void
debugging_c::hexdump(memory_c const &buffer_to_dump,
boost::optional<std::size_t> max_length) {
std::optional<std::size_t> max_length) {
auto length = std::min<std::size_t>(max_length ? *max_length : buffer_to_dump.get_size(), buffer_to_dump.get_size());
hexdump(buffer_to_dump.get_buffer(), length);
......
......@@ -31,8 +31,8 @@ public:
static void output(std::string const &msg);
static void hexdump(const void *buffer_to_dump, size_t lenth);
static void hexdump(memory_c const &buffer_to_dump, boost::optional<std::size_t> max_length = boost::none);
static void hexdump(memory_cptr const &buffer_to_dump, boost::optional<std::size_t> max_length = boost::none);
static void hexdump(memory_c const &buffer_to_dump, std::optional<std::size_t> max_length = std::nullopt);
static void hexdump(memory_cptr const &buffer_to_dump, std::optional<std::size_t> max_length = std::nullopt);
static bool requested(const char *option, std::string *arg = nullptr);
static bool requested(const std::string &option, std::string *arg = nullptr) {
......
......@@ -608,7 +608,7 @@ header_t::decode_xll_header(mtx::bits::reader_c &bc,
if (!has_core)
core_sampling_frequency = substream_assets[0].max_sample_rate;
else
extension_sampling_frequency.reset(substream_assets[0].max_sample_rate);
extension_sampling_frequency = substream_assets[0].max_sample_rate;
}
return true;
......
......@@ -130,7 +130,7 @@ struct header_t {
// -1 for "invalid"
unsigned int core_sampling_frequency{};
boost::optional<unsigned int> extension_sampling_frequency;
std::optional<unsigned int> extension_sampling_frequency;
// in bit per second, or -1 == "open", -2 == "variable", -3 == "lossless"
int transmission_bitrate{};
......@@ -192,7 +192,7 @@ struct header_t {
int dialog_normalization_gain{}, extension_dialog_normalization_gain{};
unsigned int dialog_normalization_gain_bit_position{}, extension_dialog_normalization_gain_bit_position{};
boost::optional<unsigned int> crc{};
std::optional<unsigned int> crc{};
bool has_core{}, has_exss{};
unsigned int exss_offset{}, exss_header_size{}, exss_part_size{};
......
......@@ -371,17 +371,17 @@ FindChildValue(libebml::EbmlMaster const *master,
template<typename Telement,
typename Tvalue = decltype(Telement().GetValue())>
boost::optional<Tvalue>
std::optional<Tvalue>
FindOptionalChildValue(libebml::EbmlMaster const &master) {
auto child = FindChild<Telement>(master);
if (child)
return static_cast<Tvalue>(child->GetValue());
return boost::none;
return std::nullopt;
}
template<typename Telement,
typename Tvalue = decltype(Telement().GetValue())>
boost::optional<Tvalue>
std::optional<Tvalue>
FindOptionalChildValue(libebml::EbmlMaster const *master) {
return FindOptionalChildValue<Telement>(*master);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment