Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
ostream.h
Go to the documentation of this file.
1/*
2 Formatting library for C++ - std::ostream support
3
4 Copyright (c) 2012 - 2016, Victor Zverovich
5 All rights reserved.
6
7 For the license information refer to format.h.
8 */
9
10#ifndef FMT_OSTREAM_H_
11#define FMT_OSTREAM_H_
12
13#include "format.h"
14#include <ostream>
15
16namespace fmt {
17
18namespace internal {
19
20template <class Char>
21class FormatBuf : public std::basic_streambuf<Char> {
22 private:
23 typedef typename std::basic_streambuf<Char>::int_type int_type;
24 typedef typename std::basic_streambuf<Char>::traits_type traits_type;
25
27
28 public:
29 FormatBuf(Buffer<Char> &buffer) : buffer_(buffer) {}
30
31 protected:
32 // The put-area is actually always empty. This makes the implementation
33 // simpler and has the advantage that the streambuf and the buffer are always
34 // in sync and sputc never writes into uninitialized memory. The obvious
35 // disadvantage is that each call to sputc always results in a (virtual) call
36 // to overflow. There is no disadvantage here for sputn since this always
37 // results in a call to xsputn.
38
41 buffer_.push_back(static_cast<Char>(ch));
42 return ch;
43 }
44
45 std::streamsize xsputn(const Char *s, std::streamsize count) FMT_OVERRIDE {
47 return count;
48 }
49};
50
51Yes &convert(std::ostream &);
52
53struct DummyStream : std::ostream {
54 DummyStream(); // Suppress a bogus warning in MSVC.
55
56 // Hide all operator<< overloads from std::ostream.
57 template <typename T>
58 typename EnableIf<sizeof(T) == 0>::type operator<<(const T &);
59};
60
61No &operator<<(std::ostream &, int);
62
63template <typename T>
64struct ConvertToIntImpl<T, true> {
65 // Convert to int only if T doesn't have an overloaded operator<<.
66 enum {
67 value = sizeof(convert(get<DummyStream>() << get<T>())) == sizeof(No)
68 };
69};
70
71// Write the content of w to os.
72FMT_API void write(std::ostream &os, Writer &w);
73} // namespace internal
74
75// Formats a value.
76template <typename Char, typename ArgFormatter_, typename T>
77void format_arg(BasicFormatter<Char, ArgFormatter_> &f,
78 const Char *&format_str, const T &value) {
80
84 output << value;
85
89}
90
91/**
92 \rst
93 Prints formatted data to the stream *os*.
94
95 **Example**::
96
97 print(cerr, "Don't {}!", "panic");
98 \endrst
99 */
100FMT_API void print(std::ostream &os, CStringRef format_str, ArgList args);
102} // namespace fmt
103
104#ifdef FMT_HEADER_ONLY
105# include "ostream.cc"
106#endif
107
108#endif // FMT_OSTREAM_H_
std::size_t size() const
Definition format.h:2727
const Char * data() const FMT_NOEXCEPT
Definition format.h:2733
void write(BasicCStringRef< Char > format, ArgList args)
Definition format.h:2780
std::basic_streambuf< Char >::int_type int_type
Definition ostream.h:23
int_type overflow(int_type ch=traits_type::eof()) FMT_OVERRIDE
Definition ostream.h:39
std::basic_streambuf< Char >::traits_type traits_type
Definition ostream.h:24
Buffer< Char > & buffer_
Definition ostream.h:26
FormatBuf(Buffer< Char > &buffer)
Definition ostream.h:29
std::streamsize xsputn(const Char *s, std::streamsize count) FMT_OVERRIDE
Definition ostream.h:45
MakeUnsigned< Int >::Type to_unsigned(Int value)
Definition format.h:711
FMT_FUNC void write(std::ostream &os, Writer &w)
Definition ostream.cc:15
Yes & convert(std::ostream &)
Definition format.h:408
FMT_FUNC void print(std::ostream &os, CStringRef format_str, ArgList args)
Definition ostream.cc:30
void format_arg(BasicFormatter< Char, ArgFormatter_ > &f, const Char *&format_str, const T &value)
Definition ostream.h:77
Definition json.hpp:4518
EnableIf< sizeof(T)==0 >::type operator<<(const T &)
#define FMT_OVERRIDE
Definition format.h:263
#define FMT_FUNC
Definition format.h:4170
#define FMT_VARIADIC(ReturnType, func,...)
Definition format.h:3708
#define FMT_API
Definition format.h:94