2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-10 17:47:42 +00:00

General: Use std::make_unique where applicable

No behavior change.
This commit is contained in:
Lioncash
2019-09-05 18:16:21 -04:00
parent 81beae5526
commit 765c51776b
14 changed files with 118 additions and 106 deletions

View File

@@ -43,12 +43,13 @@ Table::Table(ViewResources& res, View& parentView, ITableDataBinding* data, ITab
, m_data(data)
, m_state(state)
, m_maxColumns(maxColumns)
, m_hVerts(new SolidShaderVert[maxColumns * 6])
, m_hVerts(std::make_unique<SolidShaderVert[]>(maxColumns * 6))
, m_rowsView(*this, res) {
if (!maxColumns)
if (maxColumns == 0) {
Log.report(logvisor::Fatal, fmt("0-column tables not supported"));
}
m_scroll.m_view.reset(new ScrollView(res, *this, ScrollView::Style::ThinIndicator));
m_scroll.m_view = std::make_unique<ScrollView>(res, *this, ScrollView::Style::ThinIndicator);
commitResources(res, [&](boo::IGraphicsDataFactory::Context& ctx) -> bool {
buildResources(ctx, res);
@@ -63,7 +64,7 @@ Table::Table(ViewResources& res, View& parentView, ITableDataBinding* data, ITab
Table::~Table() = default;
Table::RowsView::RowsView(Table& t, ViewResources& res)
: View(res, t), m_t(t), m_verts(new SolidShaderVert[SPECTER_TABLE_MAX_ROWS * t.m_maxColumns * 6]) {
: View(res, t), m_t(t), m_verts(std::make_unique<SolidShaderVert[]>(SPECTER_TABLE_MAX_ROWS * t.m_maxColumns * 6)) {
commitResources(res, [&](boo::IGraphicsDataFactory::Context& ctx) -> bool {
buildResources(ctx, res);
m_vertsBinding.init(ctx, res, SPECTER_TABLE_MAX_ROWS * t.m_maxColumns * 6, m_viewVertBlockBuf);
@@ -72,7 +73,7 @@ Table::RowsView::RowsView(Table& t, ViewResources& res)
}
Table::CellView::CellView(Table& t, ViewResources& res)
: View(res, t), m_t(t), m_text(new TextView(res, *this, res.m_mainFont)) {}
: View(res, t), m_t(t), m_text(std::make_unique<TextView>(res, *this, res.m_mainFont)) {}
void Table::_setHeaderVerts(const boo::SWindowRect& sub) {
;
@@ -532,18 +533,23 @@ std::vector<Table::ColumnPool>& Table::ensureCellPools(size_t rows, size_t cols,
for (size_t i = 0; i < cols; ++i) {
ColumnPool& cp = m_cellPools[i];
if (rows > SPECTER_TABLE_MAX_ROWS) {
for (int p = 0; p < 2; ++p)
for (ViewChild<std::unique_ptr<CellView>>& cv : cp[p])
if (!cv.m_view)
cv.m_view.reset(new CellView(*this, res));
for (int p = 0; p < 2; ++p) {
for (ViewChild<std::unique_ptr<CellView>>& cv : cp[p]) {
if (cv.m_view == nullptr) {
cv.m_view = std::make_unique<CellView>(*this, res);
}
}
}
} else {
size_t r = 0;
for (ViewChild<std::unique_ptr<CellView>>& cv : cp[0]) {
if (!cv.m_view)
cv.m_view.reset(new CellView(*this, res));
if (cv.m_view == nullptr) {
cv.m_view = std::make_unique<CellView>(*this, res);
}
++r;
if (r >= rows)
if (r >= rows) {
break;
}
}
}
}
@@ -579,10 +585,12 @@ void Table::_updateData() {
for (size_t c = 0; c < m_columns; ++c) {
std::unique_ptr<CellView>& cv = m_headerViews[c].m_view;
if (!cv)
cv.reset(new CellView(*this, res));
if (cv->reset(c))
if (cv == nullptr) {
cv = std::make_unique<CellView>(*this, res);
}
if (cv->reset(c)) {
m_header = true;
}
ColumnPool& col = m_cellPools[c];