diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperBoolParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperBoolParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..cb4991c93bf4f17308cb257e9ec982ec28adf96a --- /dev/null +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperBoolParameter.h @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef otbWrapperBoolParameter_h +#define otbWrapperBoolParameter_h + +namespace otb +{ +namespace Wrapper +{ + +/** \class BoolParameter + * \brief This class represent a boolean parameter for the wrapper framework + * + * It is intended to replace the deprecated EmptyParameter + * + * \ingroup OTBApplicationEngine + */ +class OTBApplicationEngine_EXPORT BoolParameter + : public Parameter +{ +public: + /** Standard class typedef */ + typedef BoolParameter Self; + typedef Parameter Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Defining ::New() static method */ + itkNewMacro(Self); + + /** RTTI support */ + itkTypeMacro(BoolParameter, Parameter); + + /** This parameter is ON/OFF switch, it always has a value */ + bool HasValue() const override + { + return true; + } + + bool GetValue() const; + + void SetValue(bool state); + + void SetValue(const std::string & str); + +protected: + /** Constructor */ + BoolParameter() + : m_Value(false) + {} + + /** Destructor */ + ~BoolParameter() override + {} + +private: + BoolParameter(const BoolParameter &) = delete; + void operator =(const BoolParameter&) = delete; + + bool m_Value; +}; + +} // end of namespace Wrapper +} // end of namespace otb + +#endif diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperBoolParameter.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperBoolParameter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..92587a5ddd8edab5a362e57df99518b91e16853e --- /dev/null +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperBoolParameter.cxx @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "otbWrapperBoolParameter.h" + +namespace otb +{ +namespace Wrapper +{ + +bool +BoolParameter::GetValue() const +{ + return m_Value; +} + +void +BoolParameter::SetValue(bool state) +{ + if (m_Value != state) + { + m_Value = state; + this->Modified(); + } +} + +void +BoolParameter::SetValue(const std::string & str) +{ + std::string lowerStr; + // only strings less than 10 characters expected + lowerStr.reserve(10); + for (unsigned int i=0 ; i < std::min(10,str.size()) ; i++ ) + { + lowerStr.push_back(tolower(str[i])); + } + if (lowerStr == "1" || lowerStr == "on" || lowerStr == "true") + { + this->SetValue(true); + } + else if (lowerStr == "0" || lowerStr == "off" || lowerStr == "false") + { + this->SetValue(false); + } + else + { + // TODO: exception, value not a bool + } +} + +} // end of namespace Wrapper +} // end of namespace otb