Skip to content

Commit 33e1d45

Browse files
committed
use Abseil's optional in Bazel builds, for Envoy.
1 parent c7ce2be commit 33e1d45

34 files changed

+156
-125
lines changed

BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ cc_library(
2424
"src/datadog/msgpack.cpp",
2525
"src/datadog/net_util.cpp",
2626
"src/datadog/null_collector.cpp",
27+
"src/datadog/optional.cpp",
2728
"src/datadog/parse_util.cpp",
2829
"src/datadog/propagation_styles.cpp",
2930
"src/datadog/rate.cpp",
@@ -74,6 +75,7 @@ cc_library(
7475
"src/datadog/msgpack.h",
7576
"src/datadog/net_util.h",
7677
"src/datadog/null_collector.h",
78+
"src/datadog/optional.h",
7779
"src/datadog/parse_util.h",
7880
"src/datadog/propagation_styles.h",
7981
"src/datadog/rate.h",
@@ -111,5 +113,6 @@ cc_library(
111113
visibility = ["//visibility:public"],
112114
deps = [
113115
"@com_google_absl//absl/strings",
116+
"@com_google_absl//absl/types:optional",
114117
],
115118
)

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ target_sources(dd_trace_cpp PRIVATE
7676
src/datadog/msgpack.cpp
7777
src/datadog/net_util.cpp
7878
src/datadog/null_collector.cpp
79+
src/datadog/optional.cpp
7980
src/datadog/parse_util.cpp
8081
src/datadog/propagation_styles.cpp
8182
src/datadog/rate.cpp
@@ -132,6 +133,7 @@ target_sources(dd_trace_cpp PUBLIC
132133
src/datadog/msgpack.h
133134
src/datadog/net_util.h
134135
src/datadog/null_collector.h
136+
src/datadog/optional.h
135137
src/datadog/parse_util.h
136138
src/datadog/propagation_styles.h
137139
src/datadog/rate.h

src/datadog/collector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// `response_handler` parameter to `Collector::send`.
1212

1313
#include <memory>
14-
#include <optional>
14+
#include "optional.h"
1515
#include <vector>
1616

1717
#include "expected.h"

src/datadog/curl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class CurlImpl {
7171
public:
7272
explicit HeaderReader(
7373
std::unordered_map<std::string, std::string> *response_headers_lower);
74-
std::optional<StringView> lookup(StringView key) const override;
74+
Optional<StringView> lookup(StringView key) const override;
7575
void visit(const std::function<void(StringView key, StringView value)>
7676
&visitor) const override;
7777
};
@@ -438,7 +438,7 @@ CurlImpl::HeaderReader::HeaderReader(
438438
std::unordered_map<std::string, std::string> *response_headers_lower)
439439
: response_headers_lower_(response_headers_lower) {}
440440

441-
std::optional<StringView> CurlImpl::HeaderReader::lookup(StringView key) const {
441+
Optional<StringView> CurlImpl::HeaderReader::lookup(StringView key) const {
442442
buffer_.clear();
443443
std::transform(key.begin(), key.end(), std::back_inserter(buffer_),
444444
&to_lower);

src/datadog/dict_reader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// context from externalized formats: HTTP headers, gRPC metadata, etc.
66

77
#include <functional>
8-
#include <optional>
8+
#include "optional.h"
99

1010
#include "string_view.h"
1111

@@ -18,7 +18,7 @@ class DictReader {
1818

1919
// Return the value at the specified `key`, or return `std::nullopt` if there
2020
// is no value at `key`.
21-
virtual std::optional<StringView> lookup(StringView key) const = 0;
21+
virtual Optional<StringView> lookup(StringView key) const = 0;
2222

2323
// Invoke the specified `visitor` once for each key/value pair in this object.
2424
virtual void visit(

src/datadog/environment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace environment {
1010

1111
StringView name(Variable variable) { return variable_names[variable]; }
1212

13-
std::optional<StringView> lookup(Variable variable) {
13+
Optional<StringView> lookup(Variable variable) {
1414
const char *name = variable_names[variable];
1515
const char *value = std::getenv(name);
1616
if (!value) {

src/datadog/environment.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//
1515
// `lookup` retrieves the value of `Variable` in the environment.
1616

17-
#include <optional>
17+
#include "optional.h"
1818

1919
#include "json_fwd.hpp"
2020
#include "string_view.h"
@@ -70,7 +70,7 @@ StringView name(Variable variable);
7070

7171
// Return the value of the specified environment `variable`, or return
7272
// `std::nullptr` if that variable is not set in the environment.
73-
std::optional<StringView> lookup(Variable variable);
73+
Optional<StringView> lookup(Variable variable);
7474

7575
nlohmann::json to_json();
7676

src/datadog/expected.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
//
3636
// `Expected<void>` is like `Expected<T>`, except that if the value is not an
3737
// error then it cannot be "dereferenced" with `operator*`, i.e. it is analogous
38-
// to `std::optional<Error>` (and is implemented as such).
38+
// to `Optional<Error>` (and is implemented as such).
3939

40-
#include <optional>
40+
#include "optional.h"
4141
#include <variant>
4242

4343
#include "error.h"
@@ -189,7 +189,7 @@ const Error* Expected<Value>::if_error() const& {
189189

190190
template <>
191191
class Expected<void> {
192-
std::optional<Error> data_;
192+
Optional<Error> data_;
193193

194194
public:
195195
Expected() = default;

src/datadog/http_client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <chrono>
1212
#include <functional>
13-
#include <optional>
13+
#include "optional.h"
1414

1515
#include "error.h"
1616
#include "expected.h"

src/datadog/net_util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace datadog {
1010
namespace tracing {
1111

12-
std::optional<std::string> get_hostname() {
12+
Optional<std::string> get_hostname() {
1313
char buffer[256];
1414
if (::gethostname(buffer, sizeof buffer)) {
1515
return std::nullopt;

0 commit comments

Comments
 (0)