-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Refactoring dump input option #3566
base: develop
Are you sure you want to change the base?
Changes from 8 commits
22bdce6
886e9a8
7048069
22d3454
93fc6b2
3b42190
f6b4df7
e4ff33f
e44cb45
24c3e4d
4eedd40
6b4f4f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -241,6 +241,68 @@ void TableTextFormatter::setLinks( std::vector< TableLayout::Column > & columns | |
} | ||
} | ||
|
||
std::string_view ltrim( std::string_view s ) | ||
{ | ||
std::size_t const first = s.find_first_not_of( " " ); | ||
if( first != std::string::npos ) | ||
{ | ||
return s.substr( first, ( s.size() - first ) ); | ||
} | ||
return {}; | ||
} | ||
|
||
bool formatLinesWithMaxSize( std::vector< std::string > & cellLines, size_t maxLength ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. those two functions can be helpful! You could generalize a bit (erase table/cell namings) and add them to Also, this function produces incorrect results for |
||
{ | ||
std::vector< std::string > formattedDescription; | ||
bool returnLineSet = false; | ||
for( auto & line : cellLines ) | ||
{ | ||
size_t startIdx = 0; | ||
size_t endIdx = 0; | ||
size_t captureLength = 0; | ||
size_t delimIdx = 0; | ||
while( endIdx < line.size()) | ||
{ | ||
endIdx = line.find( ' ', delimIdx ); | ||
if( endIdx == std::string::npos ) | ||
{ | ||
std::string remaining = line.substr( startIdx ); | ||
// Check if the remaining substring exceeds maxLength | ||
if( remaining.size() > maxLength ) | ||
{ | ||
returnLineSet = true; | ||
formattedDescription.push_back( std::string( ltrim( line.substr( startIdx, captureLength )))); | ||
if( captureLength < remaining.size()) | ||
{ | ||
formattedDescription.push_back( std::string( ltrim( line.substr( startIdx + captureLength ))) ); | ||
} | ||
} | ||
else | ||
{ | ||
formattedDescription.push_back( std::string( ltrim( line.substr( startIdx, endIdx )))); | ||
} | ||
} | ||
else | ||
{ | ||
size_t wordsLength = endIdx - startIdx; | ||
// Check if the capture exceeds maxLength | ||
if( wordsLength > maxLength ) | ||
{ | ||
returnLineSet = true; | ||
formattedDescription.push_back( std::string( ltrim( line.substr( startIdx, captureLength )))); | ||
startIdx = delimIdx; | ||
captureLength = 0; | ||
} | ||
|
||
delimIdx = endIdx + 1; | ||
captureLength = wordsLength; | ||
} | ||
} | ||
} | ||
cellLines = formattedDescription; | ||
return returnLineSet; | ||
} | ||
|
||
void TableTextFormatter::populateHeaderCellsLayout( TableLayout & tableLayout, | ||
CellLayoutRows & cellsHeaderLayout ) const | ||
{ | ||
|
@@ -263,7 +325,6 @@ void TableTextFormatter::populateHeaderCellsLayout( TableLayout & tableLayout, | |
cellsHeaderLayout[idxRow + 1].push_back( emptyCell ); | ||
} | ||
} | ||
currentCell.m_cellWidth = it->m_header.m_cellWidth; | ||
|
||
if( it->hasParent() ) | ||
{ | ||
|
@@ -291,6 +352,14 @@ void TableTextFormatter::populateHeaderCellsLayout( TableLayout & tableLayout, | |
cellsHeaderLayout[currentLayer].push_back( mergingCell ); | ||
} | ||
|
||
if( tableLayout.isMaxColumnWidthSet()) | ||
{ | ||
formatLinesWithMaxSize( currentCell.m_lines, tableLayout.getMaxWidth() ); | ||
sublineHeaderCounts[currentLayer] = std::max( sublineHeaderCounts[currentLayer], | ||
currentCell.m_lines.size() ); | ||
|
||
} | ||
|
||
cellsHeaderLayout[currentLayer].push_back( currentCell ); | ||
} | ||
|
||
|
@@ -343,7 +412,12 @@ void TableTextFormatter::populateDataCellsLayout( TableLayout & tableLayout, | |
cell.value = m_horizontalLine; | ||
} | ||
|
||
cellsDataLayout[idxRow][idxColumn] = TableLayout::CellLayout( cell.type, cell.value, alignement ); | ||
TableLayout::CellLayout dataToCell( cell.type, cell.value, alignement ); | ||
if( tableLayout.isMaxColumnWidthSet()) | ||
{ | ||
formatLinesWithMaxSize( dataToCell.m_lines, tableLayout.getMaxWidth() ); | ||
} | ||
cellsDataLayout[idxRow][idxColumn] = dataToCell; | ||
maxLinesPerRow = std::max( maxLinesPerRow, cellsDataLayout[idxRow][idxColumn].m_lines.size() ); | ||
idxColumn++; | ||
} | ||
|
@@ -396,31 +470,35 @@ void TableTextFormatter::updateColumnMaxLength( TableLayout & tableLayout, | |
}; | ||
|
||
size_t const numColumns = cellsHeaderLayout[0].size(); | ||
//each idx per row | ||
std::vector< size_t > accMaxStringColumn( cellsDataLayout.size(), 0 ); | ||
|
||
// Accumulates column lengths for each line based on "MergeNext" tag. | ||
std::vector< size_t > linesLength( cellsDataLayout.size(), 0 ); | ||
for( size_t idxColumn = 0; idxColumn < numColumns; ++idxColumn ) | ||
{ | ||
size_t maxColumnSize = 1; | ||
|
||
// init header column max length | ||
for( size_t rowIdx = 0; rowIdx < cellsDataLayout.size(); ++rowIdx ) | ||
{ | ||
size_t const cellDataLength = getMaxLineLength( cellsDataLayout[rowIdx][idxColumn].m_lines ); | ||
if( idxColumn == 0 || | ||
(idxColumn > 0 && cellsDataLayout[rowIdx][idxColumn - 1].m_cellType != CellType::MergeNext)) | ||
|
||
{ // retrieves the maximum length of the current column | ||
// and set each header column to maxColumnSize | ||
for( size_t rowIdx = 0; rowIdx < cellsDataLayout.size(); ++rowIdx ) | ||
{ | ||
maxColumnSize = std::max( maxColumnSize, cellDataLength ); | ||
size_t const cellDataLength = getMaxLineLength( cellsDataLayout[rowIdx][idxColumn].m_lines ); | ||
if( idxColumn == 0 || | ||
(idxColumn > 0 && cellsDataLayout[rowIdx][idxColumn - 1].m_cellType != CellType::MergeNext)) | ||
{ | ||
maxColumnSize = std::max( maxColumnSize, cellDataLength ); | ||
} | ||
} | ||
} | ||
|
||
for( size_t rowIdx = 0; rowIdx < cellsHeaderLayout.size(); ++rowIdx ) | ||
{ | ||
size_t const cellHeaderLength = getMaxLineLength( cellsHeaderLayout[rowIdx][idxColumn].m_lines ); | ||
maxColumnSize = std::max( {maxColumnSize, cellHeaderLength} ); | ||
cellsHeaderLayout[rowIdx][idxColumn].m_cellWidth = maxColumnSize; | ||
for( size_t rowIdx = 0; rowIdx < cellsHeaderLayout.size(); ++rowIdx ) | ||
{ | ||
size_t const cellHeaderLength = getMaxLineLength( cellsHeaderLayout[rowIdx][idxColumn].m_lines ); | ||
maxColumnSize = std::max( {maxColumnSize, cellHeaderLength} ); | ||
cellsHeaderLayout[rowIdx][idxColumn].m_cellWidth = maxColumnSize; | ||
} | ||
} | ||
|
||
// update maxColumnSize for data cell | ||
// updates the maximum cell size for the current column | ||
for( size_t rowIdx = 0; rowIdx < cellsDataLayout.size(); ++rowIdx ) | ||
{ | ||
TableLayout::CellLayout & dataCell = cellsDataLayout[rowIdx][idxColumn]; | ||
|
@@ -430,14 +508,13 @@ void TableTextFormatter::updateColumnMaxLength( TableLayout & tableLayout, | |
|
||
if( dataCell.m_cellType == CellType::MergeNext ) | ||
{ | ||
accMaxStringColumn[rowIdx] += cellsHeaderLayout[0][idxColumn].m_cellWidth + tableLayout.getColumnMargin(); | ||
linesLength[rowIdx] += cellsHeaderLayout[0][idxColumn].m_cellWidth + tableLayout.getColumnMargin(); | ||
} | ||
|
||
if( idxColumn > 0 && | ||
previousDataCell->m_cellType == CellType::MergeNext && dataCell.m_cellType != CellType::MergeNext ) | ||
{ | ||
// root header cells know the maximum string size in the column | ||
size_t const sumOfMergingCell = accMaxStringColumn[rowIdx] + cellsHeaderLayout[0][idxColumn].m_cellWidth; | ||
size_t const sumOfMergingCell = linesLength[rowIdx] + cellsHeaderLayout[0][idxColumn].m_cellWidth; | ||
if( sumOfMergingCell < dataCell.m_cellWidth ) | ||
{ | ||
maxColumnSize -= dataCell.m_cellWidth - sumOfMergingCell; | ||
|
@@ -454,7 +531,7 @@ void TableTextFormatter::updateColumnMaxLength( TableLayout & tableLayout, | |
} | ||
} | ||
|
||
accMaxStringColumn[rowIdx] = 0; | ||
linesLength[rowIdx] = 0; | ||
} | ||
else | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -453,6 +453,20 @@ class TableLayout | |
*/ | ||
TableLayout & setMargin( MarginValue marginValue ); | ||
|
||
/** | ||
* @brief Set the maximal width for each column | ||
* @param width The max column width | ||
* @return The tableLayout reference | ||
*/ | ||
TableLayout & setMaxColumnWidth( size_t width ); | ||
|
||
/** | ||
* @brief check if a column max width has been set | ||
* @return Truef a column max width has been set, otherwise false | ||
*/ | ||
bool isMaxColumnWidthSet() | ||
{ return m_hasMaxColumnWidthSet; } | ||
|
||
/** | ||
* @return check if the line break at the end & beginning is activated | ||
*/ | ||
|
@@ -485,6 +499,12 @@ class TableLayout | |
integer const & getMarginTitle() const | ||
{ return m_titleMargin; } | ||
|
||
/** | ||
* @return The margin title | ||
*/ | ||
size_t const & getMaxWidth() const | ||
{ return m_tableColumnMaxWidth; } | ||
|
||
/** | ||
* @brief Get the Nb Rows object | ||
* @return std::vector< integer >& | ||
|
@@ -552,9 +572,14 @@ class TableLayout | |
std::vector< size_t > m_sublineHeaderCounts; | ||
/// Contains the subdivision (line) counts for each line in data. | ||
std::vector< size_t > m_sublineDataCounts; | ||
bool m_wrapLine = true; | ||
|
||
// Indicate if we have a line break a the beginning of the table | ||
bool m_lineBreakAtBegin = true; | ||
// Contain the table tible | ||
string m_tableTitle; | ||
// Contain the max width for each column | ||
size_t m_tableColumnMaxWidth = std::numeric_limits< size_t >::max(); | ||
// Indicate if a max column width has been set | ||
bool m_hasMaxColumnWidthSet = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could only keep one attribute here: using NoColumnMaxWidth = std::numeric_limits< size_t >::max();
size_t m_tableColumnMaxWidth = NoColumnMaxWidth; And in |
||
|
||
integer m_borderMargin; | ||
integer m_columnMargin; | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -17,6 +17,9 @@ | |||||
#include "Group.hpp" | ||||||
#include "ConduitRestart.hpp" | ||||||
#include "common/format/StringUtilities.hpp" | ||||||
#include "common/format/table/TableData.hpp" | ||||||
#include "common/format/table/TableFormatter.hpp" | ||||||
#include "common/format/table/TableLayout.hpp" | ||||||
#include "codingUtilities/Utilities.hpp" | ||||||
#include "common/TimingMacros.hpp" | ||||||
#include "GroupContext.hpp" | ||||||
|
@@ -302,13 +305,29 @@ string Group::dumpInputOptions() const | |||||
{ | ||||||
string rval; | ||||||
|
||||||
bool writeHeader = true; | ||||||
TableLayout logLayout( "", {TableLayout::Column() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
.setName( "name" ) | ||||||
.setValuesAlignment( TableLayout::Alignment::left ), | ||||||
"flag", | ||||||
TableLayout::Column() | ||||||
.setName( "Description" ) | ||||||
.setValuesAlignment( TableLayout::Alignment::left ) } ); | ||||||
logLayout.setMaxColumnWidth( 80 ); | ||||||
TableData logData; | ||||||
for( auto const & wrapper : m_wrappers ) | ||||||
{ | ||||||
rval.append( wrapper.second->dumpInputOptions( writeHeader ) ); | ||||||
writeHeader = false; | ||||||
if( wrapper.second->getInputFlag() == InputFlags::OPTIONAL || | ||||||
wrapper.second->getInputFlag() == InputFlags::REQUIRED ) | ||||||
{ | ||||||
logData.addRow( wrapper.second->getName(), | ||||||
InputFlagToString( wrapper.second->getInputFlag() ), | ||||||
wrapper.second->getDescription() ); | ||||||
} | ||||||
} | ||||||
|
||||||
TableTextFormatter logFormatter( logLayout ); | ||||||
rval.append( logFormatter.toString( logData )); | ||||||
|
||||||
return rval; | ||||||
} | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be constexpr.