added: to Log: IntMinWidth(size_t min_width)
minimal width for integers added: to Log: operator<<(long long s) added: to TextStreamBase: operator<<(long long); operator<<(unsigned long long); int_min_width(size_t min_width); // minimal width for integers git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1167 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
e9df044f9e
commit
5a63a8c0ec
22
log/log.cpp
22
log/log.cpp
|
@ -99,6 +99,17 @@ FileLog * Log::GetFileLog()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Log & Log::IntMinWidth(size_t min_width)
|
||||||
|
{
|
||||||
|
if( buffer )
|
||||||
|
{
|
||||||
|
buffer->int_min_width(min_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(const void * s)
|
Log & Log::operator<<(const void * s)
|
||||||
{
|
{
|
||||||
if( buffer && file_log && current_level <= file_log->get_log_level() )
|
if( buffer && file_log && current_level <= file_log->get_log_level() )
|
||||||
|
@ -211,6 +222,16 @@ Log & Log::operator<<(long s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Log & Log::operator<<(long long s)
|
||||||
|
{
|
||||||
|
if( buffer && file_log && current_level <= file_log->get_log_level() )
|
||||||
|
{
|
||||||
|
(*buffer) << s;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log & Log::operator<<(char s)
|
Log & Log::operator<<(char s)
|
||||||
|
@ -442,7 +463,6 @@ void Log::save_log()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,8 @@ public:
|
||||||
void SetMaxBufferLength(size_t max_buffer_length);
|
void SetMaxBufferLength(size_t max_buffer_length);
|
||||||
size_t GetMaxBufferLength();
|
size_t GetMaxBufferLength();
|
||||||
|
|
||||||
|
virtual Log & IntMinWidth(size_t min_width);
|
||||||
|
|
||||||
virtual Log & operator<<(const void * s);
|
virtual Log & operator<<(const void * s);
|
||||||
|
|
||||||
virtual Log & operator<<(const char * s);
|
virtual Log & operator<<(const char * s);
|
||||||
|
@ -111,7 +113,7 @@ public:
|
||||||
|
|
||||||
virtual Log & operator<<(int s);
|
virtual Log & operator<<(int s);
|
||||||
virtual Log & operator<<(long s);
|
virtual Log & operator<<(long s);
|
||||||
//virtual Log & operator<<(long long s); // added
|
virtual Log & operator<<(long long s);
|
||||||
|
|
||||||
|
|
||||||
// add unsigned long, unsigned int
|
// add unsigned long, unsigned int
|
||||||
|
|
|
@ -100,13 +100,20 @@ public:
|
||||||
TextStreamBase & operator<<(wchar_t);
|
TextStreamBase & operator<<(wchar_t);
|
||||||
TextStreamBase & operator<<(int);
|
TextStreamBase & operator<<(int);
|
||||||
TextStreamBase & operator<<(long);
|
TextStreamBase & operator<<(long);
|
||||||
|
TextStreamBase & operator<<(long long);
|
||||||
TextStreamBase & operator<<(unsigned int);
|
TextStreamBase & operator<<(unsigned int);
|
||||||
TextStreamBase & operator<<(unsigned long);
|
TextStreamBase & operator<<(unsigned long);
|
||||||
|
TextStreamBase & operator<<(unsigned long long);
|
||||||
TextStreamBase & operator<<(double);
|
TextStreamBase & operator<<(double);
|
||||||
TextStreamBase & operator<<(const void *); // printing a pointer
|
TextStreamBase & operator<<(const void *); // printing a pointer
|
||||||
TextStreamBase & operator<<(const PT::Space & space);
|
TextStreamBase & operator<<(const PT::Space & space);
|
||||||
TextStreamBase & operator<<(const PT::Date & date);
|
TextStreamBase & operator<<(const PT::Date & date);
|
||||||
|
|
||||||
|
// min width for integer output
|
||||||
|
// if the output value has less digits then first zeroes are added
|
||||||
|
// (0 turn off)
|
||||||
|
TextStreamBase & int_min_width(size_t min_width);
|
||||||
|
|
||||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
||||||
TextStreamBase & operator<<(const TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg);
|
TextStreamBase & operator<<(const TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> & arg);
|
||||||
|
|
||||||
|
@ -118,10 +125,13 @@ public:
|
||||||
TextStreamBase & write(const char * format, double val);
|
TextStreamBase & write(const char * format, double val);
|
||||||
TextStreamBase & write(const wchar_t * format, double val);
|
TextStreamBase & write(const wchar_t * format, double val);
|
||||||
|
|
||||||
|
TextStreamBase & fill_up_if_needed(wchar_t fill_up_char, size_t existing_length);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
raw access
|
raw access
|
||||||
*/
|
*/
|
||||||
int radix;
|
int radix;
|
||||||
|
size_t min_width_for_integers;
|
||||||
buffer_type buffer;
|
buffer_type buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -133,13 +143,15 @@ public:
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
TextStreamBase<char_type, stack_size, heap_block_size>::TextStreamBase()
|
TextStreamBase<char_type, stack_size, heap_block_size>::TextStreamBase()
|
||||||
{
|
{
|
||||||
radix = 10;
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
void TextStreamBase<char_type, stack_size, heap_block_size>::clear()
|
void TextStreamBase<char_type, stack_size, heap_block_size>::clear()
|
||||||
{
|
{
|
||||||
|
radix = 10;
|
||||||
|
min_width_for_integers = 0;
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,20 +335,31 @@ template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
TextStreamBase<char_type, stack_size, heap_block_size> &
|
TextStreamBase<char_type, stack_size, heap_block_size> &
|
||||||
TextStreamBase<char_type, stack_size, heap_block_size>::operator<<(int v)
|
TextStreamBase<char_type, stack_size, heap_block_size>::operator<<(int v)
|
||||||
{
|
{
|
||||||
return operator<<(static_cast<long>(v));
|
return operator<<(static_cast<long long>(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
TextStreamBase<char_type, stack_size, heap_block_size> &
|
TextStreamBase<char_type, stack_size, heap_block_size> &
|
||||||
TextStreamBase<char_type, stack_size, heap_block_size>::operator<<(long v)
|
TextStreamBase<char_type, stack_size, heap_block_size>::operator<<(long v)
|
||||||
|
{
|
||||||
|
return operator<<(static_cast<long long>(v));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
|
TextStreamBase<char_type, stack_size, heap_block_size> &
|
||||||
|
TextStreamBase<char_type, stack_size, heap_block_size>::operator<<(long long v)
|
||||||
{
|
{
|
||||||
char_type buf[50];
|
char_type buf[50];
|
||||||
size_t len = sizeof(buf) / sizeof(char_type);
|
size_t len = sizeof(buf) / sizeof(char_type);
|
||||||
size_t lenout;
|
size_t lenout;
|
||||||
|
|
||||||
if( Toa(v, buf, len, radix, &lenout) )
|
if( Toa(v, buf, len, radix, &lenout) )
|
||||||
|
{
|
||||||
|
fill_up_if_needed('0', lenout);
|
||||||
buffer.append(buf, lenout);
|
buffer.append(buf, lenout);
|
||||||
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -346,20 +369,31 @@ template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
TextStreamBase<char_type, stack_size, heap_block_size> &
|
TextStreamBase<char_type, stack_size, heap_block_size> &
|
||||||
TextStreamBase<char_type, stack_size, heap_block_size>::operator<<(unsigned int v)
|
TextStreamBase<char_type, stack_size, heap_block_size>::operator<<(unsigned int v)
|
||||||
{
|
{
|
||||||
return operator<<(static_cast<unsigned long>(v));
|
return operator<<(static_cast<unsigned long long>(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
TextStreamBase<char_type, stack_size, heap_block_size> &
|
TextStreamBase<char_type, stack_size, heap_block_size> &
|
||||||
TextStreamBase<char_type, stack_size, heap_block_size>::operator<<(unsigned long v)
|
TextStreamBase<char_type, stack_size, heap_block_size>::operator<<(unsigned long v)
|
||||||
|
{
|
||||||
|
return operator<<(static_cast<unsigned long long>(v));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
|
TextStreamBase<char_type, stack_size, heap_block_size> &
|
||||||
|
TextStreamBase<char_type, stack_size, heap_block_size>::operator<<(unsigned long long v)
|
||||||
{
|
{
|
||||||
char_type buf[50];
|
char_type buf[50];
|
||||||
size_t len = sizeof(buf) / sizeof(char_type);
|
size_t len = sizeof(buf) / sizeof(char_type);
|
||||||
size_t lenout;
|
size_t lenout;
|
||||||
|
|
||||||
if( Toa(v, buf, len, radix, &lenout) )
|
if( Toa(v, buf, len, radix, &lenout) )
|
||||||
|
{
|
||||||
|
fill_up_if_needed('0', lenout);
|
||||||
buffer.append(buf, lenout);
|
buffer.append(buf, lenout);
|
||||||
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -387,7 +421,8 @@ size_t lenout;
|
||||||
buf[0] = '0';
|
buf[0] = '0';
|
||||||
buf[1] = 'x';
|
buf[1] = 'x';
|
||||||
|
|
||||||
if( Toa(reinterpret_cast<unsigned long>(v), buf+2, len-2, 16, &lenout) )
|
// IMPROVE ME add some minimal width?
|
||||||
|
if( Toa(reinterpret_cast<unsigned long long>(v), buf+2, len-2, 16, &lenout) )
|
||||||
buffer.append(buf, lenout+2);
|
buffer.append(buf, lenout+2);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -464,6 +499,32 @@ return *this;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
|
TextStreamBase<char_type, stack_size, heap_block_size> &
|
||||||
|
TextStreamBase<char_type, stack_size, heap_block_size>::int_min_width(size_t min_width)
|
||||||
|
{
|
||||||
|
min_width_for_integers = min_width;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||||
|
TextStreamBase<char_type, stack_size, heap_block_size> &
|
||||||
|
TextStreamBase<char_type, stack_size, heap_block_size>::fill_up_if_needed(wchar_t fill_up_char, size_t existing_length)
|
||||||
|
{
|
||||||
|
if( min_width_for_integers > 0 && min_width_for_integers > existing_length )
|
||||||
|
{
|
||||||
|
for(size_t i = existing_length ; i < min_width_for_integers ; ++i)
|
||||||
|
{
|
||||||
|
buffer.append(fill_up_char);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue