예제 #1
0
void OptionsAssigner::finishOption()
{
    AbstractOptionStorage *option = impl_->currentOption_;
    GMX_RELEASE_ASSERT(option != nullptr, "startOption() not called");
    bool                   bBoolReverseValue = false;
    if (option->isBoolean())
    {
        if (impl_->currentValueCount_ == 0)
        {
            // Should not throw, otherwise something is wrong.
            option->appendValue(Variant::create<bool>(!impl_->reverseBoolean_));
        }
        else if (impl_->reverseBoolean_)
        {
            bBoolReverseValue = true;
        }
    }
    impl_->currentOption_  = nullptr;
    impl_->reverseBoolean_ = false;
    option->finishSet();
    if (bBoolReverseValue)
    {
        GMX_THROW(InvalidInputError("Cannot specify a value together with 'no' prefix"));
    }
}
예제 #2
0
void OptionsAssigner::finishOption()
{
    AbstractOptionStorage *option = _impl->_currentOption;
    GMX_RELEASE_ASSERT(option != NULL, "startOption() not called");
    bool bBoolReverseValue = false;
    if (option->isBoolean())
    {
        if (_impl->_currentValueCount == 0)
        {
            // Should not throw, otherwise something is wrong.
            // TODO: Get rid of the hard-coded values.
            option->appendValue(_impl->_reverseBoolean ? "0" : "1");
        }
        else if (_impl->_reverseBoolean)
        {
            bBoolReverseValue = true;
        }
    }
    _impl->_currentOption = NULL;
    _impl->_reverseBoolean = false;
    option->finishSet();
    if (bBoolReverseValue)
    {
        GMX_THROW(InvalidInputError("Cannot specify a value together with 'no' prefix"));
    }
}
예제 #3
0
AbstractOptionStorage *
OptionsAssigner::Impl::findOption(const char *name)
{
    GMX_RELEASE_ASSERT(currentOption_ == nullptr,
                       "Cannot search for another option while processing one");
    const Section         &section = currentSection();
    AbstractOptionStorage *option  = section.findOption(name);
    if (option == nullptr && bAcceptBooleanNoPrefix_)
    {
        if (name[0] == 'n' && name[1] == 'o')
        {
            option = section.findOption(name + 2);
            if (option != nullptr && option->isBoolean())
            {
                reverseBoolean_ = true;
            }
            else
            {
                option = nullptr;
            }
        }
    }
    return option;
}
예제 #4
0
AbstractOptionStorage *
OptionsAssigner::Impl::findOption(const char *name)
{
    GMX_RELEASE_ASSERT(_currentOption == NULL,
                       "Cannot search for another option while processing one");
    AbstractOptionStorage *option = NULL;
    Options *section = NULL;
    Options *root = &currentSection();
    Options *oldRoot = NULL;
    int      upcount = 0;
    std::deque<Options *> searchList;
    searchList.push_back(root);
    while (option == NULL && !searchList.empty())
    {
        section = searchList.front();
        option = section->_impl->findOption(name);
        if (option == NULL && hasFlag(efAcceptBooleanNoPrefix))
        {
            if (name[0] == 'n' && name[1] == 'o')
            {
                option = section->_impl->findOption(name + 2);
                if (option != NULL && option->isBoolean())
                {
                    _reverseBoolean = true;
                }
                else
                {
                    option = NULL;
                }
            }
        }
        searchList.pop_front();
        if (hasFlag(efNoStrictSectioning))
        {
            Options::Impl::SubSectionList::const_iterator i;
            for (i = section->_impl->_subSections.begin();
                 i != section->_impl->_subSections.end(); ++i)
            {
                if (*i != oldRoot)
                {
                    searchList.push_back(*i);
                }
            }
            if (searchList.empty() && root != &_options)
            {
                Options *oldRoot = root;
                root = root->_impl->_parent;
                ++upcount;
                searchList.push_back(root);
            }
        }
    }
    if (hasFlag(efNoStrictSectioning) && option != NULL)
    {
        while (upcount > 0)
        {
            _sectionStack.pop_back();
            --upcount;
        }
        std::vector<Options *> sections;
        while (section != &currentSection())
        {
            sections.push_back(section);
            section = section->_impl->_parent;
        }
        while (!sections.empty())
        {
            _sectionStack.push_back(sections.back());
            sections.pop_back();
        }
    }
    return option;
}