LibSWOC++ 1.5.14
Solid Wall of C++
Loading...
Searching...
No Matches
bwf_ex.h File Reference
#include <array>
#include <string_view>
#include "swoc/swoc_version.h"
#include "swoc/bwf_base.h"
#include "swoc/swoc_meta.h"
Include dependency graph for bwf_ex.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  swoc::bwf::Pattern
 
struct  swoc::bwf::Errno
 
struct  swoc::bwf::Date
 
struct  swoc::bwf::SubText< Args >
 
struct  swoc::bwf::UnHex
 

Namespaces

namespace  swoc
 For template deduction guides.
 

Functions

std::string_view swoc::bwf::detail::FirstOfConverter (std::nullptr_t)
 
std::string_view swoc::bwf::detail::FirstOfConverter (char const *s)
 
template<typename T>
std::string_view swoc::bwf::detail::FirstOfConverter (T &&t)
 
template<typename... Args>
std::string_view swoc::bwf::FirstOf (Args &&...args)
 
template<typename... Args>
SubText< Args... > swoc::bwf::If (bool flag, TextView const &fmt, Args &&...args)
 
template<typename T>
auto swoc::bwf::detail::Optional (meta::CaseTag< 2 >, TextView fmt, T &&t) -> decltype(void(t.empty()), meta::TypeFunc< SubText< T > >())
 
template<typename T>
auto swoc::bwf::detail::Optional (meta::CaseTag< 1 >, TextView fmt, T &&t) -> decltype(bool(t), meta::TypeFunc< SubText< T > >())
 
template<typename T>
auto swoc::bwf::detail::Optional (meta::CaseTag< 0 >, TextView fmt, T &&t) -> SubText< T >
 
template<typename ARG>
SubText< ARG > swoc::bwf::Optional (TextView fmt, ARG &&arg)
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, bwf::Pattern const &pattern)
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, bwf::Errno const &e)
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, bwf::Date const &date)
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, bwf::UnHex const &obj)
 
template<typename... Args>
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &, bwf::SubText< Args... > const &subtext)
 

Detailed Description

BufferWriter formatters for types in the std namespace.

Definition in file bwf_ex.h.

Function Documentation

◆ FirstOf()

template<typename... Args>
std::string_view swoc::bwf::FirstOf ( Args &&... args)

Print the first of a list of strings that is not an empty string. All arguments must be convertible to std::string_view.

Definition at line 86 of file bwf_ex.h.

◆ FirstOfConverter() [1/3]

std::string_view swoc::bwf::detail::FirstOfConverter ( char const * s)
inline

Definition at line 70 of file bwf_ex.h.

◆ FirstOfConverter() [2/3]

std::string_view swoc::bwf::detail::FirstOfConverter ( std::nullptr_t )
inline

Definition at line 65 of file bwf_ex.h.

◆ FirstOfConverter() [3/3]

template<typename T>
std::string_view swoc::bwf::detail::FirstOfConverter ( T && t)

Definition at line 77 of file bwf_ex.h.

◆ If()

template<typename... Args>
SubText< Args... > swoc::bwf::If ( bool flag,
TextView const & fmt,
Args &&... args )

Optional printing wrapper.

Template Parameters
ArgsArguments for output.
Parameters
flagGenerate output flag.
fmtFormat for output and args.
argsThe arguments.
Returns
A wrapper for the optional text.

This function is passed a flag, a printing format fmt, and a set of arguments args to be used by the format. Output is generated if flag is true, otherwise the empty string (no output) is generated. For example, if in a function there was a flag to determine if an extra tag with delimiters, e.g. "[tag]", was to be generated, this could be done with

w.print("Some other text{}.", bwf::If(flag, " [{}]", tag));

Definition at line 146 of file bwf_ex.h.

◆ Optional() [1/4]

template<typename T>
auto swoc::bwf::detail::Optional ( meta::CaseTag< 0 > ,
TextView fmt,
T && t ) -> SubText<T>

Definition at line 168 of file bwf_ex.h.

◆ Optional() [2/4]

template<typename T>
auto swoc::bwf::detail::Optional ( meta::CaseTag< 1 > ,
TextView fmt,
T && t ) -> decltype(bool(t), meta::TypeFunc<SubText<T>>())

Definition at line 161 of file bwf_ex.h.

◆ Optional() [3/4]

template<typename T>
auto swoc::bwf::detail::Optional ( meta::CaseTag< 2 > ,
TextView fmt,
T && t ) -> decltype(void(t.empty()), meta::TypeFunc<SubText<T>>())

Definition at line 154 of file bwf_ex.h.

◆ Optional() [4/4]

template<typename ARG>
SubText< ARG > swoc::bwf::Optional ( TextView fmt,
ARG && arg )

Simplified optional text wrapper.

Template Parameters
ARGthe type of the (single) argument.
Parameters
fmtFormat string.
argThe single argument to the format string and predicate.
Returns
An optional text wrapper.

This generates output iff arg is not empty. fmt is required to take only a single argument, which will be arg. This is a convenience overload, to handle the common case where the argument and the conditional are the same. The argument must have one of the following properties in order to serve as the conditional. These are checked in order.

  • The empty() method which returns true if the argument is empty and should not be printed. This handles the case of C++ string types.
  • Conversion to bool which is false if the argument should not be printed. This covers the case of pointers.

As an example, if an output function had three strings alpha, bravo, and charlie, each of which could be null, which should be output with space separators, this would be

w.print("Leading text{}{}{}.", Optional(" {}", alpha)
, Optional(" {}", bravo)
, Optional(" {}", charlie));

Because of the property handling, these strings can be C styles strings ( char* ) or C++ string types (such as std::string_view ).

Definition at line 206 of file bwf_ex.h.