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 
16 namespace fmt
17 {
18 
19 namespace internal
20 {
21 
22 template <class Char>
23 class FormatBuf : public std::basic_streambuf<Char>
24 {
25 private:
26  typedef typename std::basic_streambuf<Char>::int_type int_type;
27  typedef typename std::basic_streambuf<Char>::traits_type traits_type;
28 
31 
32 public:
33  FormatBuf(Buffer<Char> &buffer) : buffer_(buffer), start_(&buffer[0])
34  {
35  this->setp(start_, start_ + buffer_.capacity());
36  }
37 
38  int_type overflow(int_type ch = traits_type::eof())
39  {
40  if (!traits_type::eq_int_type(ch, traits_type::eof()))
41  {
42  size_t buf_size = size();
43  buffer_.resize(buf_size);
44  buffer_.reserve(buf_size * 2);
45 
46  start_ = &buffer_[0];
47  start_[buf_size] = traits_type::to_char_type(ch);
48  this->setp(start_+ buf_size + 1, start_ + buf_size * 2);
49  }
50  return ch;
51  }
52 
53  size_t size() const
54  {
55  return to_unsigned(this->pptr() - start_);
56  }
57 };
58 
59 Yes &convert(std::ostream &);
60 
61 struct DummyStream : std::ostream
62 {
63  DummyStream(); // Suppress a bogus warning in MSVC.
64  // Hide all operator<< overloads from std::ostream.
65  void operator<<(Null<>);
66 };
67 
68 No &operator<<(std::ostream &, int);
69 
70 template<typename T>
71 struct ConvertToIntImpl<T, true>
72 {
73  // Convert to int only if T doesn't have an overloaded operator<<.
74  enum
75  {
76  value = sizeof(convert(get<DummyStream>() << get<T>())) == sizeof(No)
77  };
78 };
79 } // namespace internal
80 
81 // Formats a value.
82 template <typename Char, typename ArgFormatter, typename T>
84  const Char *&format_str, const T &value)
85 {
87 
88  internal::FormatBuf<Char> format_buf(buffer);
89  std::basic_ostream<Char> output(&format_buf);
90  output << value;
91 
92  BasicStringRef<Char> str(&buffer[0], format_buf.size());
94  format_str = f.format(format_str, MakeArg(str));
95 }
96 
106 FMT_API void print(std::ostream &os, CStringRef format_str, ArgList args);
107 FMT_VARIADIC(void, print, std::ostream &, CStringRef)
108 
109 
118 FMT_API int fprintf(std::ostream &os, CStringRef format_str, ArgList args);
119 FMT_VARIADIC(int, fprintf, std::ostream &, CStringRef)
120 } // namespace fmt
121 
122 #ifdef FMT_HEADER_ONLY
123 # include "ostream.cc"
124 #endif
125 
126 #endif // FMT_OSTREAM_H_
Buffer< Char > & buffer_
Definition: ostream.h:29
#define FMT_VARIADIC(ReturnType, func,...)
Definition: format.h:4036
void resize(std::size_t new_size)
Definition: format.h:706
char Yes[1]
Definition: format.h:1252
FMT_API void print(std::FILE *f, CStringRef format_str, ArgList args)
Definition: format.cc:873
std::string format(CStringRef format_str, ArgList args)
Definition: format.h:3686
std::size_t capacity() const
Definition: format.h:698
int_type overflow(int_type ch=traits_type::eof())
Definition: ostream.h:38
size_t size() const
Definition: ostream.h:53
void format(BasicCStringRef< Char > format_str)
Definition: format.h:4378
Yes & convert(fmt::ULongLong)
#define FMT_API
Definition: format.h:75
FormatBuf(Buffer< Char > &buffer)
Definition: ostream.h:33
MakeUnsigned< Int >::Type to_unsigned(Int value)
Definition: format.h:635
No & operator<<(std::ostream &, int)
char No[2]
Definition: format.h:1253
std::basic_streambuf< Char >::int_type int_type
Definition: ostream.h:26
std::basic_streambuf< Char >::traits_type traits_type
Definition: ostream.h:27
void reserve(std::size_t capacity)
Definition: format.h:718
FMT_API int fprintf(std::FILE *f, CStringRef format, ArgList args)
Definition: format.cc:891
Definition: format.cc:81


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:12:07