mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +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 );
|
optWidth = ( std::min )( optWidth, consoleWidth / 2 );
|
||||||
|
|
||||||
for ( auto const& cols : rows ) {
|
for ( auto& cols : rows ) {
|
||||||
auto row = TextFlow::Column( cols.left )
|
auto row = TextFlow::Column( CATCH_MOVE(cols.left) )
|
||||||
.width( optWidth )
|
.width( optWidth )
|
||||||
.indent( 2 ) +
|
.indent( 2 ) +
|
||||||
TextFlow::Spacer( 4 ) +
|
TextFlow::Spacer( 4 ) +
|
||||||
|
@ -233,23 +233,36 @@ namespace Catch {
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
Columns Column::operator+( Column const& other ) {
|
Columns operator+(Column const& lhs, Column const& rhs) {
|
||||||
Columns cols;
|
Columns cols;
|
||||||
cols += *this;
|
cols += lhs;
|
||||||
cols += other;
|
cols += rhs;
|
||||||
|
return cols;
|
||||||
|
}
|
||||||
|
Columns operator+(Column&& lhs, Column&& rhs) {
|
||||||
|
Columns cols;
|
||||||
|
cols += CATCH_MOVE( lhs );
|
||||||
|
cols += CATCH_MOVE( rhs );
|
||||||
return cols;
|
return cols;
|
||||||
}
|
}
|
||||||
|
|
||||||
Columns& Columns::operator+=( Column const& col ) {
|
Columns& operator+=(Columns& lhs, Column const& rhs) {
|
||||||
m_columns.push_back( col );
|
lhs.m_columns.push_back( rhs );
|
||||||
return *this;
|
return lhs;
|
||||||
}
|
}
|
||||||
|
Columns& operator+=(Columns& lhs, Column&& rhs) {
|
||||||
Columns Columns::operator+( Column const& col ) {
|
lhs.m_columns.push_back( CATCH_MOVE(rhs) );
|
||||||
Columns combined = *this;
|
return lhs;
|
||||||
combined += col;
|
}
|
||||||
|
Columns operator+( Columns const& lhs, Column const& rhs ) {
|
||||||
|
auto combined( lhs );
|
||||||
|
combined += rhs;
|
||||||
return combined;
|
return combined;
|
||||||
}
|
}
|
||||||
|
Columns operator+( Columns&& lhs, Column&& rhs ) {
|
||||||
|
lhs += CATCH_MOVE( rhs );
|
||||||
|
return CATCH_MOVE( lhs );
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace TextFlow
|
} // namespace TextFlow
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
@ -8,8 +8,10 @@
|
|||||||
#ifndef CATCH_TEXTFLOW_HPP_INCLUDED
|
#ifndef CATCH_TEXTFLOW_HPP_INCLUDED
|
||||||
#define CATCH_TEXTFLOW_HPP_INCLUDED
|
#define CATCH_TEXTFLOW_HPP_INCLUDED
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <catch2/internal/catch_console_width.hpp>
|
#include <catch2/internal/catch_console_width.hpp>
|
||||||
|
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -37,7 +39,7 @@ namespace Catch {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Iterates "lines" in `Column` and return sthem
|
* Iterates "lines" in `Column` and returns them
|
||||||
*/
|
*/
|
||||||
class const_iterator {
|
class const_iterator {
|
||||||
friend Column;
|
friend Column;
|
||||||
@ -91,20 +93,35 @@ namespace Catch {
|
|||||||
using iterator = const_iterator;
|
using iterator = const_iterator;
|
||||||
|
|
||||||
explicit Column( std::string const& text ): m_string( text ) {}
|
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 );
|
assert( newWidth > 0 );
|
||||||
m_width = newWidth;
|
m_width = newWidth;
|
||||||
return *this;
|
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;
|
m_indent = newIndent;
|
||||||
return *this;
|
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;
|
m_initialIndent = newIndent;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
Column&& initialIndent( size_t newIndent ) && {
|
||||||
|
m_initialIndent = newIndent;
|
||||||
|
return CATCH_MOVE( *this );
|
||||||
|
}
|
||||||
|
|
||||||
size_t width() const { return m_width; }
|
size_t width() const { return m_width; }
|
||||||
const_iterator begin() const { return const_iterator( *this ); }
|
const_iterator begin() const { return const_iterator( *this ); }
|
||||||
@ -113,7 +130,8 @@ namespace Catch {
|
|||||||
friend std::ostream& operator<<( std::ostream& os,
|
friend std::ostream& operator<<( std::ostream& os,
|
||||||
Column const& col );
|
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
|
//! 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 begin() const { return iterator( *this ); }
|
||||||
iterator end() const { return { *this, iterator::EndTag() }; }
|
iterator end() const { return { *this, iterator::EndTag() }; }
|
||||||
|
|
||||||
Columns& operator+=( Column const& col );
|
friend Columns& operator+=( Columns& lhs, Column const& rhs );
|
||||||
Columns operator+( Column const& col );
|
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,
|
friend std::ostream& operator<<( std::ostream& os,
|
||||||
Columns const& cols );
|
Columns const& cols );
|
||||||
|
@ -315,11 +315,10 @@ public:
|
|||||||
*this << RowBreak();
|
*this << RowBreak();
|
||||||
|
|
||||||
TextFlow::Columns headerCols;
|
TextFlow::Columns headerCols;
|
||||||
auto spacer = TextFlow::Spacer(2);
|
|
||||||
for (auto const& info : m_columnInfos) {
|
for (auto const& info : m_columnInfos) {
|
||||||
assert(info.width > 2);
|
assert(info.width > 2);
|
||||||
headerCols += TextFlow::Column(info.name).width(info.width - 2);
|
headerCols += TextFlow::Column(info.name).width(info.width - 2);
|
||||||
headerCols += spacer;
|
headerCols += TextFlow::Spacer( 2 );
|
||||||
}
|
}
|
||||||
m_os << headerCols << '\n';
|
m_os << headerCols << '\n';
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user