/* * Copyright (C) 2018 Red Hat, Inc. * * Licensed under the GNU Lesser General Public License Version 2.1 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef _LIBDNF_OPTION_CHILD_HPP #define _LIBDNF_OPTION_CHILD_HPP #ifdef LIBDNF_UNSTABLE_API #include "Option.hpp" namespace libdnf { template class OptionChild : public Option { public: OptionChild(const ParentOptionType & parent); OptionChild * clone() const override; Priority getPriority() const override; void set(Priority priority, const typename ParentOptionType::ValueType & value); void set(Priority priority, const std::string & value) override; const typename ParentOptionType::ValueType getValue() const; const typename ParentOptionType::ValueType getDefaultValue() const; std::string getValueString() const override; bool empty() const noexcept override; private: const ParentOptionType * parent; typename ParentOptionType::ValueType value; }; template class OptionChild::value>::type> : public Option { public: OptionChild(const ParentOptionType & parent); OptionChild * clone() const override; Priority getPriority() const override; void set(Priority priority, const std::string & value) override; const std::string & getValue() const; const std::string & getDefaultValue() const; std::string getValueString() const override; bool empty() const noexcept override; private: const ParentOptionType * parent; std::string value; }; template inline OptionChild::OptionChild(const ParentOptionType & parent) : parent(&parent) {} template inline OptionChild * OptionChild::clone() const { return new OptionChild(*this); } template inline Option::Priority OptionChild::getPriority() const { return priority != Priority::EMPTY ? priority : parent->getPriority(); } template inline void OptionChild::set(Priority priority, const typename ParentOptionType::ValueType & value) { if (priority >= this->priority) { parent->test(value); this->priority = priority; this->value = value; } } template inline void OptionChild::set(Priority priority, const std::string & value) { if (priority >= this->priority) set(priority, parent->fromString(value)); } template inline const typename ParentOptionType::ValueType OptionChild::getValue() const { return priority != Priority::EMPTY ? value : parent->getValue(); } template inline const typename ParentOptionType::ValueType OptionChild::getDefaultValue() const { return parent->getDefaultValue(); } template inline std::string OptionChild::getValueString() const { return priority != Priority::EMPTY ? parent->toString(value) : parent->getValueString(); } template inline bool OptionChild::empty() const noexcept { return priority == Priority::EMPTY && parent->empty(); } template inline OptionChild::value>::type>::OptionChild(const ParentOptionType & parent) : parent(&parent) {} template inline OptionChild::value>::type> * OptionChild::value>::type>::clone() const { return new OptionChild(*this); } template inline Option::Priority OptionChild::value>::type>::getPriority() const { return priority != Priority::EMPTY ? priority : parent->getPriority(); } template inline void OptionChild::value>::type>::set(Priority priority, const std::string & value) { auto val = parent->fromString(value); if (priority >= this->priority) { parent->test(val); this->priority = priority; this->value = val; } } template inline const std::string & OptionChild::value>::type>::getValue() const { return priority != Priority::EMPTY ? value : parent->getValue(); } template inline const std::string & OptionChild::value>::type>::getDefaultValue() const { return parent->getDefaultValue(); } template inline std::string OptionChild::value>::type>::getValueString() const { return priority != Priority::EMPTY ? value : parent->getValue(); } template inline bool OptionChild::value>::type>::empty() const noexcept { return priority == Priority::EMPTY && parent->empty(); } } #endif #endif