foobar2000 SDK  2015-01-14
Public Member Functions | Private Attributes
pfc::format_int

#include <string_base.h>

Public Member Functions

 format_int (t_int64 p_val, unsigned p_width=0, unsigned p_base=10)
 
 format_int (const format_int &p_source)
 
const char * get_ptr () const
 
 operator const char * () const
 
const char * toString () const
 

Private Attributes

char m_buffer [64]
 

Detailed Description

Definition at line 562 of file string_base.h.

Constructor & Destructor Documentation

pfc::format_int::format_int ( t_int64  p_val,
unsigned  p_width = 0,
unsigned  p_base = 10 
)

Definition at line 608 of file string_base.cpp.

609 {
610  bool neg = false;
611  t_uint64 val;
612  if (p_val < 0) {neg = true; val = (t_uint64)(-p_val);}
613  else val = (t_uint64)p_val;
614 
615  enum {max_width = PFC_TABSIZE(m_buffer) - 1};
616 
617  if (p_width > max_width) p_width = max_width;
618  else if (p_width == 0) p_width = 1;
619 
620  if (neg && p_width > 1) p_width --;
621 
622  char temp[max_width];
623 
624  unsigned n;
625  for(n=0;n<max_width;n++)
626  {
627  temp[max_width-1-n] = format_hex_char((unsigned)(val % p_base));
628  val /= p_base;
629  }
630 
631  for(n=0;n<max_width && temp[n] == '0';n++) {}
632 
633  if (n > max_width - p_width) n = max_width - p_width;
634 
635  char * out = m_buffer;
636 
637  if (neg) *(out++) = '-';
638 
639  for(;n<max_width;n++)
640  *(out++) = temp[n];
641  *out = 0;
642 }
uint64_t t_uint64
Definition: int_types.h:3
char m_buffer[64]
Definition: string_base.h:571
char format_hex_char(unsigned p_val)
pfc::format_int::format_int ( const format_int p_source)
inline

Definition at line 566 of file string_base.h.

566 {*this = p_source;}

Member Function Documentation

const char* pfc::format_int::get_ptr ( ) const
inline

Definition at line 567 of file string_base.h.

567 {return m_buffer;}
char m_buffer[64]
Definition: string_base.h:571
pfc::format_int::operator const char * ( ) const
inline

Definition at line 569 of file string_base.h.

569 {return m_buffer;}
char m_buffer[64]
Definition: string_base.h:571
const char* pfc::format_int::toString ( ) const
inline

Definition at line 568 of file string_base.h.

568 {return m_buffer;}
char m_buffer[64]
Definition: string_base.h:571

Field Documentation

char pfc::format_int::m_buffer[64]
private

Definition at line 571 of file string_base.h.


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