/* * Copyright (c) <2002-2006> * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files * (curlpp), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, * publish, distribute, sublicense, and/or sell copies of the Software, * and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef CURLPP_OPTION_INL #define CURLPP_OPTION_INL #include "internal/OptionSetter.hpp" #include "Exception.hpp" #include namespace curlpp { // Option template Option::Option(CURLoption option, typename Option::ParamType value) : OptionBase(option), mContainer(NULL) { setValue(value); } template Option::Option(CURLoption option) : OptionBase(option), mContainer(NULL) {} template Option::Option(const Option & other) : OptionBase(other) , mContainer(NULL) { if(other.mContainer != NULL) { setValue(other.getValue()); } } template Option::~Option() { delete mContainer; mContainer = NULL; } template void Option::setValue(typename Option::ParamType value) { if(mContainer == NULL) { mContainer = new internal::OptionContainer(value); } else { mContainer->setValue(value); } } template void Option::updateMeToOption(const OptionBase & other) { const Option * option = dynamic_cast *>(&other); if(option == NULL) { throw UnsetOption("You are trying to update an option to an incompatible option"); } setValue(option->getValue()); } template void Option::clear() { delete mContainer; mContainer = NULL; } template typename Option::ReturnType Option::getValue() const { if(mContainer == NULL) throw UnsetOption("You are trying to retreive the value of an unset option"); return mContainer->getValue(); } // OptionTrait template OptionTrait::OptionTrait(typename Option::ParamType value) : Option(option, value) {} template OptionTrait::OptionTrait() : Option(option) {} template OptionTrait * OptionTrait::clone() const { return new OptionTrait(this->getValue()); } template void OptionTrait::updateHandleToMe(internal::CurlHandle * handle) const { if(this->mContainer == NULL) { throw UnsetOption("You are trying to set an unset option to a handle"); } internal::OptionSetter::setOpt(handle, this->mContainer->getHandleOptionValue()); } // NoValueOptionTrait template NoValueOptionTrait