Skip to content

Commit 7fca525

Browse files
committed
use return values instead of output parameters
1 parent d6f1328 commit 7fca525

32 files changed

+85
-114
lines changed

src/datadog/collector.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@ class Collector {
3333
std::vector<std::unique_ptr<SpanData>>&& spans,
3434
const std::shared_ptr<TraceSampler>& response_handler) = 0;
3535

36-
// Assign to the specified `destination` a JSON representation of this
37-
// object's configuration. The JSON representation is an object with
38-
// the following properties:
36+
// Return a JSON representation of this object's configuration. The JSON
37+
// representation is an object with the following properties:
3938
//
4039
// - "type" is the unmangled, qualified name of the most-derived class, e.g.
4140
// "datadog::tracing::DatadogAgent".
4241
// - "config" is an object containing this object's configuration. "config"
4342
// may be omitted if the derived class has no configuration.
44-
virtual void config_json(nlohmann::json& destination) const = 0;
43+
virtual nlohmann::json config_json() const = 0;
4544

4645
virtual ~Collector() {}
4746
};

src/datadog/curl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ void Curl::drain(std::chrono::steady_clock::time_point deadline) {
126126
impl_->drain(deadline);
127127
}
128128

129-
void Curl::config_json(nlohmann::json &destination) const {
130-
destination = nlohmann::json::object({{"type", "datadog::tracing::Curl"}});
129+
nlohmann::json Curl::config_json() const {
130+
return nlohmann::json::object({{"type", "datadog::tracing::Curl"}});
131131
}
132132

133133
CurlImpl::CurlImpl(const std::shared_ptr<Logger> &logger)

src/datadog/curl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Curl : public HTTPClient {
3737

3838
void drain(std::chrono::steady_clock::time_point deadline) override;
3939

40-
void config_json(nlohmann::json& destination) const override;
40+
nlohmann::json config_json() const override;
4141
};
4242

4343
} // namespace tracing

src/datadog/datadog_agent.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,23 +164,20 @@ Expected<void> DatadogAgent::send(
164164
return std::nullopt;
165165
}
166166

167-
void DatadogAgent::config_json(nlohmann::json& destination) const {
167+
nlohmann::json DatadogAgent::config_json() const {
168168
const auto& url = traces_endpoint_; // brevity
169169
const auto flush_interval_milliseconds =
170170
std::chrono::duration_cast<std::chrono::milliseconds>(flush_interval_)
171171
.count();
172-
nlohmann::json http_client_json, event_scheduler_json;
173-
http_client_->config_json(http_client_json);
174-
event_scheduler_->config_json(event_scheduler_json);
175172

176173
// clang-format off
177-
destination = nlohmann::json::object({
174+
return nlohmann::json::object({
178175
{"type", "datadog::tracing::DatadogAgent"},
179176
{"config", nlohmann::json::object({
180177
{"url", (url.scheme + "://" + url.authority + url.path)},
181178
{"flush_interval_milliseconds", flush_interval_milliseconds},
182-
{"http_client", http_client_json},
183-
{"event_scheduler", event_scheduler_json},
179+
{"http_client", http_client_->config_json()},
180+
{"event_scheduler", event_scheduler_->config_json()},
184181
})},
185182
});
186183
// clang-format on

src/datadog/datadog_agent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class DatadogAgent : public Collector {
5555
std::vector<std::unique_ptr<SpanData>>&& spans,
5656
const std::shared_ptr<TraceSampler>& response_handler) override;
5757

58-
void config_json(nlohmann::json& destination) const override;
58+
nlohmann::json config_json() const override;
5959
};
6060

6161
} // namespace tracing

src/datadog/environment.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ std::optional<std::string_view> lookup(Variable variable) {
1919
return std::string_view{value};
2020
}
2121

22-
void to_json(nlohmann::json &destination) {
23-
destination = nlohmann::json::object({});
22+
nlohmann::json to_json() {
23+
auto result = nlohmann::json::object({});
24+
2425
for (const char *name : variable_names) {
2526
if (const char *value = std::getenv(name)) {
26-
destination[name] = value;
27+
result[name] = value;
2728
}
2829
}
30+
31+
return result;
2932
}
3033

3134
} // namespace environment

src/datadog/environment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ std::string_view name(Variable variable);
7272
// `std::nullptr` if that variable is not set in the environment.
7373
std::optional<std::string_view> lookup(Variable variable);
7474

75-
void to_json(nlohmann::json& destination);
75+
nlohmann::json to_json();
7676

7777
} // namespace environment
7878
} // namespace tracing

src/datadog/event_scheduler.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@ class EventScheduler {
3030
std::chrono::steady_clock::duration interval,
3131
std::function<void()> callback) = 0;
3232

33-
// Assign to the specified `destination` a JSON representation of this
34-
// object's configuration. The JSON representation is an object with
35-
// the following properties:
33+
// Return a JSON representation of this object's configuration. The JSON
34+
// representation is an object with the following properties:
3635
//
3736
// - "type" is the unmangled, qualified name of the most-derived class, e.g.
3837
// "datadog::tracing::ThreadedEventScheduler".
3938
// - "config" is an object containing this object's configuration. "config"
4039
// may be omitted if the derived class has no configuration.
41-
virtual void config_json(nlohmann::json& destination) const = 0;
40+
virtual nlohmann::json config_json() const = 0;
4241

4342
virtual ~EventScheduler() = default;
4443
};

src/datadog/http_client.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,14 @@ class HTTPClient {
5252
// `deadline`.
5353
virtual void drain(std::chrono::steady_clock::time_point deadline) = 0;
5454

55-
// Assign to the specified `destination` a JSON representation of this
56-
// object's configuration. The JSON representation is an object with
57-
// the following properties:
55+
// Return a JSON representation of this object's configuration. The JSON
56+
// representation is an object with the following properties:
5857
//
5958
// - "type" is the unmangled, qualified name of the most-derived class, e.g.
6059
// "datadog::tracing::Curl".
6160
// - "config" is an object containing this object's configuration. "config"
6261
// may be omitted if the derived class has no configuration.
63-
virtual void config_json(nlohmann::json& destination) const = 0;
62+
virtual nlohmann::json config_json() const = 0;
6463

6564
virtual ~HTTPClient() = default;
6665
};

src/datadog/null_collector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace datadog {
66
namespace tracing {
77

8-
void NullCollector::config_json(nlohmann::json& destination) const {
8+
nlohmann::json NullCollector::config_json() const {
99
// clang-format off
10-
destination = nlohmann::json::object({
10+
return nlohmann::json::object({
1111
{"type", "datadog::tracing::NullCollector"},
1212
{"config", nlohmann::json::object({})},
1313
});

0 commit comments

Comments
 (0)