LibSWOC++ 1.5.14
Solid Wall of C++
Loading...
Searching...
No Matches
bwf_base.h File Reference
#include <cstdlib>
#include <utility>
#include <cstring>
#include <vector>
#include <unordered_map>
#include <string>
#include <iosfwd>
#include <string_view>
#include <functional>
#include <tuple>
#include <any>
#include <array>
#include "swoc/swoc_version.h"
#include "swoc/TextView.h"
#include "swoc/MemSpan.h"
#include "swoc/MemArena.h"
#include "swoc/BufferWriter.h"
#include "swoc/swoc_meta.h"
Include dependency graph for bwf_base.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  swoc::bwf::Spec
 
struct  swoc::bwf::Spec::Property
 Handrolled initialization the character syntactic property data. More...
 
struct  swoc::bwf::Format
 
struct  swoc::bwf::Format::TextViewExtractor
 Extraction support for TextView. More...
 
struct  swoc::bwf::Format::FormatExtractor
 Extraction support for pre-parsed format strings. More...
 
class  swoc::bwf::NameBinding
 
class  swoc::bwf::NilBinding
 
class  swoc::bwf::NameMap< F >
 
class  swoc::bwf::ExternalNames
 
class  swoc::bwf::ContextNames< T >
 
class  swoc::bwf::ContextNames< T >::Binding
 Specialized binding for names in an instance of ContextNames. More...
 
class  swoc::bwf::ArgPack
 
class  swoc::bwf::ArgTuple< Args >
 
struct  swoc::bwf::HexDump
 

Namespaces

namespace  swoc
 For template deduction guides.
 

Typedefs

using swoc::bwf::ExternalGeneratorSignature = BufferWriter &(BufferWriter &w, Spec const &spec)
 
template<typename TUPLE>
using swoc::bwf::ArgFormatterSignature = BufferWriter &(*)(BufferWriter &w, Spec const &, TUPLE const &args)
 — Formatting —
 
template<typename T>
using swoc::bwf::TupleAccessorSignature = std::any (*)(T const &t)
 The signature for accessing an element of a tuple.
 

Functions

ExternalNamesswoc::bwf::Global_Names ()
 
void swoc::bwf::Err_Bad_Arg_Index (BufferWriter &w, int i, size_t n)
 Internal error / reporting message generators.
 
template<typename TUPLE, size_t I>
BufferWriterswoc::bwf::Arg_Formatter (BufferWriter &w, Spec const &spec, TUPLE const &args)
 
template<typename TUPLE, size_t... N>
ArgFormatterSignature< TUPLE > * swoc::bwf::Get_Arg_Formatter_Array (std::index_sequence< N... >)
 
void swoc::bwf::Adjust_Alignment (BufferWriter &aux, Spec const &spec)
 
BufferWriterswoc::bwf::Format_Integer (BufferWriter &w, Spec const &spec, uintmax_t i, bool neg_p)
 
BufferWriterswoc::bwf::Format_Float (BufferWriter &w, Spec const &spec, double f, bool negative_p)
 
void swoc::bwf::Format_As_Hex (BufferWriter &w, std::string_view view, const char *digits)
 
template<size_t IDX, typename T>
std::any swoc::bwf::TupleAccessor (T const &t)
 Template access method.
 
template<typename T, size_t... N>
std::array< TupleAccessorSignature< T >, sizeof...(N)> & swoc::bwf::Tuple_Accessor_Array (std::index_sequence< N... >)
 Create and return an array of specialized accessors, indexed by tuple index.
 
template<typename T>
std::any swoc::bwf::Tuple_Nth (T const &t, size_t idx)
 Get the Nth element of the tuple as std::any.
 
template<typename F>
auto swoc::bwf::arg_capture (F &&, BufferWriter &, Spec const &, std::any &&, swoc::meta::CaseTag< 0 >) -> void
 
template<typename F>
auto swoc::bwf::arg_capture (F &&f, BufferWriter &w, Spec const &spec, std::any &&value, swoc::meta::CaseTag< 1 >) -> decltype(f.capture(w, spec, value))
 
template<typename EXTRACTOR, typename VIEW, typename SPEC>
auto swoc::bwf::extractor_spec_type (bool(EXTRACTOR::*)(VIEW, SPEC)) -> SPEC
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, std::string_view sv)
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, const void *ptr)
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, MemSpan< void const > const &span)
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, MemSpan< void > const &span)
 
template<typename T>
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, MemSpan< T > const &span)
 
template<size_t N>
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, const char(&a)[N])
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, std::nullptr_t)
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, const char *v)
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, std::string const &s)
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, TextView tv)
 
template<typename X, typename V>
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &, TransformView< X, V > &&view)
 
template<typename F>
auto swoc::bwformat (BufferWriter &w, bwf::Spec const &spec, F &&f) -> typename std::enable_if< std::is_floating_point_v< typename std::remove_reference_t< F > >, BufferWriter & >::type
 
template<typename I>
auto swoc::bwformat (BufferWriter &w, bwf::Spec const &spec, I &&i) -> typename std::enable_if< std::is_unsigned< typename std::remove_reference< I >::type >::value &&std::is_integral< typename std::remove_reference< I >::type >::value, BufferWriter & >::type
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &, char c)
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, bool f)
 
template<typename... Args>
std::string & swoc::bwprint_v (std::string &s, TextView fmt, std::tuple< Args... > const &args)
 
template<typename... Args>
std::string & swoc::bwprint (std::string &s, TextView fmt, Args &&...args)
 
template<typename... Args>
std::string & swoc::bwappend (std::string &s, TextView fmt, Args &&...args)
 
template<typename T>
auto swoc::detail::tag_label (BufferWriter &, const bwf::Spec &, meta::CaseTag< 0 >) -> void
 
template<typename T>
auto swoc::detail::tag_label (BufferWriter &w, const bwf::Spec &, meta::CaseTag< 1 >) -> decltype(T::label, meta::TypeFunc< void >())
 
template<intmax_t N, typename C, typename T>
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, Scalar< N, C, T > const &x)
 
template<typename V>
BufferWriterswoc::operator<< (BufferWriter &w, V &&v)
 
template<typename T>
HexDump swoc::bwf::As_Hex (T const &t)
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, bwf::HexDump const &hex)
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, BufferWriter const &ww)
 

Detailed Description

Basic formatting support for BufferWriter.

Definition in file bwf_base.h.

Typedef Documentation

◆ ArgFormatterSignature

template<typename TUPLE>
using swoc::bwf::ArgFormatterSignature = BufferWriter &(*)(BufferWriter &w, Spec const &, TUPLE const &args)

— Formatting —

Internal signature for template generated formatting. args is a forwarded tuple of arguments to be processed.

Definition at line 640 of file bwf_base.h.

◆ ExternalGeneratorSignature

using swoc::bwf::ExternalGeneratorSignature = BufferWriter &(BufferWriter &w, Spec const &spec)

Signature for a functor bound to a name.

Parameters
wThe output.
specThe format specifier.

The functor is expected to write to w based on spec.

Definition at line 241 of file bwf_base.h.

◆ TupleAccessorSignature

template<typename T>
using swoc::bwf::TupleAccessorSignature = std::any (*)(T const &t)

The signature for accessing an element of a tuple.

Definition at line 720 of file bwf_base.h.

Function Documentation

◆ Adjust_Alignment()

void swoc::bwf::Adjust_Alignment ( BufferWriter & aux,
Spec const & spec )

This performs generic alignment operations.

If a formatter specialization performs this operation instead, that should result in output that is at least spec._min characters wide, which will cause this function to make no further adjustments.

Perform alignment adjustments / fill on w of the content in lw. This is the normal mechanism, in cases where the length can be known or limited before conversion, it can be more efficient to work in a temporary local buffer and copy out as needed without moving data in the output buffer.

Definition at line 276 of file bw_format.cc.

◆ arg_capture() [1/2]

template<typename F>
auto swoc::bwf::arg_capture ( F && ,
BufferWriter & ,
Spec const & ,
std::any && ,
swoc::meta::CaseTag< 0 >  ) -> void

If capture is used, the format extractor must provide a capture method. This isn't required so make it compile time optional, but throw if the extractor sets up for capture and didn't provide one.

Definition at line 749 of file bwf_base.h.

◆ arg_capture() [2/2]

template<typename F>
auto swoc::bwf::arg_capture ( F && f,
BufferWriter & w,
Spec const & spec,
std::any && value,
swoc::meta::CaseTag< 1 >  ) -> decltype(f.capture(w, spec, value))

Definition at line 755 of file bwf_base.h.

◆ Arg_Formatter()

template<typename TUPLE, size_t I>
BufferWriter & swoc::bwf::Arg_Formatter ( BufferWriter & w,
Spec const & spec,
TUPLE const & args )

This selects the I th argument in the TUPLE arg pack and calls the formatter on it. This (or the equivalent lambda) is needed because the array of formatters must have a homogenous signature, not vary per argument. Effectively this indirection erases the type of the specific argument being formatted. Instances of this have the signature ArgFormatterSignature.

Definition at line 653 of file bwf_base.h.

◆ As_Hex()

template<typename T>
HexDump swoc::bwf::As_Hex ( T const & t)

Treat t as raw memory and dump the memory as hexadecimal.

Template Parameters
TType of argument.
Parameters
tObject to dump.
Returns
A wrapper to do a hex dump.

This is the standard way to do a hexadecimal memory dump of an object.

Definition at line 1309 of file bwf_base.h.

◆ Err_Bad_Arg_Index()

void swoc::bwf::Err_Bad_Arg_Index ( BufferWriter & w,
int i,
size_t n )

Internal error / reporting message generators.

Definition at line 264 of file bw_format.cc.

◆ extractor_spec_type()

template<typename EXTRACTOR, typename VIEW, typename SPEC>
auto swoc::bwf::extractor_spec_type ( bool(EXTRACTOR::*  )(VIEW, SPEC)) -> SPEC

Extract the specifier type from an Extractor.

Template Parameters
EXTRACTORFormat extractor functor type.
VIEWString view argument type.
SPECSpecifier argument type.
Returns
A value of type SPEC

This is never called - it exists to extract SPEC from a format extractor functor to be used to declare the specifier instance passed to the format extractor. When used in this fashion with decltype the extracted type is a reference and that must be removed for the actual declaration type. The purpose is to enable format extractors to subclass bwf::Spec to pass additional information along, particularly to a name binding without interfering with the base use case.

Definition at line 776 of file bwf_base.h.

◆ Format_As_Hex()

void swoc::bwf::Format_As_Hex ( BufferWriter & w,
std::string_view view,
const char * digits )

Format output as a hexadecimal dump.

Parameters
wOutput buffer.
viewInput view.
digitsDigit array for hexadecimal digits.

This dumps the memory in the view as a hexadecimal string.

Definition at line 595 of file bw_format.cc.

◆ Format_Float()

BufferWriter & swoc::bwf::Format_Float ( BufferWriter & w,
Spec const & spec,
double f,
bool negative_p )

Format for floating point values. Seperates floating point into a whole number and a fraction. The fraction is converted into an unsigned integer based on the specified precision, spec._prec. ie. 3.1415 with precision two is seperated into two unsigned integers 3 and 14. The different pieces are assembled and placed into the BufferWriter. The default is two decimal places. ie. X.XX. The value is always written in base 10.

format: whole.fraction or: left.right

Format f as a floating point value.

Parameters
wOutput buffer.
specFormat specifier.
fInput value to format.
negative_pInput value shoudl be treated as a negative value.
Returns
w

A leading sign character will be output based on spec and negative_p.

Definition at line 500 of file bw_format.cc.

◆ Format_Integer()

BufferWriter & swoc::bwf::Format_Integer ( BufferWriter & w,
Spec const & spec,
uintmax_t n,
bool negative_p )

Format n as an integral value.

Parameters
wOutput buffer.
specFormat specifier.
nInput value to format.
negative_pInput value should be treated as a negative value.
Returns
w

A leading sign character will be output based on spec and negative_p.

Definition at line 404 of file bw_format.cc.

◆ Get_Arg_Formatter_Array()

template<typename TUPLE, size_t... N>
ArgFormatterSignature< TUPLE > * swoc::bwf::Get_Arg_Formatter_Array ( std::index_sequence< N... > )

This exists only to expand the index sequence into an array of formatters for the tuple type TUPLE. Due to language limitations it cannot be done directly. The formatters can be accessed via standard array access in contrast to templated tuple access. The actual array is static and therefore at run time the only operation is loading the address of the array.

Definition at line 663 of file bwf_base.h.

◆ Global_Names()

ExternalNames & swoc::bwf::Global_Names ( )

Default global names. This nameset is used if no other is provided. Therefore bindings added to this nameset will be available in the default formatting use.

Definition at line 33 of file bw_format.cc.

◆ tag_label() [1/2]

template<typename T>
auto swoc::detail::tag_label ( BufferWriter & ,
const bwf::Spec & ,
meta::CaseTag< 0 >  ) -> void

Definition at line 1250 of file bwf_base.h.

◆ tag_label() [2/2]

template<typename T>
auto swoc::detail::tag_label ( BufferWriter & w,
const bwf::Spec & ,
meta::CaseTag< 1 >  ) -> decltype(T::label, meta::TypeFunc<void>())

Definition at line 1254 of file bwf_base.h.

◆ Tuple_Accessor_Array()

template<typename T, size_t... N>
std::array< TupleAccessorSignature< T >, sizeof...(N)> & swoc::bwf::Tuple_Accessor_Array ( std::index_sequence< N... > )

Create and return an array of specialized accessors, indexed by tuple index.

Definition at line 732 of file bwf_base.h.

◆ Tuple_Nth()

template<typename T>
std::any swoc::bwf::Tuple_Nth ( T const & t,
size_t idx )

Get the Nth element of the tuple as std::any.

Definition at line 740 of file bwf_base.h.

◆ TupleAccessor()

template<size_t IDX, typename T>
std::any swoc::bwf::TupleAccessor ( T const & t)

Template access method.

Definition at line 725 of file bwf_base.h.