Add make_shared emulation for std::tr1::shared_ptr; use make_shared

This commit is contained in:
John Hood
2014-06-15 00:59:55 -04:00
parent b41bad918d
commit 589d21bbf2
4 changed files with 49 additions and 9 deletions
+7 -3
View File
@@ -148,14 +148,16 @@ std::string Display::new_frame( bool initialized, const Framebuffer &last, const
/* Extend rows if we've gotten a resize and new is wider than old */
if ( frame.last_frame.ds.get_width() < f.ds.get_width() ) {
for ( Framebuffer::rows_type::iterator p = rows.begin(); p != rows.end(); p++ ) {
*p = Framebuffer::row_pointer( new Row( **p ) );
*p = make_shared<Row>( **p );
(*p)->cells.resize( f.ds.get_width(), Cell( f.ds.get_background_rendition() ) );
}
}
/* Add rows if we've gotten a resize and new is taller than old */
if ( static_cast<int>( rows.size() ) < f.ds.get_height() ) {
// get a proper blank row
blank_row = Framebuffer::row_pointer( new Row( f.ds.get_width(), 0 ) );
const size_t w = f.ds.get_width();
const color_type c = 0;
blank_row = make_shared<Row>( w, c );
rows.resize( f.ds.get_height(), blank_row );
}
@@ -198,7 +200,9 @@ std::string Display::new_frame( bool initialized, const Framebuffer &last, const
if ( lines_scrolled ) {
/* Now we need a proper blank row. */
if ( blank_row.get() == NULL ) {
blank_row = Framebuffer::row_pointer( new Row( f.ds.get_width(), 0 ) );
const size_t w = f.ds.get_width();
const color_type c = 0;
blank_row = make_shared<Row>( w, c );
}
frame.update_rendition( initial_rendition(), true );
+6 -3
View File
@@ -84,10 +84,13 @@ DrawState::DrawState( int s_width, int s_height )
}
Framebuffer::Framebuffer( int s_width, int s_height )
: rows( s_height, row_pointer(new Row( s_width, 0 ))), icon_name(), window_title(), bell_count( 0 ), title_initialized( false ), ds( s_width, s_height )
: rows(), icon_name(), window_title(), bell_count( 0 ), title_initialized( false ), ds( s_width, s_height )
{
assert( s_height > 0 );
assert( s_width > 0 );
const size_t w = s_width;
const color_type c = 0;
rows = rows_type(s_height, row_pointer(make_shared<Row>( w, c )));
}
Framebuffer::Framebuffer( const Framebuffer &other )
@@ -334,7 +337,7 @@ void Framebuffer::delete_line( int row, int count )
rows.insert( start, count, newrow());
}
Row::Row( size_t s_width, color_type background_color )
Row::Row( const size_t s_width, const color_type background_color )
: cells( s_width, Cell( background_color ) ), wrap( false ), gen( get_gen() )
{}
@@ -424,7 +427,7 @@ void Framebuffer::resize( int s_width, int s_height )
for ( rows_type::iterator i = rows.begin();
i != rows.end() && *i != blankrow;
i++ ) {
*i = Framebuffer::row_pointer( new Row( **i ) );
*i = make_shared<Row>( **i );
(*i)->set_wrap( false );
(*i)->cells.resize( s_width, Cell( ds.get_background_rendition() ) );
}
+9 -3
View File
@@ -48,6 +48,7 @@
namespace Terminal {
using shared::shared_ptr;
using shared::make_shared;
typedef uint16_t color_type;
class Renditions {
@@ -156,7 +157,7 @@ namespace Terminal {
// in scrolling.
uint64_t gen;
Row( size_t s_width, color_type background_color );
Row( const size_t s_width, const color_type background_color );
Row(); /* default constructor required by C++11 STL */
void insert_cell( int col, color_type background_color );
@@ -315,7 +316,12 @@ namespace Terminal {
unsigned int bell_count;
bool title_initialized; /* true if the window title has been set via an OSC */
row_pointer newrow( void ) { return row_pointer( new Row( ds.get_width(), ds.get_background_rendition())); }
row_pointer newrow( void )
{
const size_t w = ds.get_width();
const color_type c = ds.get_background_rendition();
return make_shared<Row>( w, c );
}
public:
Framebuffer( int s_width, int s_height );
@@ -349,7 +355,7 @@ namespace Terminal {
row_pointer &mutable_row = rows.at( row );
// If the row is shared, copy it.
if (!mutable_row.unique()) {
mutable_row = row_pointer( new Row( *mutable_row ));
mutable_row = make_shared<Row>( *mutable_row );
}
return mutable_row.get();
}