Skip to content

Commit

Permalink
Replace rtc::Optional with absl::optional in rtc_base
Browse files Browse the repository at this point in the history
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 <[email protected]>
Commit-Queue: Danil Chapovalov <[email protected]>
Cr-Commit-Position: refs/heads/master@{#23700}
  • Loading branch information
DanilChapovalov authored and Commit Bot committed Jun 21, 2018
1 parent c806c1d commit 0a1d189
Show file tree
Hide file tree
Showing 32 changed files with 170 additions and 171 deletions.
6 changes: 3 additions & 3 deletions p2p/base/fakepackettransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ class FakePacketTransport : public PacketTransportInternal {

const CopyOnWriteBuffer* last_sent_packet() { return &last_sent_packet_; }

Optional<NetworkRoute> network_route() const override {
absl::optional<NetworkRoute> network_route() const override {
return network_route_;
}
void SetNetworkRoute(Optional<NetworkRoute> network_route) {
void SetNetworkRoute(absl::optional<NetworkRoute> network_route) {
network_route_ = network_route;
}

Expand Down Expand Up @@ -132,7 +132,7 @@ class FakePacketTransport : public PacketTransportInternal {
bool writable_ = false;
bool receiving_ = false;

Optional<NetworkRoute> network_route_;
absl::optional<NetworkRoute> network_route_;
};

} // namespace rtc
Expand Down
8 changes: 4 additions & 4 deletions rtc_base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ rtc_source_set("rtc_base_approved_generic") {
deps += [
"..:webrtc_common",
"../api:array_view",
"../api:optional",
"//third_party/abseil-cpp/absl/types:optional",
]

if (is_android) {
Expand Down Expand Up @@ -661,7 +661,7 @@ rtc_static_library("rtc_numerics") {
":checks",
":rtc_base_approved",
":safe_compare",
"../api:optional",
"//third_party/abseil-cpp/absl/types:optional",
]
}

Expand Down Expand Up @@ -728,7 +728,7 @@ rtc_static_library("rtc_base_generic") {
":stringutils",
"..:webrtc_common",
"../api:array_view",
"../api:optional",
"//third_party/abseil-cpp/absl/types:optional",
]
public_deps = [
":rtc_base_approved",
Expand Down Expand Up @@ -1304,9 +1304,9 @@ if (rtc_include_tests) {
":rtc_base_tests_utils",
":stringutils",
"../api:array_view",
"../api:optional",
"../test:fileutils",
"../test:test_support",
"//third_party/abseil-cpp/absl/types:optional",
]
public_deps = [
":rtc_base",
Expand Down
8 changes: 4 additions & 4 deletions rtc_base/experiments/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ rtc_static_library("alr_experiment") {
]
deps = [
"../:rtc_base_approved",
"../../api:optional",
"../../system_wrappers:field_trial_api",
"//third_party/abseil-cpp/absl/types:optional",
]
}

Expand All @@ -29,11 +29,11 @@ rtc_static_library("field_trial_parser") {
]
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",
]
}

Expand All @@ -44,8 +44,8 @@ rtc_static_library("congestion_controller_experiment") {
]
deps = [
"../:rtc_base_approved",
"../../api:optional",
"../../system_wrappers:field_trial_api",
"//third_party/abseil-cpp/absl/types:optional",
]
}

Expand All @@ -57,9 +57,9 @@ rtc_static_library("quality_scaling_experiment") {
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",
]
}

Expand Down
4 changes: 2 additions & 2 deletions rtc_base/experiments/alr_experiment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ bool AlrExperimentSettings::MaxOneFieldTrialEnabled() {
.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";
Expand Down
4 changes: 2 additions & 2 deletions rtc_base/experiments/alr_experiment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -28,7 +28,7 @@ struct AlrExperimentSettings {

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();

Expand Down
6 changes: 3 additions & 3 deletions rtc_base/experiments/congestion_controller_experiment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ bool CongestionControllerExperiment::InjectedControllerEnabled() {
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;
Expand All @@ -56,7 +56,7 @@ CongestionControllerExperiment::GetBbrExperimentConfig() {
&config.probe_rtt_congestion_window_gain) == 17) {
return config;
} else {
return rtc::nullopt;
return absl::nullopt;
}
}

Expand Down
2 changes: 1 addition & 1 deletion rtc_base/experiments/congestion_controller_experiment.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CongestionControllerExperiment {
};
static bool BbrControllerEnabled();
static bool InjectedControllerEnabled();
static rtc::Optional<BbrExperimentConfig> GetBbrExperimentConfig();
static absl::optional<BbrExperimentConfig> GetBbrExperimentConfig();
};

} // namespace webrtc
Expand Down
20 changes: 10 additions & 10 deletions rtc_base/experiments/field_trial_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void ParseFieldTrial(
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;
Expand All @@ -65,37 +65,37 @@ void ParseFieldTrial(
}

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);
}

Expand All @@ -108,10 +108,10 @@ bool FieldTrialFlag::Get() const {
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;
Expand Down
28 changes: 14 additions & 14 deletions rtc_base/experiments/field_trial_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,7 +39,7 @@ class FieldTrialParameterInterface {
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:
Expand All @@ -52,10 +52,10 @@ void ParseFieldTrial(
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.
Expand All @@ -68,9 +68,9 @@ class FieldTrialParameter : public FieldTrialParameterInterface {
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;
Expand All @@ -84,31 +84,31 @@ class FieldTrialParameter : public FieldTrialParameterInterface {
};

// 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
Expand All @@ -121,7 +121,7 @@ class FieldTrialFlag : public FieldTrialParameterInterface {
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_;
Expand Down
6 changes: 3 additions & 3 deletions rtc_base/experiments/field_trial_parser_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ enum class CustomEnum {
// 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) {
Expand Down Expand Up @@ -104,7 +104,7 @@ TEST(FieldTrialParserTest, IgnoresInvalid) {
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");
Expand Down
Loading

0 comments on commit 0a1d189

Please sign in to comment.