From e519005537b1e3fcadefd545d6863b8ceed0eb07 Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <dmitri.naumov@ufz.de>
Date: Fri, 7 Oct 2016 19:33:36 +0200
Subject: [PATCH] [App/DE] Update for ptr version of getPropertyVec.

Two cleanups: reserve and fill is equal to resize,
Wrote out ternary condition operator into if-else.
---
 .../DataView/CreateStructuredGridDialog.cpp   |  8 +++----
 .../DataView/DirectConditionGenerator.cpp     | 11 +++++----
 .../DataView/MeshElementRemovalDialog.cpp     | 24 ++++++++++++-------
 3 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/Applications/DataExplorer/DataView/CreateStructuredGridDialog.cpp b/Applications/DataExplorer/DataView/CreateStructuredGridDialog.cpp
index d2e8ee3bafb..a3ec23d3bd5 100644
--- a/Applications/DataExplorer/DataView/CreateStructuredGridDialog.cpp
+++ b/Applications/DataExplorer/DataView/CreateStructuredGridDialog.cpp
@@ -256,10 +256,10 @@ void CreateStructuredGridDialog::accept()
         return;
     }
 
-    boost::optional<MeshLib::PropertyVector<int>&> mat_ids (
-        mesh->getProperties().createNewPropertyVector<int>("MaterialIDs", MeshLib::MeshItemType::Cell));
-    mat_ids->reserve(mesh->getNumberOfElements());
-    std::fill_n(std::back_inserter(*mat_ids), mesh->getNumberOfElements(), 0);
+    auto* const mat_ids = mesh->getProperties().createNewPropertyVector<int>(
+        "MaterialIDs", MeshLib::MeshItemType::Cell);
+    assert(mat_ids != nullptr);
+    mat_ids->resize(mesh->getNumberOfElements());
     emit meshAdded(mesh);
     this->done(QDialog::Accepted);
 }
diff --git a/Applications/DataExplorer/DataView/DirectConditionGenerator.cpp b/Applications/DataExplorer/DataView/DirectConditionGenerator.cpp
index cb3b05e3fdf..ed179ccbd6e 100644
--- a/Applications/DataExplorer/DataView/DirectConditionGenerator.cpp
+++ b/Applications/DataExplorer/DataView/DirectConditionGenerator.cpp
@@ -97,9 +97,10 @@ const std::vector< std::pair<std::size_t,double> >& DirectConditionGenerator::di
     const std::size_t nNodes(surface_mesh->getNumberOfNodes());
     const double no_data(raster->getHeader().no_data);
 
-    boost::optional<MeshLib::PropertyVector<int>&> const opt_node_id_pv(
-        surface_mesh->getProperties().getPropertyVector<int>(prop_name));
-    if (!opt_node_id_pv) {
+    auto const* const node_id_pv =
+        surface_mesh->getProperties().getPropertyVector<int>(prop_name);
+    if (!node_id_pv)
+    {
         ERR(
             "Need subsurface node ids, but the property \"%s\" is not "
             "available.",
@@ -107,13 +108,13 @@ const std::vector< std::pair<std::size_t,double> >& DirectConditionGenerator::di
         return _direct_values;
     }
 
-    MeshLib::PropertyVector<int> const& node_id_pv(*opt_node_id_pv);
     _direct_values.reserve(nNodes);
     for (std::size_t i=0; i<nNodes; ++i)
     {
         double val(raster->getValueAtPoint(*surface_nodes[i]));
         val = (val == no_data) ? 0 : ((val*node_area_vec[i])/scaling);
-        _direct_values.push_back(std::pair<std::size_t, double>(node_id_pv[i], val));
+        _direct_values.push_back(
+            std::pair<std::size_t, double>((*node_id_pv)[i], val));
     }
 
     return _direct_values;
diff --git a/Applications/DataExplorer/DataView/MeshElementRemovalDialog.cpp b/Applications/DataExplorer/DataView/MeshElementRemovalDialog.cpp
index 8c672a97030..c2e37d1cf8a 100644
--- a/Applications/DataExplorer/DataView/MeshElementRemovalDialog.cpp
+++ b/Applications/DataExplorer/DataView/MeshElementRemovalDialog.cpp
@@ -171,20 +171,25 @@ void MeshElementRemovalDialog::on_materialIDCheckBox_toggled(bool is_checked)
         materialListWidget->clear();
         _matIDIndex = _currentIndex;
         auto mesh = _project.getMesh(meshNameComboBox->currentText().toStdString());
-        auto const opt_mat_ids = mesh->getProperties().getPropertyVector<int>("MaterialIDs");
-        if (!opt_mat_ids) {
+        auto const* const mat_ids =
+            mesh->getProperties().getPropertyVector<int>("MaterialIDs");
+        if (!mat_ids)
+        {
             INFO("Properties \"MaterialIDs\" not found in the mesh \"%s\".",
                 mesh->getName().c_str());
             return;
         }
-        auto const& mat_ids = opt_mat_ids.get();
-        if (mat_ids.size() != mesh->getNumberOfElements()) {
-            INFO("Size mismatch: Properties \"MaterialIDs\" contains %u values,"
-                " the mesh \"%s\" contains %u elements.", mat_ids.size(),
-                mesh->getName().c_str(), mesh->getNumberOfElements());
+        if (mat_ids->size() != mesh->getNumberOfElements())
+        {
+            INFO(
+                "Size mismatch: Properties \"MaterialIDs\" contains %u values,"
+                " the mesh \"%s\" contains %u elements.",
+                mat_ids->size(), mesh->getName().c_str(),
+                mesh->getNumberOfElements());
             return;
         }
-        auto max_material = std::max_element(mat_ids.cbegin(), mat_ids.cend());
+        auto max_material =
+            std::max_element(mat_ids->cbegin(), mat_ids->cend());
 
         for (unsigned i=0; i <= static_cast<unsigned>(*max_material); ++i)
             materialListWidget->addItem(QString::number(i));
@@ -200,7 +205,8 @@ void MeshElementRemovalDialog::on_meshNameComboBox_currentIndexChanged(int idx)
     this->materialListWidget->clearSelection();
     if (this->boundingBoxCheckBox->isChecked()) this->on_boundingBoxCheckBox_toggled(true);
     auto mesh = _project.getMesh(meshNameComboBox->currentText().toStdString());
-    auto materialIds = mesh->getProperties().getPropertyVector<int>("MaterialIDs");
+    auto const* const materialIds =
+        mesh->getProperties().getPropertyVector<int>("MaterialIDs");
     if (materialIds)
     {
         if (materialIds->size() != mesh->getNumberOfElements())
-- 
GitLab