Replace rtc::Optional with absl::optional in rtc_base
This is a no-op change because rtc::Optional is an alias to absl::optional
This CL generated by running script with parameter 'rtc_base'
Then manually fix where Optional was used without rtc prefix (patchset#3)
find $@ -type f \( -name \*.h -o -name \*.cc \) \
-exec sed -i 's|rtc::Optional|absl::optional|g' {} \+ \
-exec sed -i 's|rtc::nullopt|absl::nullopt|g' {} \+ \
-exec sed -i 's|#include "api/optional.h"|#include "absl/types/optional.h"|' {} \+
find $@ -type f -name BUILD.gn \
-exec sed -r -i 's|"[\./api]*:optional"|"//third_party/abseil-cpp/absl/types:optional"|' {} \+;
git cl format
Bug: webrtc:9078
Change-Id: I825f80cc8089747876ba6316d9e7c30e05716974
Reviewed-on: https://webrtc-review.googlesource.com/84585
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23700}
diff --git a/rtc_base/experiments/BUILD.gn b/rtc_base/experiments/BUILD.gn
index 8b2b062..a95e258 100644
--- a/rtc_base/experiments/BUILD.gn
+++ b/rtc_base/experiments/BUILD.gn
@@ -15,8 +15,8 @@
]
deps = [
"../:rtc_base_approved",
- "../../api:optional",
"../../system_wrappers:field_trial_api",
+ "//third_party/abseil-cpp/absl/types:optional",
]
}
@@ -29,11 +29,11 @@
]
deps = [
"../:rtc_base_approved",
- "../../api:optional",
"../../api/units:data_rate",
"../../api/units:data_size",
"../../api/units:time_delta",
"../../system_wrappers:field_trial_api",
+ "//third_party/abseil-cpp/absl/types:optional",
]
}
@@ -44,8 +44,8 @@
]
deps = [
"../:rtc_base_approved",
- "../../api:optional",
"../../system_wrappers:field_trial_api",
+ "//third_party/abseil-cpp/absl/types:optional",
]
}
@@ -57,9 +57,9 @@
deps = [
"../:rtc_base_approved",
"../..:webrtc_common",
- "../../api:optional",
"../../api/video_codecs:video_codecs_api",
"../../system_wrappers:field_trial_api",
+ "//third_party/abseil-cpp/absl/types:optional",
]
}
diff --git a/rtc_base/experiments/alr_experiment.cc b/rtc_base/experiments/alr_experiment.cc
index c69caed..dff5ace 100644
--- a/rtc_base/experiments/alr_experiment.cc
+++ b/rtc_base/experiments/alr_experiment.cc
@@ -31,9 +31,9 @@
.empty();
}
-rtc::Optional<AlrExperimentSettings>
+absl::optional<AlrExperimentSettings>
AlrExperimentSettings::CreateFromFieldTrial(const char* experiment_name) {
- rtc::Optional<AlrExperimentSettings> ret;
+ absl::optional<AlrExperimentSettings> ret;
std::string group_name = field_trial::FindFullName(experiment_name);
const std::string kIgnoredSuffix = "_Dogfood";
diff --git a/rtc_base/experiments/alr_experiment.h b/rtc_base/experiments/alr_experiment.h
index a9c483d..4d9fd00 100644
--- a/rtc_base/experiments/alr_experiment.h
+++ b/rtc_base/experiments/alr_experiment.h
@@ -11,7 +11,7 @@
#ifndef RTC_BASE_EXPERIMENTS_ALR_EXPERIMENT_H_
#define RTC_BASE_EXPERIMENTS_ALR_EXPERIMENT_H_
-#include "api/optional.h"
+#include "absl/types/optional.h"
namespace webrtc {
struct AlrExperimentSettings {
@@ -28,7 +28,7 @@
static const char kScreenshareProbingBweExperimentName[];
static const char kStrictPacingAndProbingExperimentName[];
- static rtc::Optional<AlrExperimentSettings> CreateFromFieldTrial(
+ static absl::optional<AlrExperimentSettings> CreateFromFieldTrial(
const char* experiment_name);
static bool MaxOneFieldTrialEnabled();
diff --git a/rtc_base/experiments/congestion_controller_experiment.cc b/rtc_base/experiments/congestion_controller_experiment.cc
index 9fdaacd..b05ef71 100644
--- a/rtc_base/experiments/congestion_controller_experiment.cc
+++ b/rtc_base/experiments/congestion_controller_experiment.cc
@@ -31,10 +31,10 @@
return trial_string.find("Enabled,Injected") == 0;
}
-rtc::Optional<CongestionControllerExperiment::BbrExperimentConfig>
+absl::optional<CongestionControllerExperiment::BbrExperimentConfig>
CongestionControllerExperiment::GetBbrExperimentConfig() {
if (!BbrControllerEnabled())
- return rtc::nullopt;
+ return absl::nullopt;
std::string trial_string =
webrtc::field_trial::FindFullName(kControllerExperiment);
BbrExperimentConfig config;
@@ -56,7 +56,7 @@
&config.probe_rtt_congestion_window_gain) == 17) {
return config;
} else {
- return rtc::nullopt;
+ return absl::nullopt;
}
}
diff --git a/rtc_base/experiments/congestion_controller_experiment.h b/rtc_base/experiments/congestion_controller_experiment.h
index eba8926..5428a4f 100644
--- a/rtc_base/experiments/congestion_controller_experiment.h
+++ b/rtc_base/experiments/congestion_controller_experiment.h
@@ -34,7 +34,7 @@
};
static bool BbrControllerEnabled();
static bool InjectedControllerEnabled();
- static rtc::Optional<BbrExperimentConfig> GetBbrExperimentConfig();
+ static absl::optional<BbrExperimentConfig> GetBbrExperimentConfig();
};
} // namespace webrtc
diff --git a/rtc_base/experiments/field_trial_parser.cc b/rtc_base/experiments/field_trial_parser.cc
index d2a3add..4ea603f 100644
--- a/rtc_base/experiments/field_trial_parser.cc
+++ b/rtc_base/experiments/field_trial_parser.cc
@@ -47,7 +47,7 @@
int key_end = std::min(val_end, colon_pos);
int val_begin = key_end + 1;
std::string key = trial_string.substr(i, key_end - i);
- rtc::Optional<std::string> opt_value;
+ absl::optional<std::string> opt_value;
if (val_end >= val_begin)
opt_value = trial_string.substr(val_begin, val_end - val_begin);
i = val_end + 1;
@@ -65,37 +65,37 @@
}
template <>
-rtc::Optional<bool> ParseTypedParameter<bool>(std::string str) {
+absl::optional<bool> ParseTypedParameter<bool>(std::string str) {
if (str == "true" || str == "1") {
return true;
} else if (str == "false" || str == "0") {
return false;
}
- return rtc::nullopt;
+ return absl::nullopt;
}
template <>
-rtc::Optional<double> ParseTypedParameter<double>(std::string str) {
+absl::optional<double> ParseTypedParameter<double>(std::string str) {
double value;
if (sscanf(str.c_str(), "%lf", &value) == 1) {
return value;
} else {
- return rtc::nullopt;
+ return absl::nullopt;
}
}
template <>
-rtc::Optional<int> ParseTypedParameter<int>(std::string str) {
+absl::optional<int> ParseTypedParameter<int>(std::string str) {
int value;
if (sscanf(str.c_str(), "%i", &value) == 1) {
return value;
} else {
- return rtc::nullopt;
+ return absl::nullopt;
}
}
template <>
-rtc::Optional<std::string> ParseTypedParameter<std::string>(std::string str) {
+absl::optional<std::string> ParseTypedParameter<std::string>(std::string str) {
return std::move(str);
}
@@ -108,10 +108,10 @@
return value_;
}
-bool FieldTrialFlag::Parse(rtc::Optional<std::string> str_value) {
+bool FieldTrialFlag::Parse(absl::optional<std::string> str_value) {
// Only set the flag if there is no argument provided.
if (str_value) {
- rtc::Optional<bool> opt_value = ParseTypedParameter<bool>(*str_value);
+ absl::optional<bool> opt_value = ParseTypedParameter<bool>(*str_value);
if (!opt_value)
return false;
value_ = *opt_value;
diff --git a/rtc_base/experiments/field_trial_parser.h b/rtc_base/experiments/field_trial_parser.h
index ba60499..ff00b90 100644
--- a/rtc_base/experiments/field_trial_parser.h
+++ b/rtc_base/experiments/field_trial_parser.h
@@ -13,7 +13,7 @@
#include <stdint.h>
#include <initializer_list>
#include <string>
-#include "api/optional.h"
+#include "absl/types/optional.h"
// Field trial parser functionality. Provides funcitonality to parse field trial
// argument strings in key:value format. Each parameter is described using
@@ -39,7 +39,7 @@
friend void ParseFieldTrial(
std::initializer_list<FieldTrialParameterInterface*> fields,
std::string raw_string);
- virtual bool Parse(rtc::Optional<std::string> str_value) = 0;
+ virtual bool Parse(absl::optional<std::string> str_value) = 0;
std::string Key() const;
private:
@@ -52,10 +52,10 @@
std::initializer_list<FieldTrialParameterInterface*> fields,
std::string raw_string);
-// Specialize this in code file for custom types. Should return rtc::nullopt if
+// Specialize this in code file for custom types. Should return absl::nullopt if
// the given string cannot be properly parsed.
template <typename T>
-rtc::Optional<T> ParseTypedParameter(std::string);
+absl::optional<T> ParseTypedParameter(std::string);
// This class uses the ParseTypedParameter function to implement a parameter
// implementation with an enforced default value.
@@ -68,9 +68,9 @@
operator T() const { return Get(); }
protected:
- bool Parse(rtc::Optional<std::string> str_value) override {
+ bool Parse(absl::optional<std::string> str_value) override {
if (str_value) {
- rtc::Optional<T> value = ParseTypedParameter<T>(*str_value);
+ absl::optional<T> value = ParseTypedParameter<T>(*str_value);
if (value.has_value()) {
value_ = value.value();
return true;
@@ -84,31 +84,31 @@
};
// This class uses the ParseTypedParameter function to implement an optional
-// parameter implementation that can default to rtc::nullopt.
+// parameter implementation that can default to absl::nullopt.
template <typename T>
class FieldTrialOptional : public FieldTrialParameterInterface {
public:
explicit FieldTrialOptional(std::string key)
: FieldTrialParameterInterface(key) {}
- FieldTrialOptional(std::string key, rtc::Optional<T> default_value)
+ FieldTrialOptional(std::string key, absl::optional<T> default_value)
: FieldTrialParameterInterface(key), value_(default_value) {}
- rtc::Optional<T> Get() const { return value_; }
+ absl::optional<T> Get() const { return value_; }
protected:
- bool Parse(rtc::Optional<std::string> str_value) override {
+ bool Parse(absl::optional<std::string> str_value) override {
if (str_value) {
- rtc::Optional<T> value = ParseTypedParameter<T>(*str_value);
+ absl::optional<T> value = ParseTypedParameter<T>(*str_value);
if (!value.has_value())
return false;
value_ = value.value();
} else {
- value_ = rtc::nullopt;
+ value_ = absl::nullopt;
}
return true;
}
private:
- rtc::Optional<T> value_;
+ absl::optional<T> value_;
};
// Equivalent to a FieldTrialParameter<bool> in the case that both key and value
@@ -121,7 +121,7 @@
bool Get() const;
protected:
- bool Parse(rtc::Optional<std::string> str_value) override;
+ bool Parse(absl::optional<std::string> str_value) override;
private:
bool value_;
diff --git a/rtc_base/experiments/field_trial_parser_unittest.cc b/rtc_base/experiments/field_trial_parser_unittest.cc
index 6c343fc..73bddfd 100644
--- a/rtc_base/experiments/field_trial_parser_unittest.cc
+++ b/rtc_base/experiments/field_trial_parser_unittest.cc
@@ -43,14 +43,14 @@
// Providing a custom parser for an enum can make the trial string easier to
// read, but also adds more code and makes the string more verbose.
template <>
-rtc::Optional<CustomEnum> ParseTypedParameter<CustomEnum>(std::string str) {
+absl::optional<CustomEnum> ParseTypedParameter<CustomEnum>(std::string str) {
if (str == "default")
return CustomEnum::kDefault;
else if (str == "red")
return CustomEnum::kRed;
else if (str == "blue")
return CustomEnum::kBlue;
- return rtc::nullopt;
+ return absl::nullopt;
}
TEST(FieldTrialParserTest, ParsesValidParameters) {
@@ -104,7 +104,7 @@
EXPECT_EQ(exp.hash.Get(), "a80");
}
TEST(FieldTrialParserTest, ParsesOptionalParameters) {
- FieldTrialOptional<int> max_count("c", rtc::nullopt);
+ FieldTrialOptional<int> max_count("c", absl::nullopt);
ParseFieldTrial({&max_count}, "");
EXPECT_FALSE(max_count.Get().has_value());
ParseFieldTrial({&max_count}, "c:10");
diff --git a/rtc_base/experiments/field_trial_units.cc b/rtc_base/experiments/field_trial_units.cc
index 94af4a7..f53978b 100644
--- a/rtc_base/experiments/field_trial_units.cc
+++ b/rtc_base/experiments/field_trial_units.cc
@@ -12,7 +12,7 @@
#include <limits>
#include <string>
-#include "api/optional.h"
+#include "absl/types/optional.h"
// Large enough to fit "seconds", the longest supported unit name.
#define RTC_TRIAL_UNIT_LENGTH_STR "7"
@@ -26,7 +26,7 @@
std::string unit;
};
-rtc::Optional<ValueWithUnit> ParseValueWithUnit(std::string str) {
+absl::optional<ValueWithUnit> ParseValueWithUnit(std::string str) {
if (str == "inf") {
return ValueWithUnit{std::numeric_limits<double>::infinity(), ""};
} else if (str == "-inf") {
@@ -40,13 +40,13 @@
return ValueWithUnit{double_val, unit_char};
}
}
- return rtc::nullopt;
+ return absl::nullopt;
}
} // namespace
template <>
-rtc::Optional<DataRate> ParseTypedParameter<DataRate>(std::string str) {
- rtc::Optional<ValueWithUnit> result = ParseValueWithUnit(str);
+absl::optional<DataRate> ParseTypedParameter<DataRate>(std::string str) {
+ absl::optional<ValueWithUnit> result = ParseValueWithUnit(str);
if (result) {
if (result->unit.empty() || result->unit == "kbps") {
return DataRate::kbps(result->value);
@@ -54,22 +54,22 @@
return DataRate::bps(result->value);
}
}
- return rtc::nullopt;
+ return absl::nullopt;
}
template <>
-rtc::Optional<DataSize> ParseTypedParameter<DataSize>(std::string str) {
- rtc::Optional<ValueWithUnit> result = ParseValueWithUnit(str);
+absl::optional<DataSize> ParseTypedParameter<DataSize>(std::string str) {
+ absl::optional<ValueWithUnit> result = ParseValueWithUnit(str);
if (result) {
if (result->unit.empty() || result->unit == "bytes")
return DataSize::bytes(result->value);
}
- return rtc::nullopt;
+ return absl::nullopt;
}
template <>
-rtc::Optional<TimeDelta> ParseTypedParameter<TimeDelta>(std::string str) {
- rtc::Optional<ValueWithUnit> result = ParseValueWithUnit(str);
+absl::optional<TimeDelta> ParseTypedParameter<TimeDelta>(std::string str) {
+ absl::optional<ValueWithUnit> result = ParseValueWithUnit(str);
if (result) {
if (result->unit == "s" || result->unit == "seconds") {
return TimeDelta::seconds(result->value);
@@ -79,7 +79,7 @@
return TimeDelta::ms(result->value);
}
}
- return rtc::nullopt;
+ return absl::nullopt;
}
template class FieldTrialParameter<DataRate>;
diff --git a/rtc_base/experiments/field_trial_units_unittest.cc b/rtc_base/experiments/field_trial_units_unittest.cc
index da76f5a..1a2b75d 100644
--- a/rtc_base/experiments/field_trial_units_unittest.cc
+++ b/rtc_base/experiments/field_trial_units_unittest.cc
@@ -21,7 +21,7 @@
FieldTrialParameter<TimeDelta> period =
FieldTrialParameter<TimeDelta>("p", TimeDelta::ms(100));
FieldTrialOptional<DataSize> max_buffer =
- FieldTrialOptional<DataSize>("b", rtc::nullopt);
+ FieldTrialOptional<DataSize>("b", absl::nullopt);
explicit DummyExperiment(std::string field_trial) {
ParseFieldTrial({&target_rate, &max_buffer, &period}, field_trial);
diff --git a/rtc_base/experiments/quality_scaling_experiment.cc b/rtc_base/experiments/quality_scaling_experiment.cc
index 8c99954..c13de3f 100644
--- a/rtc_base/experiments/quality_scaling_experiment.cc
+++ b/rtc_base/experiments/quality_scaling_experiment.cc
@@ -23,14 +23,14 @@
constexpr int kMaxH264Qp = 51;
constexpr int kMaxGenericQp = 255;
-rtc::Optional<VideoEncoder::QpThresholds> GetThresholds(int low,
- int high,
- int max) {
+absl::optional<VideoEncoder::QpThresholds> GetThresholds(int low,
+ int high,
+ int max) {
if (low < kMinQp || high > max || high < low)
- return rtc::nullopt;
+ return absl::nullopt;
RTC_LOG(LS_INFO) << "QP thresholds: low: " << low << ", high: " << high;
- return rtc::Optional<VideoEncoder::QpThresholds>(
+ return absl::optional<VideoEncoder::QpThresholds>(
VideoEncoder::QpThresholds(low, high));
}
} // namespace
@@ -39,11 +39,11 @@
return webrtc::field_trial::IsEnabled(kFieldTrial);
}
-rtc::Optional<QualityScalingExperiment::Settings>
+absl::optional<QualityScalingExperiment::Settings>
QualityScalingExperiment::ParseSettings() {
const std::string group = webrtc::field_trial::FindFullName(kFieldTrial);
if (group.empty())
- return rtc::nullopt;
+ return absl::nullopt;
Settings s;
if (sscanf(group.c_str(), "Enabled-%d,%d,%d,%d,%d,%d,%d,%d,%f,%f,%d",
@@ -51,16 +51,16 @@
&s.h264_high, &s.generic_low, &s.generic_high, &s.alpha_high,
&s.alpha_low, &s.drop) != 11) {
RTC_LOG(LS_WARNING) << "Invalid number of parameters provided.";
- return rtc::nullopt;
+ return absl::nullopt;
}
return s;
}
-rtc::Optional<VideoEncoder::QpThresholds>
+absl::optional<VideoEncoder::QpThresholds>
QualityScalingExperiment::GetQpThresholds(VideoCodecType codec_type) {
const auto settings = ParseSettings();
if (!settings)
- return rtc::nullopt;
+ return absl::nullopt;
switch (codec_type) {
case kVideoCodecVP8:
@@ -73,7 +73,7 @@
return GetThresholds(settings->generic_low, settings->generic_high,
kMaxGenericQp);
default:
- return rtc::nullopt;
+ return absl::nullopt;
}
}
diff --git a/rtc_base/experiments/quality_scaling_experiment.h b/rtc_base/experiments/quality_scaling_experiment.h
index 6f24d6b..80a25ef 100644
--- a/rtc_base/experiments/quality_scaling_experiment.h
+++ b/rtc_base/experiments/quality_scaling_experiment.h
@@ -10,7 +10,7 @@
#ifndef RTC_BASE_EXPERIMENTS_QUALITY_SCALING_EXPERIMENT_H_
#define RTC_BASE_EXPERIMENTS_QUALITY_SCALING_EXPERIMENT_H_
-#include "api/optional.h"
+#include "absl/types/optional.h"
#include "api/video_codecs/video_encoder.h"
#include "common_types.h" // NOLINT(build/include)
@@ -44,10 +44,10 @@
static bool Enabled();
// Returns settings from field trial.
- static rtc::Optional<Settings> ParseSettings();
+ static absl::optional<Settings> ParseSettings();
// Returns QpThresholds for the |codec_type|.
- static rtc::Optional<VideoEncoder::QpThresholds> GetQpThresholds(
+ static absl::optional<VideoEncoder::QpThresholds> GetQpThresholds(
VideoCodecType codec_type);
// Returns parsed values. If the parsing fails, default values are returned.