X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=blobdiff_plain;f=src%2Fgromacs%2Foptions%2Fbasicoptions.cpp;h=8dff27360da2a41ccdeabc470018b69d93cf0a56;hb=236deaf1539a55c3f03ff40e16175ffcb65a6cfe;hp=2b2c0863352ea777d349438ee6b4401c6e740182;hpb=61e3221db79c7f1a37a4cbd6c37c762f3277048a;p=alexxy%2Fgromacs.git diff --git a/src/gromacs/options/basicoptions.cpp b/src/gromacs/options/basicoptions.cpp index 2b2c086335..8dff27360d 100644 --- a/src/gromacs/options/basicoptions.cpp +++ b/src/gromacs/options/basicoptions.cpp @@ -522,11 +522,6 @@ StringOptionStorage::StringOptionStorage(const StringOption &settings) GMX_THROW(APIError("Conflicting default values")); } } - // If there is no default value, match is still -1. - if (enumIndexStore_ != NULL) - { - *enumIndexStore_ = match; - } } if (settings.defaultEnumIndex_ >= 0) { @@ -534,6 +529,12 @@ StringOptionStorage::StringOptionStorage(const StringOption &settings) addValue(allowed_[settings.defaultEnumIndex_]); commitValues(); } + // Somewhat subtly, this does not update the stored enum index if the + // caller has not provided store() or storeVector(), because values() + // will be empty in such a case. This leads to (desired) behavior of + // preserving the existing value in the enum index store variable in such + // cases. + refreshEnumIndexStore(); } std::string StringOptionStorage::formatExtraDescription() const @@ -592,15 +593,27 @@ void StringOptionStorage::convertValue(const std::string &value) void StringOptionStorage::refreshValues() { MyBase::refreshValues(); + refreshEnumIndexStore(); +} + +void StringOptionStorage::refreshEnumIndexStore() +{ if (enumIndexStore_ != NULL) { for (size_t i = 0; i < values().size(); ++i) { - ValueList::const_iterator match = - std::find(allowed_.begin(), allowed_.end(), values()[i]); - GMX_ASSERT(match != allowed_.end(), - "Enum value not found (internal error)"); - enumIndexStore_[i] = static_cast(match - allowed_.begin()); + if (values()[i].empty()) + { + enumIndexStore_[i] = -1; + } + else + { + ValueList::const_iterator match = + std::find(allowed_.begin(), allowed_.end(), values()[i]); + GMX_ASSERT(match != allowed_.end(), + "Enum value not found (internal error)"); + enumIndexStore_[i] = static_cast(match - allowed_.begin()); + } } } }