diff --git a/src/coreComponents/common/format/LogPart.cpp b/src/coreComponents/common/format/LogPart.cpp index a9ce3c69da6..1f3dac85297 100644 --- a/src/coreComponents/common/format/LogPart.cpp +++ b/src/coreComponents/common/format/LogPart.cpp @@ -61,7 +61,7 @@ void LogPart::setMaxWidth( size_t const & maxWidth ) double clamp( double v, double min, double max ) { - return std::min( max, std::max( min, v )); + return LvArray::math::min( max, LvArray::math::max( min, v )); } void LogPart::formatDescriptions( LogPart::Description & description, @@ -70,34 +70,33 @@ void LogPart::formatDescriptions( LogPart::Description & description, stdVector< string > & formattedLines = formattedDescription.m_lines; size_t const borderSpaceWidth = m_nbBorderChar * 2 + m_borderMargin * 2; - size_t const formattingCharSize = borderSpaceWidth; + size_t const decorationWidth = borderSpaceWidth; size_t & maxNameSize = formattedDescription.m_maxNameWidth; size_t & maxValueSize = formattedDescription.m_maxValueWidth; formattedLines.reserve( description.m_names.size() * 2 ); - /// clamp - m_width = std::min( m_maxWidth, std::max( m_minWidth, m_width )); + m_width = clamp( m_maxWidth, m_minWidth, m_width ); for( size_t idxName = 0; idxName < description.m_names.size(); idxName++ ) { - auto const & nonFormattedNames = description.m_names[idxName]; - auto const & nonFormattedValues = description.m_values[idxName]; + auto const & rawName = description.m_names[idxName]; + auto const & rawValues = description.m_values[idxName]; // Format name with no values associated - if( nonFormattedValues.empty()) + if( rawValues.empty()) { - size_t maxLineLength = m_width - borderSpaceWidth; - auto wrappedNames = stringutilities::wrapTextToMaxLength( nonFormattedNames, maxLineLength ); + size_t availableWidth = m_width - borderSpaceWidth; + auto wrappedNames = stringutilities::wrapTextToMaxLength( rawName, availableWidth ); for( auto & name : wrappedNames ) { auto const currMaxNameSize = std::max( name.size(), maxNameSize ); - if( currMaxNameSize + formattingCharSize < m_width ) + if( currMaxNameSize + decorationWidth < m_width ) { // append space at the end of name if needed name.reserve( m_width - borderSpaceWidth ); - name.append( std::string( m_width - currMaxNameSize - formattingCharSize, ' ' )); + name.append( std::string( m_width - currMaxNameSize - decorationWidth, ' ' )); } formattedLines.push_back( name ); } @@ -105,25 +104,25 @@ void LogPart::formatDescriptions( LogPart::Description & description, } // Format name with values assiociated - size_t maxLineLength = m_width - maxNameSize - formattingCharSize - m_delimiter.size(); - auto wrappedValues = stringutilities::wrapTextToMaxLength( nonFormattedValues, maxLineLength ); + size_t availableWidthForValues = m_width - maxNameSize - decorationWidth - m_delimiter.size(); + auto wrappedValues = stringutilities::wrapTextToMaxLength( rawValues, availableWidthForValues ); // format name - stdVector< string > formatNames {nonFormattedNames}; + stdVector< string > formatNames {rawName}; for( size_t idxSubName = 0; idxSubName < formatNames.size(); idxSubName++ ) { - size_t const spaces = idxSubName < wrappedValues.size() ? - maxNameSize - formatNames[idxSubName].size() : - m_width - formatNames[idxSubName].size() - formattingCharSize; + size_t const paddingNeeded = idxSubName < wrappedValues.size() ? + maxNameSize - formatNames[idxSubName].size() : + m_width - formatNames[idxSubName].size() - decorationWidth; // append space at the end of name if needed - formatNames[idxSubName].reserve( formatNames[idxSubName].size() + spaces ); - formatNames[idxSubName].append( spaces, ' ' ); + formatNames[idxSubName].reserve( formatNames[idxSubName].size() + paddingNeeded ); + formatNames[idxSubName].append( paddingNeeded, ' ' ); } size_t const lineCount = std::max( formatNames.size(), wrappedValues.size()); // format values - size_t const minValueSizeRequired = m_width - maxNameSize - formattingCharSize - m_delimiter.size(); + size_t const minValueSizeRequired = m_width - maxNameSize - decorationWidth - m_delimiter.size(); for( auto & wrappedValue : wrappedValues ) { wrappedValue.reserve( minValueSizeRequired ); diff --git a/src/coreComponents/common/format/LogPart.hpp b/src/coreComponents/common/format/LogPart.hpp index d4223c008b0..f69729b25bc 100644 --- a/src/coreComponents/common/format/LogPart.hpp +++ b/src/coreComponents/common/format/LogPart.hpp @@ -143,7 +143,7 @@ class LogPart /// minimal length of a log part size_t m_minWidth = 100; /// maximal length of a log part - size_t m_maxWidth = SIZE_MAX; + size_t m_maxWidth = 100; /// margin (left and right) between all descriptions and the log part borders static constexpr size_t m_borderMargin = 2; /// numbers of character used for the border @@ -194,30 +194,33 @@ void LogPart::addDescriptionBySection( Description & description, FormattedDescr string_view name, Args const &... args ) { stdVector< string > values; - size_t & maxValueSize = formattedDescription.m_maxValueWidth; - size_t & maxNameSize = formattedDescription.m_maxNameWidth; + size_t & formattedDescriptionMaxWidth = formattedDescription.m_maxValueWidth; + size_t & formattedDescriptionNameWidth = formattedDescription.m_maxNameWidth; ( [&] { static_assert( has_formatter_v< decltype(args) >, "Argument passed cannot be converted to string" ); string const value = GEOS_FMT( "{}", args ); - stdVector< string_view > splitValues = divideLines< string_view >( maxValueSize, value ); - values.insert( values.end(), splitValues.begin(), splitValues.end() ); + stdVector< string_view > dividedDescriptionValues = + divideLines< string_view >( formattedDescriptionMaxWidth, value ); + values.insert( values.end(), dividedDescriptionValues.begin(), dividedDescriptionValues.end() ); } (), ...); description.m_values.push_back( values ); - size_t lineWidth = 0; - stdVector< string > nameDivided = divideLines< string >( lineWidth, name ); - if( lineWidth == 0 ) - lineWidth = name.size(); - maxNameSize = std::max( maxNameSize, lineWidth ); + size_t nameWidth = 0; + stdVector< string > nameLines = divideLines< string >( nameWidth, name ); + if( nameWidth == 0 ) + nameWidth = name.size(); + formattedDescriptionNameWidth = std::max( formattedDescriptionNameWidth, nameWidth ); - description.m_names.push_back( nameDivided ); + description.m_names.push_back( nameLines ); - size_t const formattingCharSize = m_nbBorderChar * 2 + m_borderMargin * 2; - size_t const currentTotalWidth = maxNameSize + maxValueSize + formattingCharSize; - m_width = std::max( m_width, currentTotalWidth ); + size_t const totalDecorationWidth = m_nbBorderChar * 2 + m_borderMargin * 2; + size_t const logPartTotalWidth = formattedDescriptionNameWidth + + formattedDescriptionMaxWidth + + totalDecorationWidth; + m_width = std::max( m_width, logPartTotalWidth ); m_width = std::max( m_width, formattedDescription.m_title.size()); }