TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
fmt::BasicWriter< Char > Class Template Reference

#include <format.h>

Public Member Functions

virtual ~BasicWriter ()
 
std::size_t size () const
 
const Chardata () const FMT_NOEXCEPT
 
const Charc_str () const
 
std::basic_string< Charstr () const
 
void write (BasicCStringRef< Char > format, ArgList args)
 
BasicWriteroperator<< (int value)
 
BasicWriteroperator<< (unsigned value)
 
BasicWriteroperator<< (long value)
 
BasicWriteroperator<< (unsigned long value)
 
BasicWriteroperator<< (LongLong value)
 
BasicWriteroperator<< (ULongLong value)
 
BasicWriteroperator<< (double value)
 
BasicWriteroperator<< (long double value)
 
BasicWriteroperator<< (char value)
 
BasicWriteroperator<< (typename internal::WCharHelper< wchar_t, Char >::Supported value)
 
BasicWriteroperator<< (fmt::BasicStringRef< Char > value)
 
BasicWriteroperator<< (typename internal::WCharHelper< StringRef, Char >::Supported value)
 
template<typename T , typename Spec , typename FillChar >
BasicWriteroperator<< (IntFormatSpec< T, Spec, FillChar > spec)
 
template<typename StrChar >
BasicWriteroperator<< (const StrFormatSpec< StrChar > &spec)
 
void clear () FMT_NOEXCEPT
 

Protected Member Functions

 BasicWriter (Buffer< Char > &b)
 

Private Types

typedef internal::CharTraits
< Char >::CharPtr 
CharPtr
 

Private Member Functions

 FMT_DISALLOW_COPY_AND_ASSIGN (BasicWriter)
 
CharPtr grow_buffer (std::size_t n)
 
template<typename UInt >
Charwrite_unsigned_decimal (UInt value, unsigned prefix_size=0)
 
template<typename Int >
void write_decimal (Int value)
 
CharPtr prepare_int_buffer (unsigned num_digits, const EmptySpec &, const char *prefix, unsigned prefix_size)
 
template<typename Spec >
CharPtr prepare_int_buffer (unsigned num_digits, const Spec &spec, const char *prefix, unsigned prefix_size)
 
template<typename T , typename Spec >
void write_int (T value, Spec spec)
 
template<typename T >
void write_double (T value, const FormatSpec &spec)
 
template<typename StrChar >
CharPtr write_str (const StrChar *s, std::size_t size, const AlignSpec &spec)
 
template<typename StrChar >
void write_str (const internal::Arg::StringValue< StrChar > &str, const FormatSpec &spec)
 
void operator<< (typename internal::WCharHelper< wchar_t, Char >::Unsupported)
 
void operator<< (typename internal::WCharHelper< const wchar_t *, Char >::Unsupported)
 
void append_float_length (Char *&format_ptr, long double)
 
template<typename T >
void append_float_length (Char *&, T)
 

Static Private Member Functions

static Charget (Char *p)
 
static CharPtr fill_padding (CharPtr buffer, unsigned total_size, std::size_t content_size, wchar_t fill)
 

Private Attributes

Buffer< Char > & buffer_
 

Friends

template<typename Impl , typename Char_ >
class internal::ArgFormatterBase
 
class internal::PrintfArgFormatter< Char >
 

Detailed Description

template<typename Char>
class fmt::BasicWriter< Char >

This template provides operations for formatting and writing data into a character stream. The output is stored in a buffer provided by a subclass such as :class:fmt::BasicMemoryWriter.

You can use one of the following typedefs for common character types:

+------—+-------------------—+ | Type | Definition | +=========+======================+ | Writer | BasicWriter<char> | +------—+-------------------—+ | WWriter | BasicWriter<wchar_t> | +------—+-------------------—+

Member Typedef Documentation

template<typename Char>
typedef internal::CharTraits<Char>::CharPtr fmt::BasicWriter< Char >::CharPtr
private

Constructor & Destructor Documentation

template<typename Char>
fmt::BasicWriter< Char >::BasicWriter ( Buffer< Char > &  b)
inlineexplicitprotected

Constructs a BasicWriter object.

2317 : buffer_(b) {}
Buffer< Char > & buffer_
Definition: format.h:2214
template<typename Char>
virtual fmt::BasicWriter< Char >::~BasicWriter ( )
inlinevirtual

Destroys a BasicWriter object.

2325 {}

Member Function Documentation

template<typename Char>
void fmt::BasicWriter< Char >::append_float_length ( Char *&  format_ptr,
long  double 
)
inlineprivate
2301  {
2302  *format_ptr++ = 'L';
2303  }
template<typename Char>
template<typename T >
void fmt::BasicWriter< Char >::append_float_length ( Char *&  ,
 
)
inlineprivate
2306 {}
template<typename Char>
const Char* fmt::BasicWriter< Char >::c_str ( ) const
inline

Returns a pointer to the output buffer content with terminating null character appended.

2342  {
2343  std::size_t size = buffer_.size();
2344  buffer_.reserve(size + 1);
2345  buffer_[size] = '\0';
2346  return &buffer_[0];
2347  }
std::size_t size() const
Definition: format.h:2330
std::size_t size() const
Definition: format.h:605
void reserve(std::size_t capacity)
Definition: format.h:624
Buffer< Char > & buffer_
Definition: format.h:2214

+ Here is the call graph for this function:

template<typename Char>
void fmt::BasicWriter< Char >::clear ( )
inline
2478 { buffer_.clear(); }
void clear() FMT_NOEXCEPT
Definition: format.h:629
Buffer< Char > & buffer_
Definition: format.h:2214

+ Here is the call graph for this function:

template<typename Char>
const Char* fmt::BasicWriter< Char >::data ( ) const
inline

Returns a pointer to the output buffer content. No terminating null character is appended.

2336 { return &buffer_[0]; }
Buffer< Char > & buffer_
Definition: format.h:2214
template<typename Char >
BasicWriter< Char >::CharPtr fmt::BasicWriter< Char >::fill_padding ( CharPtr  buffer,
unsigned  total_size,
std::size_t  content_size,
wchar_t  fill 
)
staticprivate
2530  {
2531  std::size_t padding = total_size - content_size;
2532  std::size_t left_padding = padding / 2;
2533  Char fill_char = internal::CharTraits<Char>::cast(fill);
2534  std::uninitialized_fill_n(buffer, left_padding, fill_char);
2535  buffer += left_padding;
2536  CharPtr content = buffer;
2537  std::uninitialized_fill_n(buffer + content_size,
2538  padding - left_padding, fill_char);
2539  return content;
2540 }
char Char
Definition: bzlib_private.h:41
internal::CharTraits< Char >::CharPtr CharPtr
Definition: format.h:2218

+ Here is the caller graph for this function:

template<typename Char>
fmt::BasicWriter< Char >::FMT_DISALLOW_COPY_AND_ASSIGN ( BasicWriter< Char )
private
template<typename Char>
static Char* fmt::BasicWriter< Char >::get ( Char p)
inlinestaticprivate
2224 { return p; }
template<typename Char>
CharPtr fmt::BasicWriter< Char >::grow_buffer ( std::size_t  n)
inlineprivate
2234  {
2235  std::size_t size = buffer_.size();
2236  buffer_.resize(size + n);
2237  return internal::make_ptr(&buffer_[size], n);
2238  }
std::size_t size() const
Definition: format.h:2330
void resize(std::size_t new_size)
Definition: format.h:613
T * make_ptr(T *ptr, std::size_t)
Definition: format.h:571
std::size_t size() const
Definition: format.h:605
Buffer< Char > & buffer_
Definition: format.h:2214

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename Char>
void fmt::BasicWriter< Char >::operator<< ( typename internal::WCharHelper< wchar_t, Char >::Unsupported  )
private
template<typename Char>
void fmt::BasicWriter< Char >::operator<< ( typename internal::WCharHelper< const wchar_t *, Char >::Unsupported  )
private
template<typename Char>
BasicWriter& fmt::BasicWriter< Char >::operator<< ( int  value)
inline
2388  {
2390  return *this;
2391  }
void write_decimal(Int value)
Definition: format.h:2251
const FieldDescriptor value
Definition: descriptor.h:1522
template<typename Char>
BasicWriter& fmt::BasicWriter< Char >::operator<< ( unsigned  value)
inline
2392  {
2393  return *this << IntFormatSpec<unsigned>(value);
2394  }
const FieldDescriptor value
Definition: descriptor.h:1522
template<typename Char>
BasicWriter& fmt::BasicWriter< Char >::operator<< ( long  value)
inline
2395  {
2397  return *this;
2398  }
void write_decimal(Int value)
Definition: format.h:2251
const FieldDescriptor value
Definition: descriptor.h:1522
template<typename Char>
BasicWriter& fmt::BasicWriter< Char >::operator<< ( unsigned long  value)
inline
2399  {
2400  return *this << IntFormatSpec<unsigned long>(value);
2401  }
const FieldDescriptor value
Definition: descriptor.h:1522
template<typename Char>
BasicWriter& fmt::BasicWriter< Char >::operator<< ( LongLong  value)
inline
2402  {
2404  return *this;
2405  }
void write_decimal(Int value)
Definition: format.h:2251
const FieldDescriptor value
Definition: descriptor.h:1522
template<typename Char>
BasicWriter& fmt::BasicWriter< Char >::operator<< ( ULongLong  value)
inline

Formats value and writes it to the stream.

2412  {
2413  return *this << IntFormatSpec<ULongLong>(value);
2414  }
const FieldDescriptor value
Definition: descriptor.h:1522
template<typename Char>
BasicWriter& fmt::BasicWriter< Char >::operator<< ( double  value)
inline
2416  {
2417  write_double(value, FormatSpec());
2418  return *this;
2419  }
void write_double(T value, const FormatSpec &spec)
Definition: format.h:2690
const FieldDescriptor value
Definition: descriptor.h:1522
template<typename Char>
BasicWriter& fmt::BasicWriter< Char >::operator<< ( long double  value)
inline

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

2427  {
2428  write_double(value, FormatSpec());
2429  return *this;
2430  }
void write_double(T value, const FormatSpec &spec)
Definition: format.h:2690
const FieldDescriptor value
Definition: descriptor.h:1522
template<typename Char>
BasicWriter& fmt::BasicWriter< Char >::operator<< ( char  value)
inline

Writes a character to the stream.

2435  {
2437  return *this;
2438  }
void push_back(const T &value)
Definition: format.h:631
const FieldDescriptor value
Definition: descriptor.h:1522
Buffer< Char > & buffer_
Definition: format.h:2214

+ Here is the call graph for this function:

template<typename Char>
BasicWriter& fmt::BasicWriter< Char >::operator<< ( typename internal::WCharHelper< wchar_t, Char >::Supported  value)
inline
2441  {
2443  return *this;
2444  }
void push_back(const T &value)
Definition: format.h:631
const FieldDescriptor value
Definition: descriptor.h:1522
Buffer< Char > & buffer_
Definition: format.h:2214

+ Here is the call graph for this function:

template<typename Char>
BasicWriter& fmt::BasicWriter< Char >::operator<< ( fmt::BasicStringRef< Char value)
inline

Writes value to the stream.

2451  {
2452  const Char *str = value.data();
2453  buffer_.append(str, str + value.size());
2454  return *this;
2455  }
const Char * data() const
Definition: format.h:441
void append(const U *begin, const U *end)
Definition: format.h:647
char Char
Definition: bzlib_private.h:41
std::size_t size() const
Definition: format.h:444
std::basic_string< Char > str() const
Definition: format.h:2354
Buffer< Char > & buffer_
Definition: format.h:2214

+ Here is the call graph for this function:

template<typename Char>
BasicWriter& fmt::BasicWriter< Char >::operator<< ( typename internal::WCharHelper< StringRef, Char >::Supported  value)
inline
2458  {
2459  const char *str = value.data();
2460  buffer_.append(str, str + value.size());
2461  return *this;
2462  }
void append(const U *begin, const U *end)
Definition: format.h:647
std::basic_string< Char > str() const
Definition: format.h:2354
const FieldDescriptor value
Definition: descriptor.h:1522
Buffer< Char > & buffer_
Definition: format.h:2214

+ Here is the call graph for this function:

template<typename Char>
template<typename T , typename Spec , typename FillChar >
BasicWriter& fmt::BasicWriter< Char >::operator<< ( IntFormatSpec< T, Spec, FillChar >  spec)
inline
2465  {
2467  write_int(spec.value(), spec);
2468  return *this;
2469  }
void write_int(T value, Spec spec)
Definition: format.h:2608
No & convert(...)

+ Here is the call graph for this function:

template<typename Char>
template<typename StrChar >
BasicWriter& fmt::BasicWriter< Char >::operator<< ( const StrFormatSpec< StrChar > &  spec)
inline
2472  {
2473  const StrChar *s = spec.str();
2475  return *this;
2476  }
CharPtr write_str(const StrChar *s, std::size_t size, const AlignSpec &spec)
Definition: format.h:2483
float length(float v)
Definition: vectorMath.h:208

+ Here is the call graph for this function:

template<typename Char>
CharPtr fmt::BasicWriter< Char >::prepare_int_buffer ( unsigned  num_digits,
const EmptySpec ,
const char *  prefix,
unsigned  prefix_size 
)
inlineprivate
2264  {
2265  unsigned size = prefix_size + num_digits;
2266  CharPtr p = grow_buffer(size);
2267  std::uninitialized_copy(prefix, prefix + prefix_size, p);
2268  return p + size - 1;
2269  }
std::size_t size() const
Definition: format.h:2330
CharPtr grow_buffer(std::size_t n)
Definition: format.h:2234
internal::CharTraits< Char >::CharPtr CharPtr
Definition: format.h:2218
template<typename Char >
template<typename Spec >
BasicWriter< Char >::CharPtr fmt::BasicWriter< Char >::prepare_int_buffer ( unsigned  num_digits,
const Spec &  spec,
const char *  prefix,
unsigned  prefix_size 
)
private
2547  {
2548  unsigned width = spec.width();
2549  Alignment align = spec.align();
2550  Char fill = internal::CharTraits<Char>::cast(spec.fill());
2551  if (spec.precision() > static_cast<int>(num_digits)) {
2552  // Octal prefix '0' is counted as a digit, so ignore it if precision
2553  // is specified.
2554  if (prefix_size > 0 && prefix[prefix_size - 1] == '0')
2555  --prefix_size;
2556  unsigned number_size =
2557  prefix_size + internal::to_unsigned(spec.precision());
2558  AlignSpec subspec(number_size, '0', ALIGN_NUMERIC);
2559  if (number_size >= width)
2560  return prepare_int_buffer(num_digits, subspec, prefix, prefix_size);
2561  buffer_.reserve(width);
2562  unsigned fill_size = width - number_size;
2563  if (align != ALIGN_LEFT) {
2564  CharPtr p = grow_buffer(fill_size);
2565  std::uninitialized_fill(p, p + fill_size, fill);
2566  }
2567  CharPtr result = prepare_int_buffer(
2568  num_digits, subspec, prefix, prefix_size);
2569  if (align == ALIGN_LEFT) {
2570  CharPtr p = grow_buffer(fill_size);
2571  std::uninitialized_fill(p, p + fill_size, fill);
2572  }
2573  return result;
2574  }
2575  unsigned size = prefix_size + num_digits;
2576  if (width <= size) {
2577  CharPtr p = grow_buffer(size);
2578  std::uninitialized_copy(prefix, prefix + prefix_size, p);
2579  return p + size - 1;
2580  }
2581  CharPtr p = grow_buffer(width);
2582  CharPtr end = p + width;
2583  if (align == ALIGN_LEFT) {
2584  std::uninitialized_copy(prefix, prefix + prefix_size, p);
2585  p += size;
2586  std::uninitialized_fill(p, end, fill);
2587  } else if (align == ALIGN_CENTER) {
2588  p = fill_padding(p, width, size, fill);
2589  std::uninitialized_copy(prefix, prefix + prefix_size, p);
2590  p += size;
2591  } else {
2592  if (align == ALIGN_NUMERIC) {
2593  if (prefix_size != 0) {
2594  p = std::uninitialized_copy(prefix, prefix + prefix_size, p);
2595  size -= prefix_size;
2596  }
2597  } else {
2598  std::uninitialized_copy(prefix, prefix + prefix_size, end - size);
2599  }
2600  std::uninitialized_fill(p, end - size, fill);
2601  p = end;
2602  }
2603  return p - 1;
2604 }
std::size_t size() const
Definition: format.h:2330
CharPtr grow_buffer(std::size_t n)
Definition: format.h:2234
Definition: format.h:1460
Definition: format.h:1460
Alignment
Definition: format.h:1459
char Char
Definition: bzlib_private.h:41
internal::CharTraits< Char >::CharPtr CharPtr
Definition: format.h:2218
MakeUnsigned< Int >::Type to_unsigned(Int value)
Definition: format.h:554
void reserve(std::size_t capacity)
Definition: format.h:624
static CharPtr fill_padding(CharPtr buffer, unsigned total_size, std::size_t content_size, wchar_t fill)
Definition: format.h:2528
Definition: format.h:1460
Buffer< Char > & buffer_
Definition: format.h:2214
CharPtr prepare_int_buffer(unsigned num_digits, const EmptySpec &, const char *prefix, unsigned prefix_size)
Definition: format.h:2263

+ Here is the call graph for this function:

template<typename Char>
std::size_t fmt::BasicWriter< Char >::size ( ) const
inline

Returns the total number of characters written.

2330 { return buffer_.size(); }
std::size_t size() const
Definition: format.h:605
Buffer< Char > & buffer_
Definition: format.h:2214

+ Here is the call graph for this function:

template<typename Char>
std::basic_string<Char> fmt::BasicWriter< Char >::str ( ) const
inline

Returns the content of the output buffer as an std::string.

2354  {
2355  return std::basic_string<Char>(&buffer_[0], buffer_.size());
2356  }
Buffer< Char > & buffer_
Definition: format.h:2214

+ Here is the caller graph for this function:

template<typename Char>
void fmt::BasicWriter< Char >::write ( BasicCStringRef< Char format,
ArgList  args 
)
inline

Writes formatted data.

args* is an argument list representing arbitrary arguments.

Example**::

MemoryWriter out; out.write("Current point:\n"); out.write("({:+f}, {:+f})", -3.14, 3.14);

This will write the following output to the out object:

.. code-block:: none

Current point: (-3.140000, +3.140000)

The output can be accessed using :func:data(), :func:c_str or :func:str methods.

See also :ref:syntax.

2383  {
2384  BasicFormatter<Char>(args, *this).format(format);
2385  }
void format(BasicFormatter< Char > &f, const Char *&format_str, const T &value)
Definition: format.h:2963

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename Char>
template<typename Int >
void fmt::BasicWriter< Char >::write_decimal ( Int  value)
inlineprivate
2251  {
2252  typedef typename internal::IntTraits<Int>::MainType MainType;
2253  MainType abs_value = static_cast<MainType>(value);
2255  abs_value = 0 - abs_value;
2256  *write_unsigned_decimal(abs_value, 1) = '-';
2257  } else {
2258  write_unsigned_decimal(abs_value, 0);
2259  }
2260  }
bool is_negative(T value)
Definition: format.h:801
Char * write_unsigned_decimal(UInt value, unsigned prefix_size=0)
Definition: format.h:2242
const FieldDescriptor value
Definition: descriptor.h:1522

+ Here is the call graph for this function:

template<typename Char >
template<typename T >
void fmt::BasicWriter< Char >::write_double ( value,
const FormatSpec spec 
)
private
2690  {
2691  // Check type.
2692  char type = spec.type();
2693  bool upper = false;
2694  switch (type) {
2695  case 0:
2696  type = 'g';
2697  break;
2698  case 'e': case 'f': case 'g': case 'a':
2699  break;
2700  case 'F':
2701 #ifdef _MSC_VER
2702  // MSVC's printf doesn't support 'F'.
2703  type = 'f';
2704 #endif
2705  // Fall through.
2706  case 'E': case 'G': case 'A':
2707  upper = true;
2708  break;
2709  default:
2710  internal::report_unknown_type(type, "double");
2711  break;
2712  }
2713 
2714  char sign = 0;
2715  // Use isnegative instead of value < 0 because the latter is always
2716  // false for NaN.
2717  if (internal::FPUtil::isnegative(static_cast<double>(value))) {
2718  sign = '-';
2719  value = -value;
2720  } else if (spec.flag(SIGN_FLAG)) {
2721  sign = spec.flag(PLUS_FLAG) ? '+' : ' ';
2722  }
2723 
2725  // Format NaN ourselves because sprintf's output is not consistent
2726  // across platforms.
2727  std::size_t nan_size = 4;
2728  const char *nan = upper ? " NAN" : " nan";
2729  if (!sign) {
2730  --nan_size;
2731  ++nan;
2732  }
2733  CharPtr out = write_str(nan, nan_size, spec);
2734  if (sign)
2735  *out = sign;
2736  return;
2737  }
2738 
2740  // Format infinity ourselves because sprintf's output is not consistent
2741  // across platforms.
2742  std::size_t inf_size = 4;
2743  const char *inf = upper ? " INF" : " inf";
2744  if (!sign) {
2745  --inf_size;
2746  ++inf;
2747  }
2748  CharPtr out = write_str(inf, inf_size, spec);
2749  if (sign)
2750  *out = sign;
2751  return;
2752  }
2753 
2754  std::size_t offset = buffer_.size();
2755  unsigned width = spec.width();
2756  if (sign) {
2757  buffer_.reserve(buffer_.size() + (width > 1u ? width : 1u));
2758  if (width > 0)
2759  --width;
2760  ++offset;
2761  }
2762 
2763  // Build format string.
2764  enum { MAX_FORMAT_SIZE = 10}; // longest format: %#-*.*Lg
2765  Char format[MAX_FORMAT_SIZE];
2766  Char *format_ptr = format;
2767  *format_ptr++ = '%';
2768  unsigned width_for_sprintf = width;
2769  if (spec.flag(HASH_FLAG))
2770  *format_ptr++ = '#';
2771  if (spec.align() == ALIGN_CENTER) {
2772  width_for_sprintf = 0;
2773  } else {
2774  if (spec.align() == ALIGN_LEFT)
2775  *format_ptr++ = '-';
2776  if (width != 0)
2777  *format_ptr++ = '*';
2778  }
2779  if (spec.precision() >= 0) {
2780  *format_ptr++ = '.';
2781  *format_ptr++ = '*';
2782  }
2783 
2784  append_float_length(format_ptr, value);
2785  *format_ptr++ = type;
2786  *format_ptr = '\0';
2787 
2788  // Format using snprintf.
2789  Char fill = internal::CharTraits<Char>::cast(spec.fill());
2790  unsigned n = 0;
2791  Char *start = 0;
2792  for (;;) {
2793  std::size_t buffer_size = buffer_.capacity() - offset;
2794 #ifdef _MSC_VER
2795  // MSVC's vsnprintf_s doesn't work with zero size, so reserve
2796  // space for at least one extra character to make the size non-zero.
2797  // Note that the buffer's capacity will increase by more than 1.
2798  if (buffer_size == 0) {
2799  buffer_.reserve(offset + 1);
2800  buffer_size = buffer_.capacity() - offset;
2801  }
2802 #endif
2803  start = &buffer_[offset];
2804  int result = internal::CharTraits<Char>::format_float(
2805  start, buffer_size, format, width_for_sprintf, spec.precision(), value);
2806  if (result >= 0) {
2807  n = internal::to_unsigned(result);
2808  if (offset + n < buffer_.capacity())
2809  break; // The buffer is large enough - continue with formatting.
2810  buffer_.reserve(offset + n + 1);
2811  } else {
2812  // If result is negative we ask to increase the capacity by at least 1,
2813  // but as std::vector, the buffer grows exponentially.
2815  }
2816  }
2817  if (sign) {
2818  if ((spec.align() != ALIGN_RIGHT && spec.align() != ALIGN_DEFAULT) ||
2819  *start != ' ') {
2820  *(start - 1) = sign;
2821  sign = 0;
2822  } else {
2823  *(start - 1) = fill;
2824  }
2825  ++n;
2826  }
2827  if (spec.align() == ALIGN_CENTER && spec.width() > n) {
2828  width = spec.width();
2829  CharPtr p = grow_buffer(width);
2830  std::memmove(get(p) + (width - n) / 2, get(p), n * sizeof(Char));
2831  fill_padding(p, spec.width(), n, fill);
2832  return;
2833  }
2834  if (spec.fill() != ' ' || sign) {
2835  while (*start == ' ')
2836  *start++ = fill;
2837  if (sign)
2838  *(start - 1) = sign;
2839  }
2840  grow_buffer(n);
2841 }
void format(BasicFormatter< Char > &f, const Char *&format_str, const T &value)
Definition: format.h:2963
Definition: format.h:1460
CharPtr grow_buffer(std::size_t n)
Definition: format.h:2234
std::size_t capacity() const
Definition: format.h:608
Definition: format.h:1460
double inf()
Definition: g3dmath.cpp:40
char Char
Definition: bzlib_private.h:41
Definition: format.h:1465
static bool isinfinity(T x)
Definition: format.h:320
internal::CharTraits< Char >::CharPtr CharPtr
Definition: format.h:2218
std::size_t size() const
Definition: format.h:605
MakeUnsigned< Int >::Type to_unsigned(Int value)
Definition: format.h:554
CharPtr write_str(const StrChar *s, std::size_t size, const AlignSpec &spec)
Definition: format.h:2483
void append_float_length(Char *&format_ptr, long double)
Definition: format.h:2301
static bool isnotanumber(T x)
Definition: format.h:333
FMT_API void report_unknown_type(char code, const char *type)
Definition: format.h:1460
Definition: format.h:1465
void reserve(std::size_t capacity)
Definition: format.h:624
const FieldDescriptor value
Definition: descriptor.h:1522
static CharPtr fill_padding(CharPtr buffer, unsigned total_size, std::size_t content_size, wchar_t fill)
Definition: format.h:2528
static bool isnegative(double x)
Definition: format.h:343
Definition: format.h:1460
Buffer< Char > & buffer_
Definition: format.h:2214
double sign(double fValue)
Definition: g3dmath.h:669
double nan()
Definition: g3dmath.cpp:77
Definition: format.h:1465

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename Char >
template<typename T , typename Spec >
void fmt::BasicWriter< Char >::write_int ( value,
Spec  spec 
)
private
2608  {
2609  unsigned prefix_size = 0;
2610  typedef typename internal::IntTraits<T>::MainType UnsignedType;
2611  UnsignedType abs_value = static_cast<UnsignedType>(value);
2612  char prefix[4] = "";
2614  prefix[0] = '-';
2615  ++prefix_size;
2616  abs_value = 0 - abs_value;
2617  } else if (spec.flag(SIGN_FLAG)) {
2618  prefix[0] = spec.flag(PLUS_FLAG) ? '+' : ' ';
2619  ++prefix_size;
2620  }
2621  switch (spec.type()) {
2622  case 0: case 'd': {
2623  unsigned num_digits = internal::count_digits(abs_value);
2625  num_digits, spec, prefix, prefix_size) + 1 - num_digits;
2626  internal::format_decimal(get(p), abs_value, num_digits);
2627  break;
2628  }
2629  case 'x': case 'X': {
2630  UnsignedType n = abs_value;
2631  if (spec.flag(HASH_FLAG)) {
2632  prefix[prefix_size++] = '0';
2633  prefix[prefix_size++] = spec.type();
2634  }
2635  unsigned num_digits = 0;
2636  do {
2637  ++num_digits;
2638  } while ((n >>= 4) != 0);
2639  Char *p = get(prepare_int_buffer(
2640  num_digits, spec, prefix, prefix_size));
2641  n = abs_value;
2642  const char *digits = spec.type() == 'x' ?
2643  "0123456789abcdef" : "0123456789ABCDEF";
2644  do {
2645  *p-- = digits[n & 0xf];
2646  } while ((n >>= 4) != 0);
2647  break;
2648  }
2649  case 'b': case 'B': {
2650  UnsignedType n = abs_value;
2651  if (spec.flag(HASH_FLAG)) {
2652  prefix[prefix_size++] = '0';
2653  prefix[prefix_size++] = spec.type();
2654  }
2655  unsigned num_digits = 0;
2656  do {
2657  ++num_digits;
2658  } while ((n >>= 1) != 0);
2659  Char *p = get(prepare_int_buffer(num_digits, spec, prefix, prefix_size));
2660  n = abs_value;
2661  do {
2662  *p-- = static_cast<Char>('0' + (n & 1));
2663  } while ((n >>= 1) != 0);
2664  break;
2665  }
2666  case 'o': {
2667  UnsignedType n = abs_value;
2668  if (spec.flag(HASH_FLAG))
2669  prefix[prefix_size++] = '0';
2670  unsigned num_digits = 0;
2671  do {
2672  ++num_digits;
2673  } while ((n >>= 3) != 0);
2674  Char *p = get(prepare_int_buffer(num_digits, spec, prefix, prefix_size));
2675  n = abs_value;
2676  do {
2677  *p-- = static_cast<Char>('0' + (n & 7));
2678  } while ((n >>= 3) != 0);
2679  break;
2680  }
2681  default:
2683  spec.type(), spec.flag(CHAR_FLAG) ? "char" : "integer");
2684  break;
2685  }
2686 }
bool is_negative(T value)
Definition: format.h:801
char Char
Definition: bzlib_private.h:41
Definition: format.h:1465
internal::CharTraits< Char >::CharPtr CharPtr
Definition: format.h:2218
FMT_API void report_unknown_type(char code, const char *type)
unsigned count_digits(uint64_t n)
Definition: format.h:844
Definition: format.h:1465
Definition: format.h:1466
const FieldDescriptor value
Definition: descriptor.h:1522
void format_decimal(Char *buffer, UInt value, unsigned num_digits)
Definition: format.h:870
Definition: format.h:1465
CharPtr prepare_int_buffer(unsigned num_digits, const EmptySpec &, const char *prefix, unsigned prefix_size)
Definition: format.h:2263

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename Char >
template<typename StrChar >
BasicWriter< Char >::CharPtr fmt::BasicWriter< Char >::write_str ( const StrChar *  s,
std::size_t  size,
const AlignSpec spec 
)
private
2484  {
2485  CharPtr out = CharPtr();
2486  if (spec.width() > size) {
2487  out = grow_buffer(spec.width());
2488  Char fill = internal::CharTraits<Char>::cast(spec.fill());
2489  if (spec.align() == ALIGN_RIGHT) {
2490  std::uninitialized_fill_n(out, spec.width() - size, fill);
2491  out += spec.width() - size;
2492  } else if (spec.align() == ALIGN_CENTER) {
2493  out = fill_padding(out, spec.width(), size, fill);
2494  } else {
2495  std::uninitialized_fill_n(out + size, spec.width() - size, fill);
2496  }
2497  } else {
2498  out = grow_buffer(size);
2499  }
2500  std::uninitialized_copy(s, s + size, out);
2501  return out;
2502 }
std::size_t size() const
Definition: format.h:2330
Definition: format.h:1460
CharPtr grow_buffer(std::size_t n)
Definition: format.h:2234
char Char
Definition: bzlib_private.h:41
internal::CharTraits< Char >::CharPtr CharPtr
Definition: format.h:2218
static CharPtr fill_padding(CharPtr buffer, unsigned total_size, std::size_t content_size, wchar_t fill)
Definition: format.h:2528
Definition: format.h:1460

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename Char >
template<typename StrChar >
void fmt::BasicWriter< Char >::write_str ( const internal::Arg::StringValue< StrChar > &  str,
const FormatSpec spec 
)
private
2507  {
2508  // Check if StrChar is convertible to Char.
2510  if (spec.type_ && spec.type_ != 's')
2511  internal::report_unknown_type(spec.type_, "string");
2512  const StrChar *str_value = s.value;
2513  std::size_t str_size = s.size;
2514  if (str_size == 0) {
2515  if (!str_value) {
2516  FMT_THROW(FormatError("string pointer is null"));
2517  return;
2518  }
2519  }
2520  std::size_t precision = static_cast<std::size_t>(spec.precision_);
2521  if (spec.precision_ >= 0 && precision < str_size)
2522  str_size = precision;
2523  write_str(str_value, str_size, spec);
2524 }
CharPtr write_str(const StrChar *s, std::size_t size, const AlignSpec &spec)
Definition: format.h:2483
FMT_API void report_unknown_type(char code, const char *type)
No & convert(...)
#define FMT_THROW(x)
Definition: format.h:166

+ Here is the call graph for this function:

template<typename Char>
template<typename UInt >
Char* fmt::BasicWriter< Char >::write_unsigned_decimal ( UInt  value,
unsigned  prefix_size = 0 
)
inlineprivate
2242  {
2243  unsigned num_digits = internal::count_digits(value);
2244  Char *ptr = get(grow_buffer(prefix_size + num_digits));
2245  internal::format_decimal(ptr + prefix_size, value, num_digits);
2246  return ptr;
2247  }
CharPtr grow_buffer(std::size_t n)
Definition: format.h:2234
char Char
Definition: bzlib_private.h:41
unsigned count_digits(uint64_t n)
Definition: format.h:844
const FieldDescriptor value
Definition: descriptor.h:1522
void format_decimal(Char *buffer, UInt value, unsigned num_digits)
Definition: format.h:870

+ Here is the call graph for this function:

Friends And Related Function Documentation

template<typename Char>
template<typename Impl , typename Char_ >
friend class internal::ArgFormatterBase
friend
template<typename Char>
friend class internal::PrintfArgFormatter< Char >
friend

Member Data Documentation

template<typename Char>
Buffer<Char>& fmt::BasicWriter< Char >::buffer_
private

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