medfall

A super great game engine
Log | Files | Refs

commit bd903388b4b1d7aa8eb4dff5df81c7ed7755c531
parent 89afa331fadbbfca8e2dc8a57a8be8ace72e99c5
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun, 29 Oct 2017 09:53:50 +0200

Allow ggformat on DynamicString

Diffstat:
dynstr.h | 10+++++++---
ggformat.h | 14+++++++-------
log.cc | 2+-
str.h | 6+++---
4 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/dynstr.h b/dynstr.h @@ -10,7 +10,7 @@ public: DynamicString() { } template< typename... Rest > - DynamicString( const char * fmt, Rest... rest ) { + DynamicString( const char * fmt, const Rest & ... rest ) { sprintf( fmt, rest... ); } @@ -30,14 +30,14 @@ public: } template< typename... Rest > - void sprintf( const char * fmt, Rest... rest ) { + void sprintf( const char * fmt, const Rest & ... rest ) { size_t len = ggformat( NULL, 0, fmt, rest... ); buf.resize( len + 1 ); ggformat( &buf[ 0 ], len + 1, fmt, rest... ); } template< typename... Rest > - void appendf( const char * fmt, Rest... rest ) { + void appendf( const char * fmt, const Rest & ... rest ) { size_t len = ggformat( NULL, 0, fmt, rest... ); size_t old_len = length(); buf.extend( old_len == 0 ? len + 1 : len ); @@ -59,3 +59,7 @@ public: private: DynamicArray< char > buf; }; + +void format( FormatBuffer * fb, const DynamicString & str, const FormatOpts & opts ) { + format( fb, str.c_str(), opts ); +} diff --git a/ggformat.h b/ggformat.h @@ -8,13 +8,13 @@ */ template< typename... Rest > -size_t ggformat( char * buf, size_t len, const char * fmt, Rest... rest ); +size_t ggformat( char * buf, size_t len, const char * fmt, const Rest & ... rest ); template< typename... Rest > -bool ggprint_to_file( FILE * file, const char * fmt, Rest... rest ); +bool ggprint_to_file( FILE * file, const char * fmt, const Rest & ... rest ); template< typename... Rest > -bool ggprint( const char * fmt, Rest... rest ); +bool ggprint( const char * fmt, const Rest & ... rest ); /* * structures and functions used for formatting specific data types @@ -78,7 +78,7 @@ void ggformat_literals( FormatBuffer * fb, const char * literals, size_t len ); PRAGMA_DISABLE_OPTIMISATIONS(); template< typename T, typename... Rest > -void ggformat_impl( FormatBuffer * fb, const char * fmt, const T & first, Rest... rest ) { +void ggformat_impl( FormatBuffer * fb, const char * fmt, const T & first, const Rest & ... rest ) { size_t start, one_past_end; bool has_fmt = ggformat_find( fmt, &start, &one_past_end ); ASSERT( has_fmt ); @@ -92,14 +92,14 @@ void ggformat_impl( FormatBuffer * fb, const char * fmt, const T & first, Rest.. } template< typename... Rest > -size_t ggformat( char * buf, size_t len, const char * fmt, Rest... rest ) { +size_t ggformat( char * buf, size_t len, const char * fmt, const Rest & ... rest ) { FormatBuffer fb( buf, len ); ggformat_impl( &fb, fmt, rest... ); return fb.len; } template< typename... Rest > -bool ggprint_to_file( FILE * file, const char * fmt, Rest... rest ) { +bool ggprint_to_file( FILE * file, const char * fmt, const Rest & ... rest ) { char buf[ 4096 ]; FormatBuffer fb( buf, sizeof( buf ) ); ggformat_impl( &fb, fmt, rest... ); @@ -120,7 +120,7 @@ bool ggprint_to_file( FILE * file, const char * fmt, Rest... rest ) { } template< typename... Rest > -bool ggprint( const char * fmt, Rest... rest ) { +bool ggprint( const char * fmt, const Rest & ... rest ) { return ggprint_to_file( stdout, fmt, rest... ); } diff --git a/log.cc b/log.cc @@ -40,7 +40,7 @@ void logger_init() { mkdir( logs_dir.c_str(), 0755 ); for( u32 i = 0; i <= LOGLEVEL_COUNT; i++ ) { - const str< 256 > path( "{}/{}.log", logs_dir.c_str(), file_names[ i ] ); + const str< 256 > path( "{}/{}.log", logs_dir, file_names[ i ] ); streams[ i ] = fopen( path.c_str(), "w" ); ASSERT( streams[ i ] != NULL ); } diff --git a/str.h b/str.h @@ -18,7 +18,7 @@ public: } template< typename... Rest > - str( const char * fmt, Rest... rest ) { + str( const char * fmt, const Rest & ... rest ) { sprintf( fmt, rest... ); } @@ -33,13 +33,13 @@ public: } template< typename... Rest > - void sprintf( const char * fmt, Rest... rest ) { + void sprintf( const char * fmt, const Rest & ... rest ) { size_t copied = ggformat( buf, N, fmt, rest... ); length = min( copied, N - 1 ); } template< typename... Rest > - void appendf( const char * fmt, Rest... rest ) { + void appendf( const char * fmt, const Rest & ... rest ) { size_t copied = ggformat( buf + length, N - length, fmt, rest... ); length += min( copied, N - length - 1 ); }