Beispiel #1
0
void OptionsAssigner::appendValue(const Variant &value)
{
    AbstractOptionStorage *option = impl_->currentOption_;
    GMX_RELEASE_ASSERT(option != nullptr, "startOption() not called");
    ++impl_->currentValueCount_;
    option->appendValue(value);
}
Beispiel #2
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"));
    }
}
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"));
    }
}
void OptionsAssigner::appendValue(const std::string &value)
{
    AbstractOptionStorage *option = _impl->_currentOption;
    GMX_RELEASE_ASSERT(option != NULL, "startOption() not called");
    // Does not count correctly, but the actual count is not really used.
    // TODO: Rename the variable to better reflect the usage.
    ++_impl->_currentValueCount;
    option->appendValue(value);
}
void OptionsAssigner::startOption(const char *name)
{
    GMX_RELEASE_ASSERT(_impl->_currentOption == NULL, "finishOption() not called");
    AbstractOptionStorage *option = _impl->findOption(name);
    if (option == NULL)
    {
        GMX_THROW(InvalidInputError("Unknown option"));
    }
    option->startSet();
    _impl->_currentOption = option;
    _impl->_currentValueCount = 0;
}
Beispiel #6
0
bool OptionsAssigner::tryStartOption(const char *name)
{
    GMX_RELEASE_ASSERT(impl_->currentOption_ == nullptr, "finishOption() not called");
    AbstractOptionStorage *option = impl_->findOption(name);
    if (option == nullptr)
    {
        return false;
    }
    option->startSet();
    impl_->currentOption_     = option;
    impl_->currentValueCount_ = 0;
    return true;
}
Beispiel #7
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;
}
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;
}
Beispiel #9
0
bool Options::isSet(const char *name) const
{
    AbstractOptionStorage *option = impl_->findOption(name);
    return (option != NULL ? option->isSet() : false);
}