LibSWOC++ 1.5.14
Solid Wall of C++
Loading...
Searching...
No Matches
bw_format.cc File Reference
#include <array>
#include <cctype>
#include <chrono>
#include <cmath>
#include <ctime>
#include <sys/param.h>
#include <unistd.h>
#include "swoc/BufferWriter.h"
#include "swoc/bwf_base.h"
#include "swoc/bwf_ex.h"
#include "swoc/swoc_meta.h"
#include "swoc/DiscreteRange.h"
Include dependency graph for bw_format.cc:

Go to the source code of this file.

Namespaces

namespace  swoc
 For template deduction guides.
 
namespace  std
 STL namespace.
 

Functions

ExternalNamesswoc::bwf::Global_Names ()
 
void swoc::bwf::Err_Bad_Arg_Index (BufferWriter &w, int i, size_t n)
 Internal error / reporting message generators.
 
void swoc::bwf::Adjust_Alignment (BufferWriter &aux, Spec const &spec)
 
template<size_t RADIX>
size_t swoc::bwf::To_Radix (uintmax_t n, char *buff, size_t width, char *digits)
 
template<typename F>
void swoc::bwf::Write_Aligned (BufferWriter &w, F const &f, Spec::Align align, int width, char fill, char neg)
 
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)
 
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, bwf::HexDump const &hex)
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, MemSpan< void const > const &span)
 
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::Pattern const &pattern)
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, std::error_code const &ec)
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, bwf::UnHex const &obj)
 
ostream & std::operator<< (ostream &s, swoc::FixedBufferWriter &w)
 
template<int RADIX>
uintmax_t svto_radix (TextView &src)
 

Detailed Description

Formatted output for BufferWriter.

Definition in file bw_format.cc.

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.

◆ 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.

◆ 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.

◆ 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.

◆ svto_radix()

template<int RADIX>
uintmax_t swoc::svto_radix ( TextView & src)

Convert the text in src to an unsigned numeric value.

Template Parameters
NThe radix (must be 1..36)
Parameters
srcThe source text. Updated during parsing.
Returns
The converted numeric value.

This is a specialized function useful only where conversion performance is critical. It is used inside svtoi and svtou for the common cases of 8, 10, and 16, therefore normally this isn't much more performant in those cases than just svtoi. Because of this only positive values are parsed. If determining the radix from the text or signed value parsing is needed, used svtoi.

src is updated in place to indicate what characters were parsed by removing them from the view Parsing stops on the first invalid digit, so any leading non-digit characters (e.g. whitespace) must already be removed. For overflow, all valid digits are consumed and the maximum value returned.

Definition at line 1059 of file TextView.h.

◆ To_Radix()

template<size_t RADIX>
size_t swoc::bwf::To_Radix ( uintmax_t n,
char * buff,
size_t width,
char * digits )

Templated radix based conversions. Only a small number of radix are supported and providing a template minimizes cut and paste code while also enabling compiler optimizations (e.g. for power of 2 radix the modulo / divide become bit operations).

Definition at line 327 of file bw_format.cc.

◆ Write_Aligned()

template<typename F>
void swoc::bwf::Write_Aligned ( BufferWriter & w,
F const & f,
Spec::Align align,
int width,
char fill,
char neg )

Output a string with a specified alignment.

Template Parameters
FOutput functor.
Parameters
wOutput buffer.
fFunctor that generates output.
alignAlignment.
widthField width.
fillFill character.
negCharacter to use for negative (null char means do not output).

Definition at line 353 of file bw_format.cc.