Use cppformat to implement writelogf
This represents the first use of variadic templates in Cantera.
This commit is contained in:
parent
61c522d7a7
commit
61a755ff51
2 changed files with 5 additions and 22 deletions
|
|
@ -20,6 +20,7 @@
|
|||
#define CT_GLOBAL_H
|
||||
|
||||
#include "ct_defs.h"
|
||||
#include "cantera/ext/format.h"
|
||||
|
||||
namespace Cantera
|
||||
{
|
||||
|
|
@ -164,7 +165,10 @@ inline void writelog(const std::string& msg, int loglevel)
|
|||
* @param fmt c format string for the following arguments
|
||||
* @ingroup textlogs
|
||||
*/
|
||||
void writelogf(const char* fmt,...);
|
||||
template <typename... Args>
|
||||
void writelogf(const char* fmt, const Args& ... args) {
|
||||
writelog(fmt::sprintf(fmt, args...));
|
||||
}
|
||||
|
||||
//! Write an end of line character to the screen and flush output
|
||||
void writelogendl();
|
||||
|
|
|
|||
|
|
@ -5,9 +5,6 @@
|
|||
#include "application.h"
|
||||
#include "units.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <stdarg.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Cantera
|
||||
|
|
@ -35,24 +32,6 @@ void writelog(const std::string& msg)
|
|||
app()->writelog(msg);
|
||||
}
|
||||
|
||||
void writelogf(const char* fmt,...)
|
||||
{
|
||||
enum { BUFSIZE = 2048 };
|
||||
char sbuf[BUFSIZE];
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
_vsnprintf(sbuf, BUFSIZE, fmt, args);
|
||||
#else
|
||||
vsprintf(sbuf, fmt, args);
|
||||
#endif
|
||||
|
||||
writelog(sbuf);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void writelogendl()
|
||||
{
|
||||
app()->writelogendl();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue