Add Selection::hasOnlyAtoms()
authorTeemu Murtola <teemu.murtola@gmail.com>
Sat, 9 Aug 2014 04:19:56 +0000 (07:19 +0300)
committerTeemu Murtola <teemu.murtola@gmail.com>
Sat, 9 Aug 2014 04:30:33 +0000 (07:30 +0300)
Add a convenience function for checking whether a selection consists of
atom positions only.  This will be useful for analysis tools that may
only support atom positions with some combination of options, leads
to clearer code than checking type() == INDEX_ATOM, and exposes less
internal implementation details.

Change-Id: Iaa2d0bfa2f567c060f6b006d423c2910ffd46a69

src/gromacs/selection/selection.h
src/gromacs/selection/selectioncollection.cpp

index b027a5ed8a51573512cf0c08f24b3e7b3b10d83a..23440078337dee86c918735cd2c9b5fe81fa56b8 100644 (file)
@@ -104,6 +104,8 @@ class SelectionData
         bool isDynamic() const { return bDynamic_; }
         //! Returns the type of positions in the selection.
         e_index_t type() const { return rawPositions_.m.type; }
+        //! Returns true if the selection only contains positions with a single atom each.
+        bool hasOnlyAtoms() const { return type() == INDEX_ATOM; }
 
         //! Number of positions in the selection.
         int posCount() const { return rawPositions_.count(); }
@@ -323,6 +325,8 @@ class Selection
         bool isDynamic() const { return data().isDynamic(); }
         //! Returns the type of positions in the selection.
         e_index_t type() const { return data().type(); }
+        //! Returns true if the selection only contains positions with a single atom each.
+        bool hasOnlyAtoms() const { return data().hasOnlyAtoms(); }
 
         //! Total number of atoms in the selection.
         int atomCount() const
index 9ac55bcc0256ccc19f6ab8ee504cf128dcff6004..2ba4fb5fe7fc03d3923afea23e75413c3163ebcd 100644 (file)
@@ -775,7 +775,7 @@ SelectionCollection::compile()
         const internal::SelectionData &sel = **iter;
         if (sel.hasFlag(efSelection_OnlyAtoms))
         {
-            if (sel.type() != INDEX_ATOM)
+            if (!sel.hasOnlyAtoms())
             {
                 std::string message = formatString(
                             "Selection '%s' does not evaluate to individual atoms. "