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
format_int Class Reference

Public Member Functions

 format_int (int value)
 format_int (long value)
 format_int (long long value)
 format_int (unsigned value)
 format_int (unsigned long value)
 format_int (unsigned long long value)
std::size_t size () const
const char * data () const
const char * c_str () const
std::string str () const

Private Types

enum  { buffer_size = std::numeric_limits<unsigned long long>::digits10 + 3 }

Private Member Functions

char * format_decimal (unsigned long long value)
void format_signed (long long value)

Private Attributes

char buffer_ [buffer_size]
char * str_

Detailed Description

Fast integer formatter.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
19002{ buffer_size = std::numeric_limits<unsigned long long>::digits10 + 3 };

Constructor & Destructor Documentation

◆ format_int() [1/6]

format_int::format_int ( int value)
inlineexplicit
19037{ format_signed(value); }

◆ format_int() [2/6]

format_int::format_int ( long value)
inlineexplicit
19038{ format_signed(value); }

◆ format_int() [3/6]

format_int::format_int ( long long value)
inlineexplicit
19039{ format_signed(value); }

◆ format_int() [4/6]

format_int::format_int ( unsigned value)
inlineexplicit
19040: str_(format_decimal(value)) {}

◆ format_int() [5/6]

format_int::format_int ( unsigned long value)
inlineexplicit
19041: str_(format_decimal(value)) {}

◆ format_int() [6/6]

format_int::format_int ( unsigned long long value)
inlineexplicit
19042: str_(format_decimal(value)) {}

Member Function Documentation

◆ format_decimal()

char * format_int::format_decimal ( unsigned long long value)
inlineprivate
19007 {
19008 char* ptr = buffer_ + (buffer_size - 1); // Parens to workaround MSVC bug.
19009 while (value >= 100) {
19010 // Integer division is slow so do it for a group of two digits instead
19011 // of for every digit. The idea comes from the talk by Alexandrescu
19012 // "Three Optimization Tips for C++". See speed-test for a comparison.
19013 auto index = static_cast<unsigned>((value % 100) * 2);
19014 value /= 100;
19015 *--ptr = internal::data::digits[index + 1];
19016 *--ptr = internal::data::digits[index];
19017 }
19018 if (value < 10) {
19019 *--ptr = static_cast<char>('0' + value);
19020 return ptr;
19021 }
19022 auto index = static_cast<unsigned>(value * 2);
19023 *--ptr = internal::data::digits[index + 1];
19024 *--ptr = internal::data::digits[index];
19025 return ptr;
19026 }
index

◆ format_signed()

void format_int::format_signed ( long long value)
inlineprivate
19028 {
19029 auto abs_value = static_cast<unsigned long long>(value);
19030 bool negative = value < 0;
19031 if (negative) abs_value = 0 - abs_value;
19032 str_ = format_decimal(abs_value);
19033 if (negative) *--str_ = '-';
19034 }

◆ size()

std::size_t format_int::size ( ) const
inline

Returns the number of characters written to the output buffer.

19045 {
19046 return internal::to_unsigned(buffer_ - str_ + buffer_size - 1);
19047 }
Here is the caller graph for this function:

◆ data()

const char * format_int::data ( ) const
inline

Returns a pointer to the output buffer content. No terminating null character is appended.

19053{ return str_; }

◆ c_str()

const char * format_int::c_str ( ) const
inline

Returns a pointer to the output buffer content with terminating null character appended.

19059 {
19060 buffer_[buffer_size - 1] = '\0';
19061 return str_;
19062 }

◆ str()

std::string format_int::str ( ) const
inline

\rst Returns the content of the output buffer as an std::string. \endrst

19069{ return std::string(str_, size()); }
std::size_t size() const
Definition duckdb.cpp:19045
Here is the call graph for this function:

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