Skip to content

Commit

Permalink
Update fmt to v5.0.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
scamille committed Jun 9, 2018
1 parent 45b234c commit 1533293
Show file tree
Hide file tree
Showing 30 changed files with 5,463 additions and 4,502 deletions.
3 changes: 2 additions & 1 deletion engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ file(GLOB_RECURSE engine_source *.cpp)
# Define engine library
add_library(engine ${engine_source})
target_link_libraries(engine Threads::Threads)
target_include_directories(engine PUBLIC ./)
target_include_directories(engine PUBLIC ./)
target_include_directories(engine PUBLIC ./util/)
2 changes: 1 addition & 1 deletion engine/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ endif

MKDIR = mkdir
CXX = g++
CPP_FLAGS = -Wall -Wextra -W -I. -DSC_SHARED_DATA=\"$(SHARED_DATA)\" --std=c++11 -O3 -MMD -MP \
CPP_FLAGS = -Wall -Wextra -W -I. -I./util -DSC_SHARED_DATA=\"$(SHARED_DATA)\" --std=c++11 -O3 -MMD -MP \
-Wpedantic \
-Wcast-qual \
-Wconversion-null \
Expand Down
9 changes: 4 additions & 5 deletions engine/report/sc_highchart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,11 @@ template <typename Stream>
bool sc_json_writer_t<Stream>::Double( double d )
{
this->Prefix( rapidjson::kNumberType );
std::array<char, 100> buffer;
fmt::ArrayWriter w( buffer.data(), buffer.size() );
w.write("{:.{}f}", d, sim.report_precision );
for ( unsigned i = 0; i < w.size(); ++i )
fmt::memory_buffer buffer;
fmt::format_to(buffer, "{:.{}f}", d, sim.report_precision );
for ( unsigned i = 0; i < buffer.size(); ++i )
{
this->os_->Put( w.data()[ i ] );
this->os_->Put( buffer.data()[ i ] );
}
return true;
}
12 changes: 6 additions & 6 deletions engine/sc_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ int to_int( const char* str );

int64_t parse_date( const std::string& month_day_year );

template<typename... Args>
int printf(fmt::CStringRef format, Args&& ... args)
template<typename Format, typename... Args>
int printf(Format&& format, Args&& ... args)
{
return fmt::printf(format, std::forward<Args>(args)... );
return fmt::printf(std::forward<Format>(format), std::forward<Args>(args)... );
}
template<typename... Args>
int fprintf(std::FILE* stream, fmt::CStringRef format, Args&& ... args)
template<typename Format, typename... Args>
int fprintf(std::FILE* stream, Format&& format, Args&& ... args)
{
return fmt::fprintf(stream, format, std::forward<Args>(args)... );
return fmt::fprintf(stream, std::forward<Format>(format), std::forward<Args>(args)... );
}

std::string encode_html( const std::string& );
Expand Down
32 changes: 16 additions & 16 deletions engine/sim/sc_progress_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,18 @@ bool progress_bar_t::update_normal( const sim_progress_t& progress, bool finishe
}

size_t prev_size = status.size();
fmt::MemoryWriter new_status;
fmt::memory_buffer new_status;

int progress_length = static_cast<int>( steps * pct + 0.5 );
if ( progress_length >= 1 )
{
new_status.write("[{:=>{}s}", ">", progress_length);
new_status.write("{:.>{}}]", "", steps - progress_length);
fmt::format_to(new_status, "[{:=>{}s}", ">", progress_length);
fmt::format_to(new_status, "{:.>{}}]", "", steps - progress_length);
}
else
{
new_status.write("[{:=>{}}", "", progress_length);
new_status.write("{:.>{}}]", "", steps - progress_length);
fmt::format_to(new_status, "[{:=>{}}", "", progress_length);
fmt::format_to(new_status, "{:.>{}}]", "", steps - progress_length);
}

double current_time = util::wall_time() - start_time;
Expand All @@ -233,21 +233,21 @@ bool progress_bar_t::update_normal( const sim_progress_t& progress, bool finishe
int remaining_min = remaining_sec / 60;
remaining_sec -= remaining_min * 60;

new_status.write(" {:d}/{:d}", finished ? progress.total_iterations : progress.current_iterations, progress.total_iterations );
fmt::format_to(new_status, " {:d}/{:d}", finished ? progress.total_iterations : progress.current_iterations, progress.total_iterations );

if ( sim.target_error > 0 )
{
new_status.write(" Mean={:.0f} Error={:.3f}%", sim.current_mean, sim.current_error );
fmt::format_to(new_status, " Mean={:.0f} Error={:.3f}%", sim.current_mean, sim.current_error );
}

if ( remaining_min > 0 )
{
new_status.write(" {:d}min", remaining_min );
fmt::format_to(new_status, " {:d}min", remaining_min );
}

if ( remaining_sec > 0 )
{
new_status.write(" {:d}sec", remaining_sec );
fmt::format_to(new_status, " {:d}sec", remaining_sec );
}

if ( finished )
Expand All @@ -257,22 +257,22 @@ bool progress_bar_t::update_normal( const sim_progress_t& progress, bool finishe
int total_msec = gsl::narrow_cast<int>(1000 * ( current_time - static_cast<int>( current_time ) ));
if ( total_min > 0 )
{
new_status.write(" {:d}min", total_min );
fmt::format_to(new_status, " {:d}min", total_min );
}

if ( total_sec > 0 )
{
new_status.write(" {:d}", total_sec );
fmt::format_to(new_status, " {:d}", total_sec );
if ( total_msec > 0 )
{
new_status.write(".{:d}", total_msec );
fmt::format_to(new_status, ".{:d}", total_msec );
}

status += "sec";
}
else if ( total_msec > 0 )
{
new_status.write(" {:d}msec", total_msec );
fmt::format_to(new_status, " {:d}msec", total_msec );
}
}

Expand All @@ -285,16 +285,16 @@ bool progress_bar_t::update_normal( const sim_progress_t& progress, bool finishe

if ( total_left > 0 )
{
new_status.write(" ({:s})", format_time( total_left ));
fmt::format_to(new_status, " ({:s})", format_time( total_left ));
}
}

if ( prev_size > new_status.size() )
{
new_status.write("{:<{}}", " ", prev_size - new_status.size() );
fmt::format_to(new_status, "{:<{}}", " ", prev_size - new_status.size() );
}

status = new_status.str();
status = fmt::to_string(new_status);

return true;
}
Expand Down
46 changes: 23 additions & 23 deletions engine/simulationcraft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,10 @@ struct sc_raw_ostream_t {
sc_raw_ostream_t & operator<< (T const& rhs)
{ (*_stream) << rhs; return *this; }

template<typename... Args>
sc_raw_ostream_t& printf(fmt::CStringRef format, Args&& ... args)
template<typename Format, typename... Args>
sc_raw_ostream_t& printf(Format&& format, Args&& ... args)
{
fmt::fprintf(*get_stream(), format, std::forward<Args>(args)... );
fmt::fprintf(*get_stream(), std::forward<Format>(format), std::forward<Args>(args)... );
return *this;
}

Expand Down Expand Up @@ -835,16 +835,16 @@ struct sim_ostream_t
template <class T>
sim_ostream_t & operator<< (T const& rhs);

template<typename... Args>
sim_ostream_t& printf(fmt::CStringRef format, Args&& ... args);
template<typename Format, typename... Args>
sim_ostream_t& printf(Format&& format, Args&& ... args);

/**
* Print using fmt libraries python-like formatting syntax.
*/
template<typename... Args>
sim_ostream_t& print(fmt::CStringRef format, Args&& ... args)
template<typename Format, typename... Args>
sim_ostream_t& print(Format&& format, Args&& ... args)
{
*this << fmt::format(format, std::forward<Args>(args)... );
*this << fmt::format(std::forward<Format>(format), std::forward<Args>(args)... );
return *this;
}
private:
Expand Down Expand Up @@ -1333,13 +1333,13 @@ struct sim_t : private sc_thread_t
/**
* Create error with printf formatting.
*/
template<typename... Args>
void errorf(fmt::CStringRef format, Args&& ... args)
template<typename Format, typename... Args>
void errorf(Format&& format, Args&& ... args)
{
if ( thread_index != 0 )
return;

auto s = fmt::sprintf(format, std::forward<Args>(args)... );
auto s = fmt::sprintf(std::forward<Format>(format), std::forward<Args>(args)... );
util::replace_all( s, "\n", "" );
std::cerr << s << "\n";

Expand All @@ -1349,13 +1349,13 @@ struct sim_t : private sc_thread_t
/**
* Create error using fmt libraries python-like formatting syntax.
*/
template<typename... Args>
void error(fmt::CStringRef format, Args&& ... args)
template<typename Format, typename... Args>
void error(Format&& format, Args&& ... args)
{
if ( thread_index != 0 )
return;

auto s = fmt::format(format, std::forward<Args>(args)... );
auto s = fmt::format(std::forward<Format>(format), std::forward<Args>(args)... );
util::replace_all( s, "\n", "" );
std::cerr << s << "\n";

Expand Down Expand Up @@ -1402,13 +1402,13 @@ struct sim_t : private sc_thread_t
* Checks if sim debug is enabled.
* Print using fmt libraries python-like formatting syntax.
*/
template<typename... Args>
void print_debug(fmt::CStringRef format, Args&& ... args)
template<typename Format, typename... Args>
void print_debug(Format&& format, Args&& ... args)
{
if ( ! debug )
return;

out_debug.print(format, std::forward<Args>(args)... );
out_debug.print(std::forward<Format>(format), std::forward<Args>(args)... );
}

/**
Expand All @@ -1417,13 +1417,13 @@ struct sim_t : private sc_thread_t
* Checks if sim logging is enabled.
* Print using fmt libraries python-like formatting syntax.
*/
template<typename... Args>
void print_log(fmt::CStringRef format, Args&& ... args)
template<typename Format, typename... Args>
void print_log(Format&& format, Args&& ... args)
{
if ( ! log )
return;

out_log.print(format, std::forward<Args>(args)... );
out_log.print(std::forward<Format>(format), std::forward<Args>(args)... );
}
private:
void do_pause();
Expand Down Expand Up @@ -7602,11 +7602,11 @@ sim_ostream_t& sim_ostream_t::operator<< (T const& rhs)
return *this;
}

template<typename... Args>
sim_ostream_t& sim_ostream_t::printf(fmt::CStringRef format, Args&& ... args)
template<typename Format, typename... Args>
sim_ostream_t& sim_ostream_t::printf(Format&& format, Args&& ... args)
{
_raw << util::to_string( sim.current_time().total_seconds(), 3 ) << " ";
fmt::fprintf(*_raw.get_stream(), format, std::forward<Args>(args)... );
fmt::fprintf(*_raw.get_stream(), std::forward<Format>(format), std::forward<Args>(args)... );
_raw << "\n";
return *this;
}
Expand Down
94 changes: 0 additions & 94 deletions engine/util/fmt/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion engine/util/fmt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ std::string s = fmt::format("{0}{1}{0}", "abra", "cad");

SimC Integration:
-----------------
* Release 4.1.0 from https://github.com/fmtlib/fmt/releases/tag/4.1.0
* Release 5.0.0 from https://github.com/fmtlib/fmt/releases/tag/5.0.0
* rename .cc files to .cpp for simpler integration into our build systems.
Loading

0 comments on commit 1533293

Please sign in to comment.