TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
fmt::FormatInt Class Reference

#include <format.h>

Public Member Functions

 FormatInt (int value)
 
 FormatInt (long value)
 
 FormatInt (LongLong value)
 
 FormatInt (unsigned value)
 
 FormatInt (unsigned long value)
 
 FormatInt (ULongLong value)
 
std::size_t size () const
 
const char * data () const
 
const char * c_str () const
 
std::string str () const
 

Private Types

enum  { BUFFER_SIZE = std::numeric_limits<ULongLong>::digits10 + 3 }
 

Private Member Functions

char * format_decimal (ULongLong value)
 
void FormatSigned (LongLong value)
 

Private Attributes

char buffer_ [BUFFER_SIZE]
 
char * str_
 

Detailed Description

Fast integer formatter.

Member Enumeration Documentation

anonymous enum
private
Enumerator
BUFFER_SIZE 
3139 {BUFFER_SIZE = std::numeric_limits<ULongLong>::digits10 + 3};
Definition: format.h:3139

Constructor & Destructor Documentation

fmt::FormatInt::FormatInt ( int  value)
inlineexplicit
3176 { FormatSigned(value); }
void FormatSigned(LongLong value)
Definition: format.h:3165
const FieldDescriptor value
Definition: descriptor.h:1522
fmt::FormatInt::FormatInt ( long  value)
inlineexplicit
3177 { FormatSigned(value); }
void FormatSigned(LongLong value)
Definition: format.h:3165
const FieldDescriptor value
Definition: descriptor.h:1522
fmt::FormatInt::FormatInt ( LongLong  value)
inlineexplicit
3178 { FormatSigned(value); }
void FormatSigned(LongLong value)
Definition: format.h:3165
const FieldDescriptor value
Definition: descriptor.h:1522
fmt::FormatInt::FormatInt ( unsigned  value)
inlineexplicit
3179 : str_(format_decimal(value)) {}
char * str_
Definition: format.h:3141
char * format_decimal(ULongLong value)
Definition: format.h:3144
const FieldDescriptor value
Definition: descriptor.h:1522
fmt::FormatInt::FormatInt ( unsigned long  value)
inlineexplicit
3180 : str_(format_decimal(value)) {}
char * str_
Definition: format.h:3141
char * format_decimal(ULongLong value)
Definition: format.h:3144
const FieldDescriptor value
Definition: descriptor.h:1522
fmt::FormatInt::FormatInt ( ULongLong  value)
inlineexplicit
3181 : str_(format_decimal(value)) {}
char * str_
Definition: format.h:3141
char * format_decimal(ULongLong value)
Definition: format.h:3144
const FieldDescriptor value
Definition: descriptor.h:1522

Member Function Documentation

const char* fmt::FormatInt::c_str ( ) const
inline

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

3198  {
3199  buffer_[BUFFER_SIZE - 1] = '\0';
3200  return str_;
3201  }
char * str_
Definition: format.h:3141
char buffer_[BUFFER_SIZE]
Definition: format.h:3140
Definition: format.h:3139
const char* fmt::FormatInt::data ( ) const
inline

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

3192 { return str_; }
char * str_
Definition: format.h:3141
char* fmt::FormatInt::format_decimal ( ULongLong  value)
inlineprivate
3144  {
3145  char *buffer_end = buffer_ + BUFFER_SIZE - 1;
3146  while (value >= 100) {
3147  // Integer division is slow so do it for a group of two digits instead
3148  // of for every digit. The idea comes from the talk by Alexandrescu
3149  // "Three Optimization Tips for C++". See speed-test for a comparison.
3150  unsigned index = static_cast<unsigned>((value % 100) * 2);
3151  value /= 100;
3152  *--buffer_end = internal::Data::DIGITS[index + 1];
3153  *--buffer_end = internal::Data::DIGITS[index];
3154  }
3155  if (value < 10) {
3156  *--buffer_end = static_cast<char>('0' + value);
3157  return buffer_end;
3158  }
3159  unsigned index = static_cast<unsigned>(value * 2);
3160  *--buffer_end = internal::Data::DIGITS[index + 1];
3161  *--buffer_end = internal::Data::DIGITS[index];
3162  return buffer_end;
3163  }
char buffer_[BUFFER_SIZE]
Definition: format.h:3140
static const char DIGITS[]
Definition: format.h:828
const FieldDescriptor value
Definition: descriptor.h:1522
Definition: format.h:3139
void fmt::FormatInt::FormatSigned ( LongLong  value)
inlineprivate
3165  {
3166  ULongLong abs_value = static_cast<ULongLong>(value);
3167  bool negative = value < 0;
3168  if (negative)
3169  abs_value = 0 - abs_value;
3170  str_ = format_decimal(abs_value);
3171  if (negative)
3172  *--str_ = '-';
3173  }
FMT_GCC_EXTENSION typedef unsigned long long ULongLong
Definition: format.h:362
char * str_
Definition: format.h:3141
char * format_decimal(ULongLong value)
Definition: format.h:3144
const FieldDescriptor value
Definition: descriptor.h:1522

+ Here is the call graph for this function:

std::size_t fmt::FormatInt::size ( ) const
inline

Returns the number of characters written to the output buffer.

3184  {
3186  }
char * str_
Definition: format.h:3141
char buffer_[BUFFER_SIZE]
Definition: format.h:3140
MakeUnsigned< Int >::Type to_unsigned(Int value)
Definition: format.h:554
Definition: format.h:3139

+ Here is the call graph for this function:

std::string fmt::FormatInt::str ( ) const
inline

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

3208 { return std::string(str_, size()); }
char * str_
Definition: format.h:3141
std::size_t size() const
Definition: format.h:3184

Member Data Documentation

char fmt::FormatInt::buffer_[BUFFER_SIZE]
mutableprivate
char* fmt::FormatInt::str_
private

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