Skip to content
Snippets Groups Projects
Commit 6d75dddd authored by Guillaume Pasero's avatar Guillaume Pasero
Browse files

ADD: new boolean parameter

parent 62f1f7fa
No related branches found
No related tags found
1 merge request!15Parameter bool
/*
* 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
/*
* 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment