mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-22 11:23:29 +01:00
Move-enable various parts of TextFlow
This removes about 200 pointless copies from printing the help message (the original motivation for the change), and also nicely improves performance of the various reporters that depend on TextFlow.
This commit is contained in:
parent
eaafd07674
commit
b52d97855d
@ -366,8 +366,8 @@ namespace Catch {
|
||||
|
||||
optWidth = ( std::min )( optWidth, consoleWidth / 2 );
|
||||
|
||||
for ( auto const& cols : rows ) {
|
||||
auto row = TextFlow::Column( cols.left )
|
||||
for ( auto& cols : rows ) {
|
||||
auto row = TextFlow::Column( CATCH_MOVE(cols.left) )
|
||||
.width( optWidth )
|
||||
.indent( 2 ) +
|
||||
TextFlow::Spacer( 4 ) +
|
||||
|
@ -233,23 +233,36 @@ namespace Catch {
|
||||
return os;
|
||||
}
|
||||
|
||||
Columns Column::operator+( Column const& other ) {
|
||||
Columns operator+(Column const& lhs, Column const& rhs) {
|
||||
Columns cols;
|
||||
cols += *this;
|
||||
cols += other;
|
||||
cols += lhs;
|
||||
cols += rhs;
|
||||
return cols;
|
||||
}
|
||||
Columns operator+(Column&& lhs, Column&& rhs) {
|
||||
Columns cols;
|
||||
cols += CATCH_MOVE( lhs );
|
||||
cols += CATCH_MOVE( rhs );
|
||||
return cols;
|
||||
}
|
||||
|
||||
Columns& Columns::operator+=( Column const& col ) {
|
||||
m_columns.push_back( col );
|
||||
return *this;
|
||||
Columns& operator+=(Columns& lhs, Column const& rhs) {
|
||||
lhs.m_columns.push_back( rhs );
|
||||
return lhs;
|
||||
}
|
||||
|
||||
Columns Columns::operator+( Column const& col ) {
|
||||
Columns combined = *this;
|
||||
combined += col;
|
||||
Columns& operator+=(Columns& lhs, Column&& rhs) {
|
||||
lhs.m_columns.push_back( CATCH_MOVE(rhs) );
|
||||
return lhs;
|
||||
}
|
||||
Columns operator+( Columns const& lhs, Column const& rhs ) {
|
||||
auto combined( lhs );
|
||||
combined += rhs;
|
||||
return combined;
|
||||
}
|
||||
Columns operator+( Columns&& lhs, Column&& rhs ) {
|
||||
lhs += CATCH_MOVE( rhs );
|
||||
return CATCH_MOVE( lhs );
|
||||
}
|
||||
|
||||
} // namespace TextFlow
|
||||
} // namespace Catch
|
||||
|
@ -8,8 +8,10 @@
|
||||
#ifndef CATCH_TEXTFLOW_HPP_INCLUDED
|
||||
#define CATCH_TEXTFLOW_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include <catch2/internal/catch_console_width.hpp>
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -37,7 +39,7 @@ namespace Catch {
|
||||
|
||||
public:
|
||||
/**
|
||||
* Iterates "lines" in `Column` and return sthem
|
||||
* Iterates "lines" in `Column` and returns them
|
||||
*/
|
||||
class const_iterator {
|
||||
friend Column;
|
||||
@ -91,20 +93,35 @@ namespace Catch {
|
||||
using iterator = const_iterator;
|
||||
|
||||
explicit Column( std::string const& text ): m_string( text ) {}
|
||||
explicit Column( std::string&& text ):
|
||||
m_string( CATCH_MOVE(text)) {}
|
||||
|
||||
Column& width( size_t newWidth ) {
|
||||
Column& width( size_t newWidth ) & {
|
||||
assert( newWidth > 0 );
|
||||
m_width = newWidth;
|
||||
return *this;
|
||||
}
|
||||
Column& indent( size_t newIndent ) {
|
||||
Column&& width( size_t newWidth ) && {
|
||||
assert( newWidth > 0 );
|
||||
m_width = newWidth;
|
||||
return CATCH_MOVE( *this );
|
||||
}
|
||||
Column& indent( size_t newIndent ) & {
|
||||
m_indent = newIndent;
|
||||
return *this;
|
||||
}
|
||||
Column& initialIndent( size_t newIndent ) {
|
||||
Column&& indent( size_t newIndent ) && {
|
||||
m_indent = newIndent;
|
||||
return CATCH_MOVE( *this );
|
||||
}
|
||||
Column& initialIndent( size_t newIndent ) & {
|
||||
m_initialIndent = newIndent;
|
||||
return *this;
|
||||
}
|
||||
Column&& initialIndent( size_t newIndent ) && {
|
||||
m_initialIndent = newIndent;
|
||||
return CATCH_MOVE( *this );
|
||||
}
|
||||
|
||||
size_t width() const { return m_width; }
|
||||
const_iterator begin() const { return const_iterator( *this ); }
|
||||
@ -113,7 +130,8 @@ namespace Catch {
|
||||
friend std::ostream& operator<<( std::ostream& os,
|
||||
Column const& col );
|
||||
|
||||
Columns operator+( Column const& other );
|
||||
friend Columns operator+( Column const& lhs, Column const& rhs );
|
||||
friend Columns operator+( Column&& lhs, Column&& rhs );
|
||||
};
|
||||
|
||||
//! Creates a column that serves as an empty space of specific width
|
||||
@ -157,8 +175,10 @@ namespace Catch {
|
||||
iterator begin() const { return iterator( *this ); }
|
||||
iterator end() const { return { *this, iterator::EndTag() }; }
|
||||
|
||||
Columns& operator+=( Column const& col );
|
||||
Columns operator+( Column const& col );
|
||||
friend Columns& operator+=( Columns& lhs, Column const& rhs );
|
||||
friend Columns& operator+=( Columns& lhs, Column&& rhs );
|
||||
friend Columns operator+( Columns const& lhs, Column const& rhs );
|
||||
friend Columns operator+( Columns&& lhs, Column&& rhs );
|
||||
|
||||
friend std::ostream& operator<<( std::ostream& os,
|
||||
Columns const& cols );
|
||||
|
@ -315,11 +315,10 @@ public:
|
||||
*this << RowBreak();
|
||||
|
||||
TextFlow::Columns headerCols;
|
||||
auto spacer = TextFlow::Spacer(2);
|
||||
for (auto const& info : m_columnInfos) {
|
||||
assert(info.width > 2);
|
||||
headerCols += TextFlow::Column(info.name).width(info.width - 2);
|
||||
headerCols += spacer;
|
||||
headerCols += TextFlow::Spacer( 2 );
|
||||
}
|
||||
m_os << headerCols << '\n';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user