From 057653e28bffab498a0ea104e7d900d5f0f767b8 Mon Sep 17 00:00:00 2001 From: Teemu Murtola Date: Sat, 9 Aug 2014 07:19:56 +0300 Subject: [PATCH] Add Selection::hasOnlyAtoms() 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 | 4 ++++ src/gromacs/selection/selectioncollection.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/gromacs/selection/selection.h b/src/gromacs/selection/selection.h index b027a5ed8a..2344007833 100644 --- a/src/gromacs/selection/selection.h +++ b/src/gromacs/selection/selection.h @@ -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 diff --git a/src/gromacs/selection/selectioncollection.cpp b/src/gromacs/selection/selectioncollection.cpp index 9ac55bcc02..2ba4fb5fe7 100644 --- a/src/gromacs/selection/selectioncollection.cpp +++ b/src/gromacs/selection/selectioncollection.cpp @@ -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. " -- 2.22.0