void SelectionTreeElement::resolveIndexGroupReference( gmx_ana_indexgrps_t *grps, int natoms) { GMX_RELEASE_ASSERT(type == SEL_GROUPREF, "Should only be called for index group reference elements"); if (grps == NULL) { std::string message = formatString( "Cannot match '%s', because index groups are not available.", name().c_str()); GMX_THROW(InconsistentInputError(message)); } gmx_ana_index_t foundGroup; std::string foundName; if (u.gref.name != NULL) { if (!gmx_ana_indexgrps_find(&foundGroup, &foundName, grps, u.gref.name)) { std::string message = formatString( "Cannot match '%s', because no such index group can be found.", name().c_str()); GMX_THROW(InconsistentInputError(message)); } } else { if (!gmx_ana_indexgrps_extract(&foundGroup, &foundName, grps, u.gref.id)) { std::string message = formatString( "Cannot match '%s', because no such index group can be found.", name().c_str()); GMX_THROW(InconsistentInputError(message)); } } if (!gmx_ana_index_check_sorted(&foundGroup)) { flags |= SEL_UNSORTED; } sfree(u.gref.name); type = SEL_CONST; gmx_ana_index_set(&u.cgrp, foundGroup.isize, foundGroup.index, foundGroup.nalloc_index); setName(foundName); if (natoms > 0) { checkIndexGroup(natoms); } }
void SelectionCollection::Impl::resolveExternalGroups( t_selelem *root, MessageStringCollector *errors) { if (root->type == SEL_GROUPREF) { bool bOk = true; if (_grps == NULL) { // TODO: Improve error messages errors->append("Unknown group referenced in a selection"); bOk = false; } else if (root->u.gref.name != NULL) { char *name = root->u.gref.name; if (!gmx_ana_indexgrps_find(&root->u.cgrp, _grps, name)) { // TODO: Improve error messages errors->append("Unknown group referenced in a selection"); bOk = false; } else { sfree(name); } } else { if (!gmx_ana_indexgrps_extract(&root->u.cgrp, _grps, root->u.gref.id)) { // TODO: Improve error messages errors->append("Unknown group referenced in a selection"); bOk = false; } } if (bOk) { root->type = SEL_CONST; root->name = root->u.cgrp.name; } } t_selelem *child = root->child; while (child != NULL) { resolveExternalGroups(child, errors); child = child->next; } }