Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef ABSL_STRINGS_INTERNAL_STR_FORMAT_OUTPUT_H_
00022 #define ABSL_STRINGS_INTERNAL_STR_FORMAT_OUTPUT_H_
00023
00024 #include <cstdio>
00025 #include <ostream>
00026 #include <string>
00027
00028 #include "absl/base/port.h"
00029 #include "absl/strings/string_view.h"
00030
00031 class Cord;
00032
00033 namespace absl {
00034 namespace str_format_internal {
00035
00036
00037
00038
00039 class BufferRawSink {
00040 public:
00041 BufferRawSink(char* buffer, size_t size) : buffer_(buffer), size_(size) {}
00042
00043 size_t total_written() const { return total_written_; }
00044 void Write(string_view v);
00045
00046 private:
00047 char* buffer_;
00048 size_t size_;
00049 size_t total_written_ = 0;
00050 };
00051
00052
00053
00054
00055 class FILERawSink {
00056 public:
00057 explicit FILERawSink(std::FILE* output) : output_(output) {}
00058
00059 void Write(string_view v);
00060
00061 size_t count() const { return count_; }
00062 int error() const { return error_; }
00063
00064 private:
00065 std::FILE* output_;
00066 int error_ = 0;
00067 size_t count_ = 0;
00068 };
00069
00070
00071 inline void AbslFormatFlush(std::string* out, string_view s) {
00072 out->append(s.data(), s.size());
00073 }
00074 inline void AbslFormatFlush(std::ostream* out, string_view s) {
00075 out->write(s.data(), s.size());
00076 }
00077
00078 template <class AbslCord, typename = typename std::enable_if<
00079 std::is_same<AbslCord, ::Cord>::value>::type>
00080 inline void AbslFormatFlush(AbslCord* out, string_view s) {
00081 out->Append(s);
00082 }
00083
00084 inline void AbslFormatFlush(FILERawSink* sink, string_view v) {
00085 sink->Write(v);
00086 }
00087
00088 inline void AbslFormatFlush(BufferRawSink* sink, string_view v) {
00089 sink->Write(v);
00090 }
00091
00092 template <typename T>
00093 auto InvokeFlush(T* out, string_view s)
00094 -> decltype(str_format_internal::AbslFormatFlush(out, s)) {
00095 str_format_internal::AbslFormatFlush(out, s);
00096 }
00097
00098 }
00099 }
00100
00101 #endif // ABSL_STRINGS_INTERNAL_STR_FORMAT_OUTPUT_H_