VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
format.h 文件参考

Lightweight header-only {} placeholder formatter with no dynamic allocation. 更多...

#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>
#include "./macros.h"
format.h 的引用(Include)关系图:
此图展示该文件被哪些文件直接或间接地引用了:

浏览该文件的源代码.

 Compile-time format string wrapper that carries type information about arguments. 更多...
 Result type for format_to_n, carrying the output pointer, written size and truncation flag. 更多...
 Result type for the fixed-array overload of format_to. 更多...

命名空间

类型定义

template<typename T>
using vlink::format::detail::RemoveCvref = typename std::remove_cv_t<std::remove_reference_t<T>>
using vlink::format::detail::FormatArgs = BasicFormatArgs<char>
template<typename... T>
using vlink::format::format_string = typename FString<T...>::t
 Alias for FString used as the type of format-string parameters.

枚举

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
}

函数

template<typename UIntT>
int vlink::format::detail::count_digits (UIntT n)
template<typename CharT, typename UIntT>
CharT * vlink::format::detail::write_int_digits (CharT *buf, UIntT value, int num_digits)
template<typename... ArgsT>
detail::FormatArgStore< char, detail::RemoveCvref< ArgsT >... > vlink::format::make_format_args (const ArgsT &... args)
 Creates a type-erased argument store from a variadic argument list.
template<typename... ArgsT>
FormatToNResult< char * > vlink::format::format_to_n (char *out, size_t n, format_string< ArgsT... > fmt, const ArgsT &... args)
 Formats arguments into a char* buffer, writing at most n characters.
template<size_t N, typename... ArgsT>
FormatToResult vlink::format::format_to (char(&out)[N], format_string< ArgsT... > fmt, const ArgsT &... args)
 Formats arguments into a fixed-size char array.
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 arguments to an output iterator.

变量

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

详细描述

Lightweight header-only {} placeholder formatter with no dynamic allocation.

This namespace provides a minimal subset of std::format-compatible formatting for use inside the VLink logger hot path where <format> may be unavailable (C++17) or too heavyweight. All formatting writes through a stack-allocated writer or a user-supplied output iterator and never touches the heap.

Supported argument types:

C++ type Format token Example output
int / short / signed char {} 42
unsigned / unsigned short / ... {} 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 (any) {} underlying int

Placeholder syntax:

  • {} – consume arguments in order.
  • {0}, {1}, ... – explicit positional indexing.
  • {{ / }} – literal brace.

Public API:

  • format_to_n(out, n, fmt, args...) – writes at most n chars into a char* buffer.
  • format_to(out[N], fmt, args...) – writes into a fixed array.
  • format_to(iterator, fmt, args...) – writes to an output iterator.
注解
  • Float and double are formatted via snprintf with "%g". There is no precision specifier in the placeholder syntax.
  • Custom types (those not listed above) trigger a static_assert at compile time.
  • Truncated format_to_n results set the truncated flag in the returned struct.
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"