Fix more clang-tidy issues
authorMark Abraham <mark.j.abraham@gmail.com>
Tue, 28 Aug 2018 10:53:42 +0000 (12:53 +0200)
committerMark Abraham <mark.j.abraham@gmail.com>
Tue, 28 Aug 2018 20:49:41 +0000 (22:49 +0200)
Change-Id: I64f138bc2034bbf1cfd734e49db8e88d07139ca9

src/gromacs/hardware/hardwaretopology.cpp
src/gromacs/selection/compiler.cpp
src/gromacs/selection/params.cpp
src/gromacs/selection/parsetree.cpp
src/gromacs/selection/sm_keywords.cpp
src/gromacs/timing/walltime_accounting.cpp
src/gromacs/utility/exceptions.cpp

index c3ca7de5f8e115684280b0f4770df30fe885faf7..1d8e6d48a24b8bcfedc7fe8f9f5023e7328e4b20 100644 (file)
@@ -175,7 +175,7 @@ parseCpuInfo(HardwareTopology::Machine *        machine,
 
 // Compatibility function for accessing hwloc_obj_t object memory with different API versions of hwloc
 std::size_t
-getHwLocObjectMemory(const hwloc_obj_t obj)
+getHwLocObjectMemory(hwloc_obj_t obj)
 {
 #if GMX_HWLOC_API_VERSION_IS_2XX
     return obj->total_memory;
@@ -196,7 +196,7 @@ getHwLocObjectMemory(const hwloc_obj_t obj)
  *          were found, the vector will be empty.
  */
 const std::vector<hwloc_obj_t>
-getHwLocDescendantsByType(const hwloc_topology_t topo, const hwloc_obj_t obj, const hwloc_obj_type_t type)
+getHwLocDescendantsByType(hwloc_topology_t topo, hwloc_obj_t obj, const hwloc_obj_type_t type)
 {
     GMX_RELEASE_ASSERT(obj, "NULL hwloc object provided to getHwLocDescendantsByType()");
 
@@ -229,7 +229,7 @@ int
 parseHwLocSocketsCoresThreads(hwloc_topology_t                   topo,
                               HardwareTopology::Machine *        machine)
 {
-    const hwloc_obj_t                      root         = hwloc_get_root_obj(topo);
+    hwloc_obj_t                            root         = hwloc_get_root_obj(topo);
     std::vector<hwloc_obj_t>               hwlocSockets = getHwLocDescendantsByType(topo, root, HWLOC_OBJ_PACKAGE);
 
     machine->logicalProcessorCount = hwloc_get_nbobjs_by_type(topo, HWLOC_OBJ_PU);
@@ -298,15 +298,13 @@ parseHwLocSocketsCoresThreads(hwloc_topology_t                   topo,
     }
 }
 
-/*! \brief Read cache information from hwloc topology
+/*! \brief Fill \c machine with cache information from hwloc topology
  *
  *  \param topo    hwloc topology handle that has been initialized and loaded
  *  \param machine Pointer to the machine structure in the HardwareTopology
- *                 class, where cache data will be filled.
- *
- *  \return If any cache data is found the return value is 0, otherwise non-zero.
+ *                 class, where cache data will be filled if found and valid.
  */
-int
+void
 parseHwLocCache(hwloc_topology_t                   topo,
                 HardwareTopology::Machine *        machine)
 {
@@ -332,11 +330,10 @@ parseHwLocCache(hwloc_topology_t                   topo,
             }
         }
     }
-    return machine->caches.empty();
 }
 
 
-/*! \brief Read numa information from hwloc topology
+/*! \brief Fill \c machine with numa information from hwloc topology
  *
  *  \param topo    hwloc topology handle that has been initialized and loaded
  *  \param machine Pointer to the machine structure in the HardwareTopology
@@ -351,14 +348,15 @@ parseHwLocCache(hwloc_topology_t                   topo,
  *  completed successfully before calling this one. If this is not the case,
  *  you will get an error return code.
  *
- *  \return If the data found makes sense (either in the numa node or the
- *          entire machine) the return value is 0, otherwise non-zero.
+ *  If the data found makes sense (either in the numa node or the
+ *  entire machine) the numa.nodes data structure in
+ *  HardwareTopology::Machine will be filled upon exit.
  */
-int
+void
 parseHwLocNuma(hwloc_topology_t                   topo,
                HardwareTopology::Machine *        machine)
 {
-    const hwloc_obj_t                  root           = hwloc_get_root_obj(topo);
+    hwloc_obj_t                        root           = hwloc_get_root_obj(topo);
     std::vector<hwloc_obj_t>           hwlocNumaNodes = getHwLocDescendantsByType(topo, root, HWLOC_OBJ_NUMANODE);
     bool                               topologyOk     = true;
 
@@ -524,31 +522,24 @@ parseHwLocNuma(hwloc_topology_t                   topo,
         }
     }
 #endif      // end if not GMX_HWLOC_API_VERSION_IS_2XX
-    if (topologyOk)
-    {
-        return 0;
-    }
-    else
+    if (!topologyOk)
     {
         machine->numa.nodes.clear();
-        return -1;
     }
-
 }
 
-/*! \brief Read PCI device information from hwloc topology
+/*! \brief Fill \c machine with PCI device information from hwloc topology
  *
  *  \param topo    hwloc topology handle that has been initialized and loaded
  *  \param machine Pointer to the machine structure in the HardwareTopology
- *                 class, where PCI device information will be filled.
- * *
- *  \return If any devices were found the return value is 0, otherwise non-zero.
+ *                 class, where PCI device information will be filled if found
+ *                 and valid.
  */
-int
+void
 parseHwLocDevices(hwloc_topology_t                   topo,
                   HardwareTopology::Machine *        machine)
 {
-    const hwloc_obj_t        root    = hwloc_get_root_obj(topo);
+    hwloc_obj_t              root    = hwloc_get_root_obj(topo);
     std::vector<hwloc_obj_t> pcidevs = getHwLocDescendantsByType(topo, root, HWLOC_OBJ_PCI_DEVICE);
 
     for (auto &p : pcidevs)
@@ -593,7 +584,6 @@ parseHwLocDevices(hwloc_topology_t                   topo,
                                         numaId
                                     } );
     }
-    return pcidevs.empty();
 }
 
 void
@@ -626,7 +616,7 @@ parseHwLoc(HardwareTopology::Machine *        machine,
     }
 
     // If we get here, we can get a valid root object for the topology
-    *isThisSystem = hwloc_topology_is_thissystem(topo);
+    *isThisSystem = bool(hwloc_topology_is_thissystem(topo));
 
     // Parse basic information about sockets, cores, and hardware threads
     if (parseHwLocSocketsCoresThreads(topo, machine) == 0)
@@ -640,7 +630,9 @@ parseHwLoc(HardwareTopology::Machine *        machine,
     }
 
     // Get information about cache and numa nodes
-    if (parseHwLocCache(topo, machine) == 0 && parseHwLocNuma(topo, machine) == 0)
+    parseHwLocCache(topo, machine);
+    parseHwLocNuma(topo, machine);
+    if (!machine->caches.empty() && !machine->numa.nodes.empty())
     {
         *supportLevel = HardwareTopology::SupportLevel::Full;
     }
@@ -651,7 +643,8 @@ parseHwLoc(HardwareTopology::Machine *        machine,
     }
 
     // PCI devices
-    if (parseHwLocDevices(topo, machine) == 0)
+    parseHwLocDevices(topo, machine);
+    if (!machine->devices.empty())
     {
         *supportLevel = HardwareTopology::SupportLevel::FullWithDevices;
     }
index 4bfc66c2dbe60024fb03927432ab0b7e6c712616..8438dbe00cfc2fbd3b37eecdd85ae4c25ab2f400 100644 (file)
@@ -791,17 +791,17 @@ extract_item_subselections(const SelectionTreeElementPointer &sel,
             /* Create the root element for the subexpression */
             if (!root)
             {
-                root.reset(new SelectionTreeElement(SEL_ROOT, location));
+                root    = std::make_shared<SelectionTreeElement>(SEL_ROOT, location);
                 subexpr = root;
             }
             else
             {
-                subexpr->next.reset(new SelectionTreeElement(SEL_ROOT, location));
-                subexpr = subexpr->next;
+                subexpr->next = std::make_shared<SelectionTreeElement>(SEL_ROOT, location);
+                subexpr       = subexpr->next;
             }
             /* Create the subexpression element and
              * move the actual subexpression under the created element. */
-            subexpr->child.reset(new SelectionTreeElement(SEL_SUBEXPR, location));
+            subexpr->child = std::make_shared<SelectionTreeElement>(SEL_SUBEXPR, location);
             _gmx_selelem_set_vtype(subexpr->child, child->v.type);
             subexpr->child->child = child->child;
             child->child          = subexpr->child;
@@ -1929,7 +1929,7 @@ evaluate_boolean_static_part(gmx_sel_evaluate_t                *data,
         child->next.reset();
         sel->cdata->evaluate(data, sel, g);
         /* Replace the subexpressions with the result */
-        child.reset(new SelectionTreeElement(SEL_CONST, SelectionLocation::createEmpty()));
+        child             = std::make_shared<SelectionTreeElement>(SEL_CONST, SelectionLocation::createEmpty());
         child->flags      = SEL_FLAGSSET | SEL_SINGLEVAL | SEL_ALLOCVAL | SEL_ALLOCDATA;
         _gmx_selelem_set_vtype(child, GROUP_VALUE);
         child->evaluate   = nullptr;
index 7b38a2c4040fbe7804e5c4adc1bb840b3f73c542..52bbf6b81c9759326072e32c9af0d7255e14c4fc 100644 (file)
@@ -581,7 +581,7 @@ add_child(const SelectionTreeElementPointer &root, gmx_ana_selparam_t *param,
     else
     {
         // TODO: Initialize such that it includes the parameter.
-        child.reset(new SelectionTreeElement(SEL_SUBEXPRREF, expr->location()));
+        child = std::make_shared<SelectionTreeElement>(SEL_SUBEXPRREF, expr->location());
         _gmx_selelem_set_vtype(child, expr->v.type);
         child->child  = expr;
     }
index f3f16a6f821837ed79ae5c19e4716a5a54c00d72..304da3d07ff244d5044190836392e53aeb2a4d48 100644 (file)
@@ -724,7 +724,7 @@ init_keyword_internal(gmx_ana_selmethod_t *method,
                                   "Unknown type for keyword selection"));
         }
         /* Initialize the selection element */
-        root.reset(new SelectionTreeElement(SEL_EXPRESSION, location));
+        root = std::make_shared<SelectionTreeElement>(SEL_EXPRESSION, location);
         _gmx_selelem_set_method(root, kwmethod, scanner);
         if (method->type == STR_VALUE)
         {
@@ -1013,8 +1013,8 @@ _gmx_sel_init_variable_ref(const gmx::SelectionTreeElementPointer &sel,
     }
     else
     {
-        ref.reset(new SelectionTreeElement(
-                          SEL_SUBEXPRREF, _gmx_sel_lexer_get_current_location(scanner)));
+        ref = std::make_shared<SelectionTreeElement>(
+                    SEL_SUBEXPRREF, _gmx_sel_lexer_get_current_location(scanner));
         _gmx_selelem_set_vtype(ref, sel->v.type);
         ref->setName(sel->name());
         ref->child = sel;
@@ -1113,10 +1113,10 @@ _gmx_sel_assign_variable(const char                             *name,
     {
         SelectionLocation location(_gmx_sel_lexer_get_current_location(scanner));
         /* Create the root element */
-        root.reset(new SelectionTreeElement(SEL_ROOT, location));
+        root = std::make_shared<SelectionTreeElement>(SEL_ROOT, location);
         root->setName(name);
         /* Create the subexpression element */
-        root->child.reset(new SelectionTreeElement(SEL_SUBEXPR, location));
+        root->child = std::make_shared<SelectionTreeElement>(SEL_SUBEXPR, location);
         root->child->setName(name);
         _gmx_selelem_set_vtype(root->child, expr->v.type);
         root->child->child  = expr;
index 6609900c67b6e43c883103151c0f79f99149fc79..8f2bcf341d16f3df461059819c32f9b32568396e 100644 (file)
@@ -222,7 +222,7 @@ class StringKeywordMatchItem
                                             "cannot match \"%s\"", str);
                     GMX_THROW(gmx::InvalidInputError(message));
                 }
-                regex_.reset(new gmx::Regex(str));
+                regex_ = std::make_shared<gmx::Regex>(str);
             }
         }
 
index 0ad9fbcd73bbbd864363ca71f28ea223bb92a784..5828bcd1e850f0d2b4a526ce3173dfc883358241 100644 (file)
@@ -109,7 +109,7 @@ typedef struct gmx_walltime_accounting {
 static double gmx_gettime_per_thread();
 
 // TODO In principle, all this should get protected by checks that
-// walltime_accounting is not null. In practice, that NULL condition
+// walltime_accounting is not nullptr. In practice, that nullptr condition
 // does not happen, and future refactoring will likely enforce it by
 // having the gmx_walltime_accounting_t object be owned by the runner
 // object. When these become member functions, existence will be
@@ -235,14 +235,14 @@ gmx_gettime()
     struct timeval t;
     double         seconds;
 
-    gettimeofday(&t, NULL);
+    gettimeofday(&t, nullptr);
     seconds = static_cast<double>(t.tv_sec) + 1e-6*t.tv_usec;
 
     return seconds;
 #else
     double  seconds;
 
-    seconds = time(NULL);
+    seconds = time(nullptr);
 
     return seconds;
 #endif
index 0dd967c908c19e1227e5dc23e0ab6c31e3ec074a..19886c1f4c40410bb97160dcde9b48d550c5401f 100644 (file)
@@ -160,7 +160,7 @@ ErrorMessage
 ErrorMessage::prependContext(const std::string &context) const
 {
     ErrorMessage newMessage(context);
-    newMessage.child_.reset(new ErrorMessage(*this));
+    newMessage.child_ = std::make_shared<ErrorMessage>(*this);
     return newMessage;
 }