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

Function integerColumn

src/base/SolutionArray.cpp:314–375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

312}
313
314vector<string> integerColumn(string name, const vector<long int>& comp,
315 int rows, int width)
316{
317 // extract data for processing
318 vector<long int> data;
319 string notation = fmt::format("{{:{}}}", width);
320 size_t maxLen = 2; // minimum column width is 2
321 int csize = static_cast<int>(comp.size());
322 int dots = csize + 1;
323 if (csize <= rows) {
324 for (const auto& val : comp) {
325 data.push_back(val);
326 string formatted = boost::trim_copy(
327 fmt::format(fmt::runtime(notation), val));
328 if (formatted[0] == '-') {
329 formatted = formatted.substr(1);
330 }
331 maxLen = std::max(maxLen, formatted.size());
332 }
333 } else {
334 dots = (rows + 1) / 2;
335 for (int row = 0; row < dots; row++) {
336 data.push_back(comp[row]);
337 string formatted = boost::trim_copy(
338 fmt::format(fmt::runtime(notation), comp[row]));
339 if (formatted[0] == '-') {
340 formatted = formatted.substr(1);
341 }
342 maxLen = std::max(maxLen, formatted.size());
343 }
344 for (int row = csize - rows / 2; row < csize; row++) {
345 data.push_back(comp[row]);
346 string formatted = boost::trim_copy(
347 fmt::format(fmt::runtime(notation), comp[row]));
348 if (formatted[0] == '-') {
349 formatted = formatted.substr(1);
350 }
351 maxLen = std::max(maxLen, formatted.size());
352 }
353 }
354
355 if (name == "") {
356 // index column
357 notation = fmt::format("{{:<{}}}", maxLen);
358 } else {
359 // regular column
360 maxLen = std::max(maxLen, name.size());
361 notation = fmt::format(" {{:>{}}}", maxLen + 1);
362 }
363
364 // assemble output
365 vector<string> col = {fmt::format(fmt::runtime(notation), name)};
366 int count = 0;
367 for (const auto& val : data) {
368 col.push_back(fmt::format(fmt::runtime(notation), val));
369 count++;
370 if (count == dots) {
371 col.push_back(fmt::format(fmt::runtime(notation), ".."));

Callers 2

formatColumnFunction · 0.85
infoMethod · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected