Add absl::string_view to openscreen
This PR does the work of adding the absl::string_view class
to our code base, with suggested usage from the Abseil team,
found here:
https://abseil.io/tips/1
Bug: openscreen:23
Change-Id: I43fd60e2574f8c116946a52a10a422a15487e266
Reviewed-on: https://chromium-review.googlesource.com/c/1422681
Commit-Queue: Jordan Bayles <jophba@chromium.org>
Reviewed-by: mark a. foltz <mfoltz@chromium.org>
diff --git a/platform/api/BUILD.gn b/platform/api/BUILD.gn
index 8900278..14e6957 100644
--- a/platform/api/BUILD.gn
+++ b/platform/api/BUILD.gn
@@ -18,5 +18,6 @@
public_deps = [
"//base",
"//third_party/abseil",
+ "//third_party/abseil",
]
}
diff --git a/platform/api/logging.cc b/platform/api/logging.cc
index 5abdf57..b4f240b 100644
--- a/platform/api/logging.cc
+++ b/platform/api/logging.cc
@@ -9,7 +9,7 @@
LogMessage::LogMessage(LogLevel level,
int verbose_level,
- const char* file,
+ absl::string_view file,
int line)
: level_(level), verbose_level_(verbose_level), file_(file), line_(line) {}
diff --git a/platform/api/logging.h b/platform/api/logging.h
index c323810..5a2e237 100644
--- a/platform/api/logging.h
+++ b/platform/api/logging.h
@@ -7,6 +7,8 @@
#include <sstream>
+#include "third_party/abseil/src/absl/strings/string_view.h"
+
namespace openscreen {
namespace platform {
@@ -27,9 +29,9 @@
void SetLogLevel(LogLevel level, int verbose_level = 0);
void LogWithLevel(LogLevel level,
int verbose_level,
- const char* file,
+ absl::string_view file,
int line,
- const char* msg);
+ absl::string_view msg);
void Break();
//
// END PLATFORM IMPLEMENTATION
@@ -39,7 +41,10 @@
// base/logging.h.
class LogMessage {
public:
- LogMessage(LogLevel level, int verbose_level, const char* file, int line);
+ LogMessage(LogLevel level,
+ int verbose_level,
+ absl::string_view file,
+ int line);
~LogMessage();
std::ostream& stream() { return stream_; }
@@ -47,7 +52,11 @@
private:
const LogLevel level_;
const int verbose_level_;
- const char* const file_;
+
+ // The file here comes from the __FILE__ macro, which should persist while
+ // we are doing the logging. Hence, keeping it unmanaged here and not
+ // creating a copy should be safe.
+ absl::string_view const file_;
const int line_;
std::ostringstream stream_;
};