grpc
third_party
bloaty
third_party
abseil-cpp
absl
strings
internal
str_format
bloaty/third_party/abseil-cpp/absl/strings/internal/str_format/output.h
Go to the documentation of this file.
1
// Copyright 2017 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
// Output extension hooks for the Format library.
16
// `internal::InvokeFlush` calls the appropriate flush function for the
17
// specified output argument.
18
// `BufferRawSink` is a simple output sink for a char buffer. Used by SnprintF.
19
// `FILERawSink` is a std::FILE* based sink. Used by PrintF and FprintF.
20
21
#ifndef ABSL_STRINGS_INTERNAL_STR_FORMAT_OUTPUT_H_
22
#define ABSL_STRINGS_INTERNAL_STR_FORMAT_OUTPUT_H_
23
24
#include <cstdio>
25
#include <ostream>
26
#include <string>
27
28
#include "absl/base/port.h"
29
#include "absl/strings/string_view.h"
30
31
namespace
absl
{
32
ABSL_NAMESPACE_BEGIN
33
namespace
str_format_internal
{
34
35
// RawSink implementation that writes into a char* buffer.
36
// It will not overflow the buffer, but will keep the total count of chars
37
// that would have been written.
38
class
BufferRawSink {
39
public
:
40
BufferRawSink
(
char
*
buffer
,
size_t
size
) :
buffer_
(
buffer
),
size_
(
size
) {}
41
42
size_t
total_written
()
const
{
return
total_written_
; }
43
void
Write
(
string_view
v
);
44
45
private
:
46
char
*
buffer_
;
47
size_t
size_
;
48
size_t
total_written_
= 0;
49
};
50
51
// RawSink implementation that writes into a FILE*.
52
// It keeps track of the total number of bytes written and any error encountered
53
// during the writes.
54
class
FILERawSink {
55
public
:
56
explicit
FILERawSink
(
std::FILE
*
output
) :
output_
(
output
) {}
57
58
void
Write
(
string_view
v
);
59
60
size_t
count
()
const
{
return
count_
; }
61
int
error
()
const
{
return
error_
; }
62
63
private
:
64
std::FILE
*
output_
;
65
int
error_
= 0;
66
size_t
count_
= 0;
67
};
68
69
// Provide RawSink integration with common types from the STL.
70
inline
void
AbslFormatFlush
(
std::string
*
out
,
string_view
s) {
71
out
->append(
s
.data(),
s
.size());
72
}
73
inline
void
AbslFormatFlush
(std::ostream*
out
,
string_view
s) {
74
out
->write(s.data(), s.size());
75
}
76
77
inline
void
AbslFormatFlush
(FILERawSink*
sink
,
string_view
v
) {
78
sink
->Write(
v
);
79
}
80
81
inline
void
AbslFormatFlush
(BufferRawSink*
sink
,
string_view
v
) {
82
sink
->Write(
v
);
83
}
84
85
// This is a SFINAE to get a better compiler error message when the type
86
// is not supported.
87
template
<
typename
T>
88
auto
InvokeFlush
(
T
*
out
,
string_view
s) -> decltype(
AbslFormatFlush
(
out
, s)) {
89
AbslFormatFlush
(
out
, s);
90
}
91
92
}
// namespace str_format_internal
93
ABSL_NAMESPACE_END
94
}
// namespace absl
95
96
#endif // ABSL_STRINGS_INTERNAL_STR_FORMAT_OUTPUT_H_
absl::str_format_internal::InvokeFlush
auto InvokeFlush(T *out, string_view s) -> decltype(AbslFormatFlush(out, s))
Definition:
abseil-cpp/absl/strings/internal/str_format/output.h:89
absl::string_view
Definition:
abseil-cpp/absl/strings/string_view.h:167
absl::str_format_internal::FILERawSink::error_
int error_
Definition:
abseil-cpp/absl/strings/internal/str_format/output.h:66
testing::internal::string
::std::string string
Definition:
bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
absl::FormatConversionChar::s
@ s
absl::str_format_internal::BufferRawSink::total_written_
size_t total_written_
Definition:
abseil-cpp/absl/strings/internal/str_format/output.h:49
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition:
third_party/abseil-cpp/absl/base/config.h:171
T
#define T(upbtypeconst, upbtype, ctype, default_value)
absl::str_format_internal::FILERawSink::output_
std::FILE * output_
Definition:
abseil-cpp/absl/strings/internal/str_format/output.h:65
absl::str_format_internal::BufferRawSink::BufferRawSink
BufferRawSink(char *buffer, size_t size)
Definition:
bloaty/third_party/abseil-cpp/absl/strings/internal/str_format/output.h:40
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition:
third_party/abseil-cpp/absl/base/config.h:170
absl::str_format_internal::FILERawSink::count
size_t count() const
Definition:
bloaty/third_party/abseil-cpp/absl/strings/internal/str_format/output.h:60
gmock_output_test.output
output
Definition:
bloaty/third_party/googletest/googlemock/test/gmock_output_test.py:175
setup.v
v
Definition:
third_party/bloaty/third_party/capstone/bindings/python/setup.py:42
absl::str_format_internal::FILERawSink::Write
void Write(string_view v)
Definition:
abseil-cpp/absl/strings/internal/str_format/output.cc:42
absl::str_format_internal::BufferRawSink::size_
size_t size_
Definition:
abseil-cpp/absl/strings/internal/str_format/output.h:48
buffer
char buffer[1024]
Definition:
libuv/docs/code/idle-compute/main.c:8
absl::str_format_internal::BufferRawSink::Write
void Write(string_view v)
Definition:
abseil-cpp/absl/strings/internal/str_format/output.cc:34
absl::str_format_internal::AbslFormatFlush
void AbslFormatFlush(std::string *out, string_view s)
Definition:
abseil-cpp/absl/strings/internal/str_format/output.h:71
benchmark.FILE
FILE
Definition:
benchmark.py:21
sink
FormatSinkImpl * sink
Definition:
abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:450
absl::str_format_internal::FILERawSink::count_
size_t count_
Definition:
abseil-cpp/absl/strings/internal/str_format/output.h:67
absl::str_format_internal::FILERawSink::FILERawSink
FILERawSink(std::FILE *output)
Definition:
bloaty/third_party/abseil-cpp/absl/strings/internal/str_format/output.h:56
absl::str_format_internal::BufferRawSink::buffer_
char * buffer_
Definition:
abseil-cpp/absl/strings/internal/str_format/output.h:47
absl::str_format_internal::FILERawSink::error
int error() const
Definition:
bloaty/third_party/abseil-cpp/absl/strings/internal/str_format/output.h:61
absl
Definition:
abseil-cpp/absl/algorithm/algorithm.h:31
absl::out
char * out
Definition:
abseil-cpp/absl/synchronization/mutex.h:1048
size
voidpf void uLong size
Definition:
bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
str_format_internal
absl::str_format_internal::BufferRawSink::total_written
size_t total_written() const
Definition:
bloaty/third_party/abseil-cpp/absl/strings/internal/str_format/output.h:42
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:36