MCPcopy Create free account
hub / github.com/Cantera/cantera / formatColumn

Function formatColumn

src/base/SolutionArray.cpp:422–471  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

420}
421
422vector<string> formatColumn(string name, const AnyValue& comp, int rows, int width)
423{
424 if (comp.isVector<double>()) {
425 return doubleColumn(name, comp.asVector<double>(), rows, width);
426 }
427 if (comp.isVector<long int>()) {
428 return integerColumn(name, comp.asVector<long int>(), rows, width);
429 }
430 if (comp.isVector<string>()) {
431 return stringColumn(name, comp.asVector<string>(), rows, width);
432 }
433
434 // create alternative representation
435 string repr;
436 int size;
437 if (comp.isVector<vector<double>>()) {
438 repr = "[ <double> ]";
439 size = len(comp.asVector<vector<double>>());
440 } else if (comp.isVector<vector<long int>>()) {
441 repr = "[ <long int> ]";
442 size = len(comp.asVector<vector<long int>>());
443 } else if (comp.isVector<vector<string>>()) {
444 repr = "[ <string> ]";
445 size = len(comp.asVector<vector<string>>());
446 } else {
447 throw CanteraError(
448 "formatColumn", "Encountered invalid data for component '{}'.", name);
449 }
450 size_t maxLen = std::max(repr.size(), name.size());
451
452 // assemble output
453 string notation = fmt::format(" {{:>{}}}", maxLen);
454 repr = fmt::format(fmt::runtime(notation), repr);
455 vector<string> col = {fmt::format(fmt::runtime(notation), name)};
456 if (size <= rows) {
457 for (int row = 0; row < size; row++) {
458 col.push_back(repr);
459 }
460 } else {
461 int dots = (rows + 1) / 2;
462 for (int row = 0; row < dots; row++) {
463 col.push_back(repr);
464 }
465 col.push_back(fmt::format(fmt::runtime(notation), "..."));
466 for (int row = size - rows / 2; row < size; row++) {
467 col.push_back(repr);
468 }
469 }
470 return col;
471}
472
473} // end unnamed namespace
474

Callers 1

infoMethod · 0.85

Calls 6

doubleColumnFunction · 0.85
integerColumnFunction · 0.85
stringColumnFunction · 0.85
lenFunction · 0.85
CanteraErrorClass · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected