farm-ng-core
format.h File Reference
#include <farm_ng/core/logging/backtrace.h>
#include <farm_pp/preprocessor/comparison/equal.hpp>
#include <farm_pp/preprocessor/control/if.hpp>
#include <farm_pp/preprocessor/variadic/size.hpp>
#include <fmt/core.h>
#include <fmt/format.h>
#include <fmt/ostream.h>
#include <functional>
#include <iostream>
Include dependency graph for format.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 farm_ng
 
 farm_ng::details
 

Macros

#define FARM_STRING(x)   x
 
#define FARM_IMPL_LOG_PRINTLN_ZERO()
 
#define FARM_IMPL_LOG_PRINTLN_ONE(cstr)   farm_ng::logLine(FARM_STRING(cstr))
 
#define FARM_IMPL_LOG_PRINTLN_ARGS(cstr, ...)   farm_ng::logLine(::fmt::format(FMT_STRING(cstr), __VA_ARGS__))
 
#define FARM_IMPL_LOG_PRINTLN_VARG(cstr, ...)
 
#define FARM_IMPL_LOG_PRINTLN(...)
 
#define FARM_IMPL_ABORT()
 
#define FARM_RUNTIME_FORMAT(str, ...)   ::farm_ng::details::runtimeFormatImpl(__FILE__, __LINE__, str, __VA_ARGS__)
 Formats the cstr using the libfmt library. More...
 
#define FARM_IMPL_FORMAT_ARGS(cstr, ...)   FARM_RUNTIME_FORMAT(cstr, __VA_ARGS__)
 
#define FARM_IMPL_FORMAT_VARG(cstr, ...)
 
#define FARM_FORMAT(...)
 Formats the cstr using the libfmt library. More...
 

Functions

void farm_ng::setLogLineFunction (std::function< void(std::string const &)> f)
 
void farm_ng::logLine (std::string const &line)
 
template<class... TArgs>
std::string farm_ng::details::runtimeFormatImpl (std::string const &file, int line, std::string const &str, TArgs &&...args)
 

Variables

std::function< void(std::string const &)> & farm_ng::getLogLineFunction ()
 

Macro Definition Documentation

◆ FARM_FORMAT

#define FARM_FORMAT (   ...)
Value:
FARM_PP_IF( \
FARM_PP_EQUAL(FARM_PP_VARIADIC_SIZE(dummy, ##__VA_ARGS__), 1), \
std::string(), \
FARM_IMPL_FORMAT_VARG(__VA_ARGS__))

Formats the cstr using the libfmt library.

See here for details: https://fmt.dev/latest/syntax.html

Note that compile-time format check is performed, and hence cstr needs to be a string literal. If no compile-time check is required, and/or the string is a variable, call FARM_RUNTIME_FORMAT(fmt, ...) instead.

FARM_COMPILE_TIME_FMT is not defined, the runtime version will be used, to speed up compile times.

◆ FARM_IMPL_ABORT

#define FARM_IMPL_ABORT ( )
Value:
do { \
::std::abort(); \
} while (false)

◆ FARM_IMPL_FORMAT_ARGS

#define FARM_IMPL_FORMAT_ARGS (   cstr,
  ... 
)    FARM_RUNTIME_FORMAT(cstr, __VA_ARGS__)

◆ FARM_IMPL_FORMAT_VARG

#define FARM_IMPL_FORMAT_VARG (   cstr,
  ... 
)
Value:
FARM_PP_IF( \
FARM_PP_EQUAL(FARM_PP_VARIADIC_SIZE(cstr, ##__VA_ARGS__), 1), \
std::string(cstr), \
FARM_IMPL_FORMAT_ARGS(cstr, ##__VA_ARGS__))

◆ FARM_IMPL_LOG_PRINTLN

#define FARM_IMPL_LOG_PRINTLN (   ...)
Value:
FARM_PP_IF( \
FARM_PP_EQUAL(FARM_PP_VARIADIC_SIZE(dummy, ##__VA_ARGS__), 1), \

◆ FARM_IMPL_LOG_PRINTLN_ARGS

#define FARM_IMPL_LOG_PRINTLN_ARGS (   cstr,
  ... 
)    farm_ng::logLine(::fmt::format(FMT_STRING(cstr), __VA_ARGS__))

◆ FARM_IMPL_LOG_PRINTLN_ONE

#define FARM_IMPL_LOG_PRINTLN_ONE (   cstr)    farm_ng::logLine(FARM_STRING(cstr))

◆ FARM_IMPL_LOG_PRINTLN_VARG

#define FARM_IMPL_LOG_PRINTLN_VARG (   cstr,
  ... 
)
Value:
FARM_PP_IF( \
FARM_PP_EQUAL(FARM_PP_VARIADIC_SIZE(cstr, ##__VA_ARGS__), 1), \
FARM_IMPL_LOG_PRINTLN_ARGS(cstr, ##__VA_ARGS__))

◆ FARM_IMPL_LOG_PRINTLN_ZERO

#define FARM_IMPL_LOG_PRINTLN_ZERO ( )

◆ FARM_RUNTIME_FORMAT

#define FARM_RUNTIME_FORMAT (   str,
  ... 
)    ::farm_ng::details::runtimeFormatImpl(__FILE__, __LINE__, str, __VA_ARGS__)

Formats the cstr using the libfmt library.

See here for details: https://fmt.dev/latest/syntax.html

If str is cstring literal, call FARM_FORMAT instead, and the format will be checked at compile time.

◆ FARM_STRING

#define FARM_STRING (   x)    x
FARM_IMPL_LOG_PRINTLN_ONE
#define FARM_IMPL_LOG_PRINTLN_ONE(cstr)
Definition: format.h:45
FARM_IMPL_LOG_PRINTLN_ZERO
#define FARM_IMPL_LOG_PRINTLN_ZERO()
Definition: format.h:43
FARM_IMPL_LOG_PRINTLN_VARG
#define FARM_IMPL_LOG_PRINTLN_VARG(cstr,...)
Definition: format.h:50
FARM_IMPL_LOG_PRINTLN_ARGS
#define FARM_IMPL_LOG_PRINTLN_ARGS(cstr,...)
Definition: format.h:47
farm_ng::printBacktrace
void printBacktrace()
Definition: backtrace.cpp:103
FARM_IMPL_FORMAT_ARGS
#define FARM_IMPL_FORMAT_ARGS(cstr,...)
Definition: format.h:105
FARM_IMPL_FORMAT_VARG
#define FARM_IMPL_FORMAT_VARG(cstr,...)
Definition: format.h:108