Classes | Public Types | Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
basic_writer< Range > Class Template Reference

#include <format.h>

Classes

struct  double_writer
 
struct  inf_or_nan_writer
 
struct  int_writer
 
struct  padded_int_writer
 
struct  str_writer
 

Public Types

typedef Range::value_type char_type
 
typedef basic_format_specs< char_typeformat_specs
 

Public Member Functions

 basic_writer (Range out, internal::locale_ref loc=internal::locale_ref())
 
iterator out () const
 
void write (int value)
 
void write (long value)
 
void write (long long value)
 
void write (unsigned value)
 
void write (unsigned long value)
 
void write (unsigned long long value)
 
template<typename T , typename FormatSpec , typename... FormatSpecs>
std::enable_if< std::is_integral< T >::value, void >::type write (T value, FormatSpec spec, FormatSpecs...specs)
 
void write (double value)
 
void write (long double value)
 
void write (char value)
 
void write (wchar_t value)
 
void write (string_view value)
 
void write (wstring_view value)
 
template<typename Char >
void write (const Char *s, std::size_t size, const align_spec &spec)
 
template<typename Char >
void write (basic_string_view< Char > s, const format_specs &spec=format_specs())
 
template<typename T >
std::enable_if< std::is_same< T, void >::value >::type write (const T *p)
 

Public Attributes

decltype(internal::declval< Range >().begin()) typedef iterator
 

Private Types

enum  { INF_SIZE = 3 }
 

Private Member Functions

auto reserve (std::size_t n) -> decltype(internal::reserve(out_, n))
 
template<typename F >
void write_padded (const align_spec &spec, F &&f)
 
template<typename Spec , typename F >
void write_int (int num_digits, string_view prefix, const Spec &spec, F f)
 
template<typename Int >
void write_decimal (Int value)
 
template<typename T , typename Spec >
void write_int (T value, const Spec &spec)
 
template<typename T >
void write_double (T value, const format_specs &spec)
 

Private Attributes

iterator out_
 
internal::locale_ref locale_
 

Friends

template<typename Char >
class internal::arg_formatter_base
 

Detailed Description

template<typename Range>
class basic_writer< Range >

This template provides operations for formatting and writing data into a character range.

Definition at line 330 of file format.h.

Member Typedef Documentation

template<typename Range>
typedef Range::value_type basic_writer< Range >::char_type

Definition at line 2261 of file format.h.

template<typename Range>
typedef basic_format_specs<char_type> basic_writer< Range >::format_specs

Definition at line 2263 of file format.h.

Member Enumeration Documentation

template<typename Range>
anonymous enum
private
Enumerator
INF_SIZE 

Definition at line 2504 of file format.h.

2504 {INF_SIZE = 3}; // This is an enum to workaround a bug in MSVC.

Constructor & Destructor Documentation

template<typename Range>
basic_writer< Range >::basic_writer ( Range  out,
internal::locale_ref  loc = internal::locale_ref() 
)
inlineexplicit

Constructs a basic_writer object.

Definition at line 2567 of file format.h.

2569  : out_(out.begin()), locale_(loc) {}
internal::locale_ref locale_
Definition: format.h:2267
iterator out_
Definition: format.h:2266

Member Function Documentation

template<typename Range>
iterator basic_writer< Range >::out ( ) const
inline

Definition at line 2571 of file format.h.

2571 { return out_; }
iterator out_
Definition: format.h:2266
template<typename Range>
auto basic_writer< Range >::reserve ( std::size_t  n) -> decltype(internal::reserve(out_, n))
inlineprivate

Definition at line 2271 of file format.h.

2271  {
2272  return internal::reserve(out_, n);
2273  }
iterator out_
Definition: format.h:2266
std::enable_if< is_contiguous< Container >::value, typename checked< typename Container::value_type >::type >::type reserve(std::back_insert_iterator< Container > &it, std::size_t n)
Definition: format.h:596
std::size_t n
Definition: format.h:3399
template<typename Range>
void basic_writer< Range >::write ( int  value)
inline

Definition at line 2573 of file format.h.

2573 { write_decimal(value); }
void write_decimal(Int value)
Definition: format.h:2349
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
template<typename Range>
void basic_writer< Range >::write ( long  value)
inline

Definition at line 2574 of file format.h.

2574 { write_decimal(value); }
void write_decimal(Int value)
Definition: format.h:2349
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
template<typename Range>
void basic_writer< Range >::write ( long long  value)
inline

Definition at line 2575 of file format.h.

2575 { write_decimal(value); }
void write_decimal(Int value)
Definition: format.h:2349
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
template<typename Range>
void basic_writer< Range >::write ( unsigned  value)
inline

Definition at line 2577 of file format.h.

2577 { write_decimal(value); }
void write_decimal(Int value)
Definition: format.h:2349
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
template<typename Range>
void basic_writer< Range >::write ( unsigned long  value)
inline

Definition at line 2578 of file format.h.

2578 { write_decimal(value); }
void write_decimal(Int value)
Definition: format.h:2349
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
template<typename Range>
void basic_writer< Range >::write ( unsigned long long  value)
inline

Definition at line 2579 of file format.h.

2579 { write_decimal(value); }
void write_decimal(Int value)
Definition: format.h:2349
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
template<typename Range>
template<typename T , typename FormatSpec , typename... FormatSpecs>
std::enable_if<std::is_integral<T>::value, void>::type basic_writer< Range >::write ( value,
FormatSpec  spec,
FormatSpecs...  specs 
)
inline

Formats value and writes it to the buffer.

Definition at line 2588 of file format.h.

2588  {
2589  format_specs s(spec, specs...);
2590  s.align_ = ALIGN_RIGHT;
2591  write_int(value, s);
2592  }
void write_int(int num_digits, string_view prefix, const Spec &spec, F f)
Definition: format.h:2326
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
static QCString * s
Definition: config.cpp:1042
template<typename Range>
void basic_writer< Range >::write ( double  value)
inline

Definition at line 2594 of file format.h.

2594  {
2596  }
void write_double(T value, const format_specs &spec)
Definition: format.h:2698
basic_format_specs< char_type > format_specs
Definition: format.h:2263
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
template<typename Range>
void basic_writer< Range >::write ( long double  value)
inline

Formats value using the general format for floating-point numbers ('g') and writes it to the buffer.

Definition at line 2604 of file format.h.

2604  {
2606  }
void write_double(T value, const format_specs &spec)
Definition: format.h:2698
basic_format_specs< char_type > format_specs
Definition: format.h:2263
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
template<typename Range>
void basic_writer< Range >::write ( char  value)
inline

Writes a character to the buffer.

Definition at line 2609 of file format.h.

2609  {
2610  *reserve(1) = value;
2611  }
auto reserve(std::size_t n) -> decltype(internal::reserve(out_, n))
Definition: format.h:2271
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
template<typename Range>
void basic_writer< Range >::write ( wchar_t  value)
inline

Definition at line 2612 of file format.h.

2612  {
2613  static_assert(std::is_same<char_type, wchar_t>::value, "");
2614  *reserve(1) = value;
2615  }
auto reserve(std::size_t n) -> decltype(internal::reserve(out_, n))
Definition: format.h:2271
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
template<typename Range>
void basic_writer< Range >::write ( string_view  value)
inline

Writes value to the buffer.

Definition at line 2622 of file format.h.

2622  {
2623  auto &&it = reserve(value.size());
2624  it = internal::copy_str<char_type>(value.begin(), value.end(), it);
2625  }
auto reserve(std::size_t n) -> decltype(internal::reserve(out_, n))
Definition: format.h:2271
FMT_CONSTEXPR size_t size() const
Definition: core.h:389
FMT_CONSTEXPR iterator end() const
Definition: core.h:392
FMT_CONSTEXPR iterator begin() const
Definition: core.h:391
template<typename Range>
void basic_writer< Range >::write ( wstring_view  value)
inline

Definition at line 2626 of file format.h.

2626  {
2627  static_assert(std::is_same<char_type, wchar_t>::value, "");
2628  auto &&it = reserve(value.size());
2629  it = std::copy(value.begin(), value.end(), it);
2630  }
auto reserve(std::size_t n) -> decltype(internal::reserve(out_, n))
Definition: format.h:2271
FMT_CONSTEXPR size_t size() const
Definition: core.h:389
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
T copy(T const &v)
FMT_CONSTEXPR iterator end() const
Definition: core.h:392
FMT_CONSTEXPR iterator begin() const
Definition: core.h:391
template<typename Range>
template<typename Char >
void basic_writer< Range >::write ( const Char *  s,
std::size_t  size,
const align_spec spec 
)
inline

Definition at line 2634 of file format.h.

2634  {
2635  write_padded(spec, str_writer<Char>{s, size});
2636  }
void write_padded(const align_spec &spec, F &&f)
Definition: format.h:2279
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:87
static QCString * s
Definition: config.cpp:1042
template<typename Range>
template<typename Char >
void basic_writer< Range >::write ( basic_string_view< Char >  s,
const format_specs spec = format_specs() 
)
inline

Definition at line 2639 of file format.h.

2640  {
2641  const Char *data = s.data();
2642  std::size_t size = s.size();
2643  if (spec.precision >= 0 && internal::to_unsigned(spec.precision) < size)
2644  size = internal::to_unsigned(spec.precision);
2645  write(data, size, spec);
2646  }
basic_data data
Definition: format.h:764
FMT_CONSTEXPR size_t size() const
Definition: core.h:389
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:87
FMT_CONSTEXPR const Char * data() const
Definition: core.h:386
FMT_CONSTEXPR std::make_unsigned< Int >::type to_unsigned(Int value)
Definition: core.h:208
void write(int value)
Definition: format.h:2573
template<typename Range>
template<typename T >
std::enable_if<std::is_same<T, void>::value>::type basic_writer< Range >::write ( const T *  p)
inline

Definition at line 2650 of file format.h.

2650  {
2651  format_specs specs;
2652  specs.flags = HASH_FLAG;
2653  specs.type = 'x';
2654  write_int(reinterpret_cast<uintptr_t>(p), specs);
2655  }
void write_int(int num_digits, string_view prefix, const Spec &spec, F f)
Definition: format.h:2326
p
Definition: test.py:223
uint_least8_t flags
Definition: format.h:1102
template<typename Range>
template<typename Int >
void basic_writer< Range >::write_decimal ( Int  value)
inlineprivate

Definition at line 2349 of file format.h.

2349  {
2350  typedef typename internal::int_traits<Int>::main_type main_type;
2351  main_type abs_value = static_cast<main_type>(value);
2352  bool is_negative = internal::is_negative(value);
2353  if (is_negative)
2354  abs_value = 0 - abs_value;
2355  int num_digits = internal::count_digits(abs_value);
2356  auto &&it = reserve((is_negative ? 1 : 0) + static_cast<size_t>(num_digits));
2357  if (is_negative)
2358  *it++ = static_cast<char_type>('-');
2359  it = internal::format_decimal<char_type>(it, abs_value, num_digits);
2360  }
auto reserve(std::size_t n) -> decltype(internal::reserve(out_, n))
Definition: format.h:2271
FMT_CONSTEXPR std::enable_if< !std::numeric_limits< T >::is_signed, bool >::type is_negative(T)
Definition: format.h:732
Range::value_type char_type
Definition: format.h:2261
FMT_CONSTEXPR std::enable_if< std::numeric_limits< T >::is_signed, bool >::type is_negative(T value)
Definition: format.h:727
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
int count_digits(uint64_t n)
Definition: format.h:777
template<typename Range >
template<typename T >
void basic_writer< Range >::write_double ( value,
const format_specs spec 
)
private

Definition at line 2698 of file format.h.

2698  {
2699  // Check type.
2700  float_spec_handler handler(static_cast<char>(spec.type));
2702 
2703  char sign = 0;
2704  // Use signbit instead of value < 0 because the latter is always
2705  // false for NaN.
2706  if (std::signbit(value)) {
2707  sign = '-';
2708  value = -value;
2709  } else if (spec.has(SIGN_FLAG)) {
2710  sign = spec.has(PLUS_FLAG) ? '+' : ' ';
2711  }
2712 
2713  struct write_inf_or_nan_t {
2715  format_specs spec;
2716  char sign;
2717  void operator()(const char *str) const {
2718  writer.write_padded(spec, inf_or_nan_writer{sign, str});
2719  }
2720  } write_inf_or_nan = {*this, spec, sign};
2721 
2722  // Format NaN and ininity ourselves because sprintf's output is not consistent
2723  // across platforms.
2724  if (internal::fputil::isnotanumber(value))
2725  return write_inf_or_nan(handler.upper ? "NAN" : "nan");
2726  if (internal::fputil::isinfinity(value))
2727  return write_inf_or_nan(handler.upper ? "INF" : "inf");
2728 
2730  bool use_grisu = FMT_USE_GRISU && sizeof(T) <= sizeof(double) &&
2731  spec.type != 'a' && spec.type != 'A' &&
2732  internal::grisu2_format(static_cast<double>(value), buffer, spec);
2733  if (!use_grisu) {
2734  format_specs normalized_spec(spec);
2735  normalized_spec.type = handler.type;
2736  internal::sprintf_format(value, buffer, normalized_spec);
2737  }
2738  size_t n = buffer.size();
2739  align_spec as = spec;
2740  if (spec.align() == ALIGN_NUMERIC) {
2741  if (sign) {
2742  auto &&it = reserve(1);
2743  *it++ = static_cast<char_type>(sign);
2744  sign = 0;
2745  if (as.width_)
2746  --as.width_;
2747  }
2748  as.align_ = ALIGN_RIGHT;
2749  } else {
2750  if (spec.align() == ALIGN_DEFAULT)
2751  as.align_ = ALIGN_RIGHT;
2752  if (sign)
2753  ++n;
2754  }
2755  write_padded(as, double_writer{n, sign, buffer});
2756 }
auto reserve(std::size_t n) -> decltype(internal::reserve(out_, n))
Definition: format.h:2271
alignment align_
Definition: format.h:1092
void write_padded(const align_spec &spec, F &&f)
Definition: format.h:2279
FMT_CONSTEXPR void handle_float_type_spec(char spec, Handler &&handler)
Definition: format.h:1163
void sprintf_format(Double value, internal::buffer &buf, core_format_specs spec)
Definition: format-inl.h:764
basic_writer< back_insert_range< internal::buffer > > writer
Definition: format.h:361
FMT_CONSTEXPR bool has(unsigned f) const
Definition: format.h:1106
format_arg_store< context, Args... > as
Definition: format.h:3345
#define FMT_USE_GRISU
Definition: format.h:165
internal::basic_buffer< FMT_CHAR(S)> buffer
Definition: printf.h:757
std::size_t size() const FMT_NOEXCEPT
Definition: core.h:250
Range::value_type char_type
Definition: format.h:2261
std::string str(const std::pair< Type, Type > &tt)
Definition: test_pimpos.cxx:12
int sign(double val)
Definition: UtilFunc.cxx:104
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
static msg_handler handler
Definition: qglobal.cpp:234
FMT_FUNC std::enable_if< sizeof(Double)==sizeof(uint64_t), bool >::type grisu2_format(Double value, buffer &buf, core_format_specs specs)
Definition: format-inl.h:716
unsigned width_
Definition: format.h:1088
if(!yymsg) yymsg
std::size_t n
Definition: format.h:3399
FMT_CONSTEXPR alignment align() const
Definition: format.h:1097
template<typename Range>
template<typename Spec , typename F >
void basic_writer< Range >::write_int ( int  num_digits,
string_view  prefix,
const Spec &  spec,
f 
)
inlineprivate

Definition at line 2326 of file format.h.

2327  {
2328  std::size_t size = prefix.size() + internal::to_unsigned(num_digits);
2329  char_type fill = static_cast<char_type>(spec.fill());
2330  std::size_t padding = 0;
2331  if (spec.align() == ALIGN_NUMERIC) {
2332  if (spec.width() > size) {
2333  padding = spec.width() - size;
2334  size = spec.width();
2335  }
2336  } else if (spec.precision > num_digits) {
2337  size = prefix.size() + internal::to_unsigned(spec.precision);
2338  padding = internal::to_unsigned(spec.precision - num_digits);
2339  fill = static_cast<char_type>('0');
2340  }
2341  align_spec as = spec;
2342  if (spec.align() == ALIGN_DEFAULT)
2343  as.align_ = ALIGN_RIGHT;
2344  write_padded(as, padded_int_writer<F>{size, prefix, fill, padding, f});
2345  }
alignment align_
Definition: format.h:1092
void write_padded(const align_spec &spec, F &&f)
Definition: format.h:2279
format_arg_store< context, Args... > as
Definition: format.h:3345
FMT_CONSTEXPR size_t size() const
Definition: core.h:389
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:87
Range::value_type char_type
Definition: format.h:2261
FMT_CONSTEXPR std::make_unsigned< Int >::type to_unsigned(Int value)
Definition: core.h:208
def fill(s)
Definition: translator.py:93
template<typename Range>
template<typename T , typename Spec >
void basic_writer< Range >::write_int ( value,
const Spec &  spec 
)
inlineprivate

Definition at line 2499 of file format.h.

2499  {
2501  int_writer<T, Spec>(*this, value, spec));
2502  }
FMT_CONSTEXPR void handle_int_type_spec(char spec, Handler &&handler)
Definition: format.h:1140
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
template<typename Range>
template<typename F >
void basic_writer< Range >::write_padded ( const align_spec spec,
F &&  f 
)
inlineprivate

Definition at line 2279 of file format.h.

2279  {
2280  unsigned width = spec.width(); // User-perceived width (in code points).
2281  size_t size = f.size(); // The number of code units.
2282  size_t num_code_points = width != 0 ? f.width() : size;
2283  if (width <= num_code_points)
2284  return f(reserve(size));
2285  auto &&it = reserve(width + (size - num_code_points));
2286  char_type fill = static_cast<char_type>(spec.fill());
2287  std::size_t padding = width - num_code_points;
2288  if (spec.align() == ALIGN_RIGHT) {
2289  it = std::fill_n(it, padding, fill);
2290  f(it);
2291  } else if (spec.align() == ALIGN_CENTER) {
2292  std::size_t left_padding = padding / 2;
2293  it = std::fill_n(it, left_padding, fill);
2294  f(it);
2295  it = std::fill_n(it, padding - left_padding, fill);
2296  } else {
2297  f(it);
2298  it = std::fill_n(it, padding, fill);
2299  }
2300  }
auto reserve(std::size_t n) -> decltype(internal::reserve(out_, n))
Definition: format.h:2271
const double width
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:87
Range::value_type char_type
Definition: format.h:2261
FMT_CONSTEXPR wchar_t fill() const
Definition: format.h:1096
FMT_CONSTEXPR unsigned width() const
Definition: format.h:1095
def fill(s)
Definition: translator.py:93
FMT_CONSTEXPR alignment align() const
Definition: format.h:1097

Friends And Related Function Documentation

template<typename Range>
template<typename Char >
friend class internal::arg_formatter_base
friend

Definition at line 2563 of file format.h.

Member Data Documentation

template<typename Range>
decltype(internal::declval<Range>().begin()) typedef basic_writer< Range >::iterator

Definition at line 2262 of file format.h.

template<typename Range>
internal::locale_ref basic_writer< Range >::locale_
private

Definition at line 2267 of file format.h.

template<typename Range>
iterator basic_writer< Range >::out_
private

Definition at line 2266 of file format.h.


The documentation for this class was generated from the following file: