VLink  2.0.0
A high-performance communication middleware
format.h File Reference

Minimal heap-free {} placeholder formatter for the logger hot path. More...

#include <cstddef>
#include <cstdint>
#include <cstring>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>
#include "./macros.h"
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.

Classes

struct  vlink::format::detail::IsOutputIteratorImpl< TypeT, typename >
 
struct  vlink::format::detail::IsOutputIteratorImpl< TypeT, std::enable_if_t< std::is_assignable_v< decltype(*std::declval< TypeT & >()++), char > > >
 
struct  vlink::format::detail::IsOutputIteratorImpl< char * >
 
struct  vlink::format::detail::IsOutputIteratorImpl< TypeT[NumT]>
 
struct  vlink::format::detail::TypeConstant< T >
 
struct  vlink::format::detail::TypeConstant< signed char >
 
struct  vlink::format::detail::TypeConstant< unsigned char >
 
struct  vlink::format::detail::TypeConstant< short >
 
struct  vlink::format::detail::TypeConstant< unsigned short >
 
struct  vlink::format::detail::TypeConstant< int >
 
struct  vlink::format::detail::TypeConstant< unsigned >
 
struct  vlink::format::detail::TypeConstant< long >
 
struct  vlink::format::detail::TypeConstant< unsigned long >
 
struct  vlink::format::detail::TypeConstant< long long >
 
struct  vlink::format::detail::TypeConstant< unsigned long long >
 
struct  vlink::format::detail::TypeConstant< bool >
 
struct  vlink::format::detail::TypeConstant< char >
 
struct  vlink::format::detail::TypeConstant< float >
 
struct  vlink::format::detail::TypeConstant< double >
 
struct  vlink::format::detail::TypeConstant< const char * >
 
struct  vlink::format::detail::TypeConstant< char * >
 
struct  vlink::format::detail::TypeConstant< std::string_view >
 
struct  vlink::format::detail::TypeConstant< std::string >
 
struct  vlink::format::detail::TypeConstant< char[NumT]>
 
struct  vlink::format::detail::TypeConstant< const char[NumT]>
 
struct  vlink::format::detail::TypeConstant< T * >
 
class  vlink::format::detail::StringWriter
 
class  vlink::format::detail::IteratorWriter< OutputItT >
 
class  vlink::format::detail::Value< CharT >
 
class  vlink::format::detail::FormatArg< CharT >
 
struct  vlink::format::detail::FormatArgStore< CharT, ArgsT >
 
class  vlink::format::detail::BasicFormatArgs< CharT >
 
class  vlink::format::detail::FormatWriter< CharT, WriterT >
 
struct  vlink::format::FString< ArgsT >
 Compile-time format-string wrapper carrying the expected argument list. More...
 
struct  vlink::format::FormatToNResult< OutputItT >
 Return type of format_to_n; carries the end iterator, total size and truncation flag. More...
 
struct  vlink::format::FormatToResult
 Return type of the fixed-array format_to overload. More...
 

Namespaces

 
 
 

Typedefs

template<typename TypeT >
using vlink::format::detail::RemoveCvref = typename std::remove_cv_t< std::remove_reference_t< TypeT > >
 
using vlink::format::detail::FormatArgs = BasicFormatArgs< char >
 
template<typename... ArgsT>
using vlink::format::format_string = typename FString< ArgsT... >::t
 Convenience alias used as the formal type of format-string parameters. More...
 

Enumerations

enum class  vlink::format::detail::Type : uint8_t {
  vlink::format::detail::kNone , vlink::format::detail::kInt , vlink::format::detail::kUint , vlink::format::detail::kLongLong ,
  vlink::format::detail::kUlongLong , vlink::format::detail::kBool , vlink::format::detail::kChar , vlink::format::detail::kFloat ,
  vlink::format::detail::kDouble , vlink::format::detail::kString , vlink::format::detail::kCstring , vlink::format::detail::kPointer
}
 

Functions

VLINK_EXPORT size_t vlink::format::detail::format_uint_to (char *buf, unsigned value) noexcept
 
VLINK_EXPORT size_t vlink::format::detail::format_int_to (char *buf, int value) noexcept
 
VLINK_EXPORT size_t vlink::format::detail::format_ulong_long_to (char *buf, unsigned long long value) noexcept
 
VLINK_EXPORT size_t vlink::format::detail::format_long_long_to (char *buf, long long value) noexcept
 
VLINK_EXPORT size_t vlink::format::detail::format_pointer_to (char *buf, const void *ptr) noexcept
 
VLINK_EXPORT size_t vlink::format::detail::format_float_to (char *buf, size_t buflen, float value) noexcept
 
VLINK_EXPORT size_t vlink::format::detail::format_double_to (char *buf, size_t buflen, double value) noexcept
 
template<typename... ArgsT>
detail::FormatArgStore< char, detail::RemoveCvref< ArgsT >... > vlink::format::make_format_args (const ArgsT &... args)
 Public API. More...
 
template<typename... ArgsT>
FormatToNResult< char * > vlink::format::format_to_n (char *out, size_t n, format_string< ArgsT... > fmt, const ArgsT &... args)
 Formats args into out, writing at most n characters. More...
 
template<size_t NumT, typename... ArgsT>
FormatToResult vlink::format::format_to (char(&out)[NumT], format_string< ArgsT... > fmt, const ArgsT &... args)
 Formats args into a fixed-size character array; equivalent to format_to_n. More...
 
template<typename OutputItT , typename... ArgsT, std::enable_if_t< detail::kIsOutputIterator< detail::RemoveCvref< OutputItT >> &&!std::is_array_v< std::remove_reference_t< OutputItT >>, int > = 0>
detail::RemoveCvref< OutputItT > vlink::format::format_to (OutputItT &&out, format_string< ArgsT... > fmt, const ArgsT &... args)
 Formats args through an output iterator. More...
 

Variables

template<typename TypeT >
constexpr bool vlink::format::detail::kIsOutputIterator = IsOutputIteratorImpl<TypeT>::value
 

Detailed Description

Minimal heap-free {} placeholder formatter for the logger hot path.

VLink targets C++17 first; std::format is unavailable on that baseline and far heavier on older standards. This header provides a focused subset of std::format-style formatting that writes through a stack-allocated buffer or a user-supplied output iterator, never allocates, and dispatches via a compile-time type tag rather than a virtual call chain.

Supported argument types
C++ type Format token Example output
signed char / short / int {} 42
unsigned char / ... {} 42
long / long long {} 123456789
unsigned long / long long {} 123456789
bool {} true / false
char {} A
float / double {} 3.14
const char* / char* {} hello
std::string / std::string_view {} hello
T* (any pointer) {} 0x7ffe1234
enum {} underlying integer
Placeholder syntax
Token Meaning
{} Consume the next argument in order
{0}, {1}, ... Explicit positional index
{{ / }} Literal opening / closing brace
Public API
Function Output target Truncation flag
format_to_n(out, n, fmt, ...) char* buffer with cap n yes
format_to(out[N], fmt, ...) Fixed-size array yes
format_to(it, fmt, ...) Output iterator no
Example
char buf[128];
auto result = vlink::format::format_to_n(buf, sizeof(buf) - 1, "x={} y={}", 3, 4.5);
buf[result.size] = '\0';
// buf == "x=3 y=4.5"
Note
Floats and doubles use "%g" via snprintf; there is no precision modifier in the placeholder syntax. Unsupported argument types trigger a compile-time static_assert.