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
internal::basic_writer< Range > Class Template Reference
Collaboration diagram for internal::basic_writer< Range >:

Classes

struct  padded_int_writer
struct  int_writer
struct  str_writer
struct  pointer_writer

Public Types

using char_type = typename Range::value_type
using iterator = typename Range::iterator
using format_specs = basic_format_specs<char_type>

Public Member Functions

 basic_writer (Range out, locale_ref loc=locale_ref())
iterator out () const
template<typename F>
void write_padded (const format_specs &specs, F &&f)
void write (int value)
void write (long value)
void write (long long value)
void write (unsigned value)
void write (unsigned long value)
void write (unsigned long long value)
void write (int128_t value)
void write (uint128_t value)
template<typename T, typename Spec>
void write_int (T value, const Spec &spec)
template<typename T, FMT_ENABLE_IF(std::is_floating_point< T >::value)>
void write (T value, format_specs specs={})
void write (char value)
template<typename Char, FMT_ENABLE_IF(std::is_same< Char, char_type >::value)>
void write (Char value)
void write (string_view value)
void write (wstring_view value)
template<typename Char>
void write (const Char *s, std::size_t size, const format_specs &specs)
template<typename Char>
void write (basic_string_view< Char > s, const format_specs &specs={})
template<typename UIntPtr>
void write_pointer (UIntPtr value, const format_specs *specs)

Private Member Functions

auto reserve (std::size_t n) -> decltype(internal::reserve(out_, n))
template<typename F>
void write_int (int num_digits, string_view prefix, format_specs specs, F f)
template<typename Int>
void write_decimal (Int value)

Private Attributes

iterator out_
locale_ref locale_

Constructor & Destructor Documentation

◆ basic_writer()

template<typename Range>
internal::basic_writer< Range >::basic_writer ( Range out,
locale_ref loc = locale_ref() )
inlineexplicit
17896 : out_(out.begin()), locale_(loc) {}
Definition duckdb.cpp:17649

Member Function Documentation

◆ reserve()

template<typename Range>
auto internal::basic_writer< Range >::reserve ( std::size_t n) ->decltype(internal::reserve(out_, n))
inlineprivate
17661 {
17662 return internal::reserve(out_, n);
17663 }

◆ write_int() [1/2]

template<typename Range>
template<typename F>
void internal::basic_writer< Range >::write_int ( int num_digits,
string_view prefix,
format_specs specs,
F f )
inlineprivate
17687 {
17689 char_type fill = specs.fill[0];
17690 std::size_t padding = 0;
17691 if (specs.align == align::numeric) {
17692 auto unsiged_width = to_unsigned(specs.width);
17693 if (unsiged_width > size) {
17696 }
17697 } else if (specs.precision > num_digits) {
17698 size = prefix.size() + to_unsigned(specs.precision);
17699 padding = to_unsigned(specs.precision - num_digits);
17700 fill = static_cast<char_type>('0');
17701 }
17702 if (specs.align == align::none) specs.align = align::right;
17703 write_padded(specs, padded_int_writer<F>{size, prefix, fill, padding, f});
17704 }

◆ write_decimal()

template<typename Range>
template<typename Int>
void internal::basic_writer< Range >::write_decimal ( Int value)
inlineprivate
17707 {
17708 auto abs_value = static_cast<uint32_or_64_or_128_t<Int>>(value);
17709 bool negative = is_negative(value);
17710 // Don't do -abs_value since it trips unsigned-integer-overflow sanitizer.
17711 if (negative) abs_value = ~abs_value + 1;
17713 auto&& it = reserve((negative ? 1 : 0) + static_cast<size_t>(num_digits));
17714 if (negative) *it++ = static_cast<char_type>('-');
17716 }

◆ out()

template<typename Range>
iterator internal::basic_writer< Range >::out ( ) const
inline
17898{ return out_; }

◆ write_padded()

template<typename Range>
template<typename F>
void internal::basic_writer< Range >::write_padded ( const format_specs & specs,
F && f )
inline
17903 {
17904 // User-perceived width (in code points).
17905 unsigned width = to_unsigned(specs.width);
17906 size_t size = f.size(); // The number of code units.
17907 size_t num_code_points = width != 0 ? f.width() : size;
17908 if (width <= num_code_points) return f(reserve(size));
17909 auto&& it = reserve(width + (size - num_code_points));
17910 char_type fill = specs.fill[0];
17912 if (specs.align == align::right) {
17914 f(it);
17915 } else if (specs.align == align::center) {
17918 f(it);
17920 } else {
17921 f(it);
17923 }
17924 }

◆ write() [1/15]

template<typename Range>
void internal::basic_writer< Range >::write ( int value)
inline
17926{ write_decimal(value); }

◆ write() [2/15]

template<typename Range>
void internal::basic_writer< Range >::write ( long value)
inline
17927{ write_decimal(value); }

◆ write() [3/15]

template<typename Range>
void internal::basic_writer< Range >::write ( long long value)
inline
17928{ write_decimal(value); }

◆ write() [4/15]

template<typename Range>
void internal::basic_writer< Range >::write ( unsigned value)
inline
17930{ write_decimal(value); }

◆ write() [5/15]

template<typename Range>
void internal::basic_writer< Range >::write ( unsigned long value)
inline
17931{ write_decimal(value); }

◆ write() [6/15]

template<typename Range>
void internal::basic_writer< Range >::write ( unsigned long long value)
inline
17932{ write_decimal(value); }

◆ write() [7/15]

template<typename Range>
void internal::basic_writer< Range >::write ( int128_t value)
inline
17934{ write_decimal(value); }

◆ write() [8/15]

template<typename Range>
void internal::basic_writer< Range >::write ( uint128_t value)
inline
17935{ write_decimal(value); }

◆ write_int() [2/2]

template<typename Range>
template<typename T, typename Spec>
void internal::basic_writer< Range >::write_int ( T value,
const Spec & spec )
inline
17938 {
17940 }
Definition duckdb.cpp:17719

◆ write() [9/15]

template<typename Range>
template<typename T, FMT_ENABLE_IF(std::is_floating_point< T >::value)>
void internal::basic_writer< Range >::write ( T value,
format_specs specs = {} )
inline
17943 {}) {
17945 fspecs.sign = specs.sign;
17946 if (std::signbit(value)) { // value < 0 is false for NaN so use signbit.
17947 fspecs.sign = sign::minus;
17948 value = -value;
17949 } else if (fspecs.sign == sign::minus) {
17950 fspecs.sign = sign::none;
17951 }
17952
17953 if (!std::isfinite(value)) {
17954 auto str = std::isinf(value) ? (fspecs.upper ? "INF" : "inf")
17955 : (fspecs.upper ? "NAN" : "nan");
17956 return write_padded(specs, nonfinite_writer<char_type>{fspecs.sign, str});
17957 }
17958
17959 if (specs.align == align::none) {
17960 specs.align = align::right;
17961 } else if (specs.align == align::numeric) {
17962 if (fspecs.sign) {
17963 auto&& it = reserve(1);
17964 *it++ = static_cast<char_type>(data::signs[fspecs.sign]);
17965 fspecs.sign = sign::none;
17966 if (specs.width != 0) --specs.width;
17967 }
17968 specs.align = align::right;
17969 }
17970
17972 if (fspecs.format == float_format::hex) {
17973 if (fspecs.sign) buffer.push_back(data::signs[fspecs.sign]);
17975 write_padded(specs, str_writer<char>{buffer.data(), buffer.size()});
17976 return;
17977 }
17978 int precision = specs.precision >= 0 || !specs.type ? specs.precision : 6;
17979 if (fspecs.format == float_format::exp) ++precision;
17980 if (const_check(std::is_same<T, float>())) fspecs.binary32 = true;
17981 fspecs.use_grisu = use_grisu<T>();
17982 if (const_check(FMT_DEPRECATED_PERCENT) && fspecs.percent) value *= 100;
17984 if (const_check(FMT_DEPRECATED_PERCENT) && fspecs.percent) {
17985 buffer.push_back('%');
17986 --exp; // Adjust decimal place position.
17987 }
17988 fspecs.precision = precision;
17989 char_type point;
17990 if (fspecs.locale) {
17992 } else if (fspecs.thousand_sep == '.') {
17993 // if the thousand separator is a point, we automatically switch the decimal separator to comma
17994 point =static_cast<char_type>(',');
17995 } else {
17996 point = static_cast<char_type>('.');
17997 }
17998 write_padded(specs, float_writer<char_type>(buffer.data(),
17999 static_cast<int>(buffer.size()),
18000 exp, fspecs, point));
18001 }
Definition duckdb.cpp:17866

◆ write() [10/15]

template<typename Range>
void internal::basic_writer< Range >::write ( char value)
inline
18003 {
18004 auto&& it = reserve(1);
18005 *it++ = value;
18006 }

◆ write() [11/15]

template<typename Range>
template<typename Char, FMT_ENABLE_IF(std::is_same< Char, char_type >::value)>
void internal::basic_writer< Range >::write ( Char value)
inline
18009 {
18010 auto&& it = reserve(1);
18011 *it++ = value;
18012 }

◆ write() [12/15]

template<typename Range>
void internal::basic_writer< Range >::write ( string_view value)
inline
18014 {
18015 auto&& it = reserve(value.size());
18016 it = copy_str<char_type>(value.begin(), value.end(), it);
18017 }

◆ write() [13/15]

template<typename Range>
void internal::basic_writer< Range >::write ( wstring_view value)
inline
18018 {
18019 static_assert(std::is_same<char_type, wchar_t>::value, "");
18020 auto&& it = reserve(value.size());
18021 it = std::copy(value.begin(), value.end(), it);
18022 }

◆ write() [14/15]

template<typename Range>
template<typename Char>
void internal::basic_writer< Range >::write ( const Char * s,
std::size_t size,
const format_specs & specs )
inline
18025 {
18026 write_padded(specs, str_writer<Char>{s, size});
18027 }

◆ write() [15/15]

template<typename Range>
template<typename Char>
void internal::basic_writer< Range >::write ( basic_string_view< Char > s,
const format_specs & specs = {} )
inline
18030 {}) {
18031 const Char* data = s.data();
18032 std::size_t size = s.size();
18033 if (specs.precision >= 0 && to_unsigned(specs.precision) < size)
18034 size = code_point_index(s, to_unsigned(specs.precision));
18035 write(data, size, specs);
18036 }

◆ write_pointer()

template<typename Range>
template<typename UIntPtr>
void internal::basic_writer< Range >::write_pointer ( UIntPtr value,
const format_specs * specs )
inline
18039 {
18042 if (!specs) return pw(reserve(to_unsigned(num_digits) + 2));
18043 format_specs specs_copy = *specs;
18044 if (specs_copy.align == align::none) specs_copy.align = align::right;
18045 write_padded(specs_copy, pw);
18046 }
Definition duckdb.cpp:17880

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