xref: /aosp_15_r20/external/angle/third_party/abseil-cpp/absl/log/internal/structured.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 // Copyright 2022 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // -----------------------------------------------------------------------------
16 // File: log/internal/structured.h
17 // -----------------------------------------------------------------------------
18 
19 #ifndef ABSL_LOG_INTERNAL_STRUCTURED_H_
20 #define ABSL_LOG_INTERNAL_STRUCTURED_H_
21 
22 #include <ostream>
23 
24 #include "absl/base/config.h"
25 #include "absl/base/attributes.h"
26 #include "absl/log/internal/log_message.h"
27 #include "absl/strings/string_view.h"
28 
29 namespace absl {
30 ABSL_NAMESPACE_BEGIN
31 namespace log_internal {
32 
33 class ABSL_MUST_USE_RESULT AsLiteralImpl final {
34  public:
AsLiteralImpl(absl::string_view str ABSL_ATTRIBUTE_LIFETIME_BOUND)35   explicit AsLiteralImpl(absl::string_view str ABSL_ATTRIBUTE_LIFETIME_BOUND)
36       : str_(str) {}
37   AsLiteralImpl(const AsLiteralImpl&) = default;
38   AsLiteralImpl& operator=(const AsLiteralImpl&) = default;
39 
40  private:
41   absl::string_view str_;
42 
43   friend std::ostream& operator<<(std::ostream& os,
44                                   AsLiteralImpl&& as_literal) {
45     return os << as_literal.str_;
46   }
AddToMessage(log_internal::LogMessage & m)47   void AddToMessage(log_internal::LogMessage& m) {
48     m.CopyToEncodedBuffer<log_internal::LogMessage::StringType::kLiteral>(str_);
49   }
50   friend log_internal::LogMessage& operator<<(log_internal::LogMessage& m,
51                                               AsLiteralImpl as_literal) {
52     as_literal.AddToMessage(m);
53     return m;
54   }
55 };
56 
57 }  // namespace log_internal
58 ABSL_NAMESPACE_END
59 }  // namespace absl
60 
61 #endif  // ABSL_LOG_INTERNAL_STRUCTURED_H_
62