Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
basic_printf_context< OutputIt, Char > Class Template Reference
Collaboration diagram for basic_printf_context< OutputIt, Char >:

Public Types

using char_type = Char
using format_arg = basic_format_arg<basic_printf_context>
template<typename T>
using formatter_type = printf_formatter<T>

Public Member Functions

 basic_printf_context (OutputIt out, basic_string_view< char_type > format_str, basic_format_args< basic_printf_context > args)
OutputIt out ()
void advance_to (OutputIt it)
format_arg arg (int id) const
basic_format_parse_context< Char > & parse_context ()
FMT_CONSTEXPR void on_error (std::string message)
template<typename ArgFormatter = printf_arg_formatter<buffer_range<Char>>>
OutputIt format ()

Private Types

using format_specs = basic_format_specs<char_type>

Private Member Functions

format_arg get_arg (int arg_index=-1)
int parse_header (const Char *&it, const Char *end, format_specs &specs)

Static Private Member Functions

static void parse_flags (format_specs &specs, const Char *&it, const Char *end)

Private Attributes

OutputIt out_
basic_format_args< basic_printf_context > args_
basic_format_parse_context< Char > parse_ctx_

Detailed Description

template<typename OutputIt, typename Char>
class basic_printf_context< OutputIt, Char >

This template formats data and writes the output to a writer.

Member Typedef Documentation

◆ char_type

template<typename OutputIt, typename Char>
using basic_printf_context< OutputIt, Char >::char_type = Char

The character type for the output.

Constructor & Destructor Documentation

◆ basic_printf_context()

template<typename OutputIt, typename Char>
basic_printf_context< OutputIt, Char >::basic_printf_context ( OutputIt out,
basic_string_view< char_type > format_str,
basic_format_args< basic_printf_context< OutputIt, Char > > args )
inline

\rst Constructs a printf_context object. References to the arguments and the writer are stored in the context object so make sure they have appropriate lifetimes. \endrst

71511 : out_(out), args_(args), parse_ctx_(format_str) {}
Definition duckdb.cpp:71477

Member Function Documentation

◆ parse_flags()

template<typename OutputIt, typename Char>
void basic_printf_context< OutputIt, Char >::parse_flags ( format_specs & specs,
const Char *& it,
const Char * end )
staticprivate
71532 {
71533 for (; it != end; ++it) {
71534 switch (*it) {
71535 case '-':
71536 specs.align = align::left;
71537 break;
71538 case '+':
71539 specs.sign = sign::plus;
71540 break;
71541 case '0':
71542 specs.fill[0] = '0';
71543 break;
71544 case ' ':
71545 specs.sign = sign::space;
71546 break;
71547 case '#':
71548 specs.alt = true;
71549 break;
71550 case ',':
71551 specs.thousands = ',';
71552 break;
71553 case '\'':
71554 specs.thousands = '\'';
71555 break;
71556 case '_':
71557 specs.thousands = '_';
71558 break;
71559 default:
71560 return;
71561 }
71562 }
71563}

◆ get_arg()

template<typename OutputIt, typename Char>
basic_printf_context< OutputIt, Char >::format_arg basic_printf_context< OutputIt, Char >::get_arg ( int arg_index = -1)
private
71567 {
71568 if (arg_index < 0)
71569 arg_index = parse_ctx_.next_arg_id();
71570 else
71571 parse_ctx_.check_arg_id(--arg_index);
71572 return internal::get_arg(*this, arg_index);
71573}

◆ parse_header()

template<typename OutputIt, typename Char>
int basic_printf_context< OutputIt, Char >::parse_header ( const Char *& it,
const Char * end,
format_specs & specs )
private
71577 {
71578 int arg_index = -1;
71579 char_type c = *it;
71580 if (c >= '0' && c <= '9') {
71581 // Parse an argument index (if followed by '$') or a width possibly
71582 // preceded with '0' flag(s).
71585 if (it != end && *it == '$') { // value is an argument index
71586 ++it;
71587 arg_index = value;
71588 } else {
71589 if (c == '0') specs.fill[0] = '0';
71590 if (value != 0) {
71591 // Nonzero value means that we parsed width and don't need to
71592 // parse it or flags again, so return now.
71593 specs.width = value;
71594 return arg_index;
71595 }
71596 }
71597 }
71598 parse_flags(specs, it, end);
71599 // Parse width.
71600 if (it != end) {
71601 if (*it >= '0' && *it <= '9') {
71603 specs.width = parse_nonnegative_int(it, end, eh);
71604 } else if (*it == '*') {
71605 ++it;
71606 specs.width = static_cast<int>(visit_format_arg(
71608 }
71609 }
71610 return arg_index;
71611}
Char char_type
Definition duckdb.cpp:71480
FMT_CONSTEXPR auto visit_format_arg(Visitor &&vis, const basic_format_arg< Context > &arg) -> decltype(vis(0))
Definition duckdb.cpp:15830

◆ out()

template<typename OutputIt, typename Char>
OutputIt basic_printf_context< OutputIt, Char >::out ( )
inline
71513{ return out_; }

◆ advance_to()

template<typename OutputIt, typename Char>
void basic_printf_context< OutputIt, Char >::advance_to ( OutputIt it)
inline
71514{ out_ = it; }

◆ arg()

template<typename OutputIt, typename Char>
format_arg basic_printf_context< OutputIt, Char >::arg ( int id) const
inline
71516{ return args_.get(id); }

◆ parse_context()

template<typename OutputIt, typename Char>
basic_format_parse_context< Char > & basic_printf_context< OutputIt, Char >::parse_context ( )
inline
71518{ return parse_ctx_; }

◆ on_error()

template<typename OutputIt, typename Char>
FMT_CONSTEXPR void basic_printf_context< OutputIt, Char >::on_error ( std::string message)
inline
71520 {
71521 parse_ctx_.on_error(message);
71522 }

◆ format()

template<typename OutputIt, typename Char>
template<typename ArgFormatter>
OutputIt basic_printf_context< OutputIt, Char >::format ( )

Formats stored arguments and writes the output to the range.

71615 {
71616 auto out = this->out();
71617 const Char* start = parse_ctx_.begin();
71618 const Char* end = parse_ctx_.end();
71619 auto it = start;
71620 while (it != end) {
71621 char_type c = *it++;
71622 if (c != '%') continue;
71623 if (it != end && *it == c) {
71624 out = std::copy(start, it, out);
71625 start = ++it;
71626 continue;
71627 }
71628 out = std::copy(start, it - 1, out);
71629
71630 format_specs specs;
71631 specs.align = align::right;
71632
71633 // Parse argument index, flags and width.
71634 int arg_index = parse_header(it, end, specs);
71635 if (arg_index == 0) on_error("argument index out of range");
71636
71637 // Parse precision.
71638 bool empty_precision = false;
71639 if (it != end && *it == '.') {
71640 ++it;
71641 c = it != end ? *it : 0;
71642 if ('0' <= c && c <= '9') {
71644 specs.precision = parse_nonnegative_int(it, end, eh);
71645 } else if (c == '*') {
71646 ++it;
71647 specs.precision =
71648 static_cast<int>(visit_format_arg(internal::printf_precision_handler(), get_arg()));
71649 } else {
71650 specs.precision = 0;
71651 empty_precision = true;
71652 }
71653 }
71654
71655 format_arg arg = get_arg(arg_index);
71656 if (specs.alt && visit_format_arg(internal::is_zero_int(), arg))
71657 specs.alt = false;
71658 if (specs.fill[0] == '0') {
71659 if (arg.is_arithmetic())
71660 specs.align = align::numeric;
71661 else
71662 specs.fill[0] = ' '; // Ignore '0' flag for non-numeric types.
71663 }
71664
71665 // Parse length and convert the argument to the required type.
71666 c = it != end ? *it++ : 0;
71667 char_type t = it != end ? *it : 0;
71669 switch (c) {
71670 case 'h':
71671 if (t == 'h') {
71672 ++it;
71673 t = it != end ? *it : 0;
71675 } else {
71676 convert_arg<short>(arg, t);
71677 }
71678 break;
71679 case 'l':
71680 if (t == 'l') {
71681 ++it;
71682 t = it != end ? *it : 0;
71684 } else {
71685 convert_arg<long>(arg, t);
71686 }
71687 break;
71688 case 'j':
71690 break;
71691 case 'z':
71693 break;
71694 case 't':
71696 break;
71697 case 'L':
71698 // printf produces garbage when 'L' is omitted for long double, no
71699 // need to do the same.
71700 break;
71701 default:
71702 --it;
71703 convert_arg<void>(arg, c);
71704 }
71705
71706 // Parse type.
71707 if (it == end) FMT_THROW(duckdb::InvalidInputException("invalid format string"));
71708 specs.type = static_cast<char>(*it++);
71709 if (arg.is_integral()) {
71710 // Normalize type.
71711 switch (specs.type) {
71712 case 'i':
71713 case 'u':
71714 specs.type = 'd';
71715 break;
71716 case 'c':
71718 arg);
71719 break;
71720 }
71721 }
71722 if (specs.type == 'd' && empty_precision) {
71723 specs.thousands = '.';
71724 }
71725
71726 start = it;
71727
71728 // Format argument.
71729 visit_format_arg(ArgFormatter(out, specs, *this), arg);
71730 }
71731 return std::copy(start, it, out);
71732}
Here is the call graph for this function:

The documentation for this class was generated from the following file: