Add make_shared emulation for std::tr1::shared_ptr; use make_shared
This commit is contained in:
@@ -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 );
|
||||
|
||||
|
||||
@@ -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() ) );
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -42,9 +42,36 @@
|
||||
namespace shared {
|
||||
#ifdef HAVE_STD_SHARED_PTR
|
||||
using std::shared_ptr;
|
||||
using std::make_shared;
|
||||
#else
|
||||
#ifdef HAVE_STD_TR1_SHARED_PTR
|
||||
using std::tr1::shared_ptr;
|
||||
|
||||
// make_shared emulation.
|
||||
template<typename Tp, typename A1>
|
||||
inline shared_ptr<Tp>
|
||||
make_shared(const A1& a1)
|
||||
{
|
||||
return shared_ptr<Tp>(new Tp(a1));
|
||||
}
|
||||
template<typename Tp, typename A1, typename A2>
|
||||
inline shared_ptr<Tp>
|
||||
make_shared(const A1& a1, const A2& a2)
|
||||
{
|
||||
return shared_ptr<Tp>(new Tp(a1, a2));
|
||||
}
|
||||
template<typename Tp, typename A1, typename A2, typename A3>
|
||||
inline shared_ptr<Tp>
|
||||
make_shared(const A1& a1, const A2& a2, const A3& a3)
|
||||
{
|
||||
return shared_ptr<Tp>(new Tp(a1, a2, a3));
|
||||
}
|
||||
template<typename Tp, typename A1, typename A2, typename A3, typename A4>
|
||||
inline shared_ptr<Tp>
|
||||
make_shared(const A1& a1, const A2& a2, const A3& a3, const A4& a4)
|
||||
{
|
||||
return shared_ptr<Tp>(new Tp(a1, a2, a3, a4));
|
||||
}
|
||||
#else
|
||||
#error Need a shared_ptr class. Try Boost::TR1.
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user