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
duckdb::BoxRenderer Class Reference
Collaboration diagram for duckdb::BoxRenderer:

Public Member Functions

 BoxRenderer (BoxRendererConfig config_p=BoxRendererConfig())
 
string ToString (ClientContext &context, const vector< string > &names, const ColumnDataCollection &op)
 
unique_ptr< BoxRendererStatePrepare (ClientContext &context, const vector< string > &names, const ColumnDataCollection &op)
 
void Render (ClientContext &context, const vector< string > &names, const ColumnDataCollection &op, BaseResultRenderer &ss)
 
void Print (ClientContext &context, const vector< string > &names, const ColumnDataCollection &op)
 

Static Public Member Functions

static string TryFormatLargeNumber (const string &numeric, char decimal_sep)
 
static string TruncateValue (const string &value, idx_t column_width, idx_t &pos, idx_t &current_render_width)
 

Private Attributes

BoxRendererConfig config
 The configuration used for rendering.
 

Constructor & Destructor Documentation

◆ BoxRenderer()

duckdb::BoxRenderer::BoxRenderer ( BoxRendererConfig  config_p = BoxRendererConfig())
explicit
49560 : config(std::move(config_p)) {
49561}
BoxRendererConfig config
The configuration used for rendering.
Definition duckdb.cpp:35753

Member Function Documentation

◆ ToString()

string duckdb::BoxRenderer::ToString ( ClientContext context,
const vector< string > &  names,
const ColumnDataCollection op 
)
49563 {
49564 StringResultRenderer ss;
49565 Render(context, names, result, ss);
49566 return ss.str();
49567}

◆ Prepare()

unique_ptr< BoxRendererState > duckdb::BoxRenderer::Prepare ( ClientContext context,
const vector< string > &  names,
const ColumnDataCollection op 
)
49574 {
49575 return make_uniq<BoxRendererImplementation>(config, context, names, result);
49576}

◆ Render()

void duckdb::BoxRenderer::Render ( ClientContext context,
const vector< string > &  names,
const ColumnDataCollection op,
BaseResultRenderer ss 
)
49579 {
49580 auto state = Prepare(context, names, result);
49581 state->Render(ss);
49582}

◆ Print()

void duckdb::BoxRenderer::Print ( ClientContext context,
const vector< string > &  names,
const ColumnDataCollection op 
)
49569 {
49570 Printer::Print(ToString(context, names, result));
49571}
static DUCKDB_API void Print(OutputStream stream, const string &str)
Print the object to the stream.

◆ TryFormatLargeNumber()

string duckdb::BoxRenderer::TryFormatLargeNumber ( const string &  numeric,
char  decimal_sep 
)
static
47816 {
47817 // we only return a readable rendering if the number is > 1 million
47818 if (numeric.size() <= 5) {
47819 // number too small for sure
47820 return string();
47821 }
47822 // get the number to summarize
47823 idx_t number = 0;
47824 bool negative = false;
47825 idx_t i = 0;
47826 if (numeric[0] == '-') {
47827 negative = true;
47828 i++;
47829 }
47830 for (; i < numeric.size(); i++) {
47831 char c = numeric[i];
47832 if (c == '.') {
47833 break;
47834 }
47835 if (c < '0' || c > '9') {
47836 // not a number or something funky (e.g. 1.23e7)
47837 // we could theoretically summarize numbers with exponents
47838 return string();
47839 }
47840 if (number >= 1000000000000000000ULL) {
47841 // number too big
47842 return string();
47843 }
47844 number = number * 10 + static_cast<idx_t>(c - '0');
47845 }
47846 struct UnitBase {
47847 idx_t base;
47848 const char *name;
47849 };
47850 static constexpr idx_t BASE_COUNT = 5;
47851 UnitBase bases[] = {{1000000ULL, "million"},
47852 {1000000000ULL, "billion"},
47853 {1000000000000ULL, "trillion"},
47854 {1000000000000000ULL, "quadrillion"},
47855 {1000000000000000000ULL, "quintillion"}};
47856 idx_t base = 0;
47857 string unit;
47858 for (idx_t i = 0; i < BASE_COUNT; i++) {
47859 // round the number according to this base
47860 idx_t rounded_number = number + ((bases[i].base / 100ULL) / 2);
47861 if (rounded_number >= bases[i].base) {
47862 base = bases[i].base;
47863 unit = bases[i].name;
47864 }
47865 }
47866 if (unit.empty()) {
47867 return string();
47868 }
47869 number += (base / 100ULL) / 2;
47870 idx_t decimal_unit = number / (base / 100ULL);
47871 string decimal_str = to_string(decimal_unit);
47872 string result;
47873 if (negative) {
47874 result += "-";
47875 }
47876 result += decimal_str.substr(0, decimal_str.size() - 2);
47877 result += decimal_sep == '\0' ? '.' : decimal_sep;
47878 result += decimal_str.substr(decimal_str.size() - 2, 2);
47879 result += " ";
47880 result += unit;
47881 return result;
47882}

◆ TruncateValue()

string duckdb::BoxRenderer::TruncateValue ( const string &  value,
idx_t  column_width,
idx_t pos,
idx_t current_render_width 
)
static
47661 {
47662 idx_t start_pos = pos;
47663 while (pos < value.size()) {
47664 if (value[pos] == '\n') {
47665 // newline character - stop rendering for this line - but skip the newline
47666 idx_t render_pos = pos;
47667 pos++;
47668 return value.substr(start_pos, render_pos - start_pos);
47669 }
47670 // check if this character fits...
47671 auto char_size = Utf8Proc::RenderWidth(value.c_str(), value.size(), pos);
47672 if (current_render_width + char_size > column_width) {
47673 // it doesn't! stop
47674 break;
47675 }
47676 // it does! move to the next character
47677 current_render_width += char_size;
47678 pos = Utf8Proc::NextGraphemeCluster(value.c_str(), value.size(), pos);
47679 }
47680 return value.substr(start_pos, pos - start_pos);
47681}
static size_t NextGraphemeCluster(const char *s, size_t len, size_t pos)
Returns the position (in bytes) of the next grapheme cluster.
static size_t RenderWidth(const char *s, size_t len, size_t pos)
Returns the render width of a single character in a string.

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