Commit 89539a5b authored by Pawel Sznajder's avatar Pawel Sznajder
Browse files

Add `std::string` based constructor to allow set type by string of

characters (and not cast from integer) #24
parent cc22ab32
......@@ -21,12 +21,19 @@ namespace NumA {
*/
class IntegratorType1D {
public:
/**
* Type of integration.
*/
enum Type {
UNDEFINED = 0, TRAPEZOIDAL, TRAPEZOIDALLOG, GaussLegendre, DEXP, GK21_ADAPTIVE
UNDEFINED = 0, //!< Undefined type.
TRAPEZOIDAL = 1, //!< Trapezoidal method with a fixed number of equidistant steps.
TRAPEZOIDALLOG = 2, //!< Trapezoidal method with a fixed number with equidistantly distributed steps in [ln(min), ln(max)] range.
GaussLegendre = 3, //!< Gauss-Legendre method with a fixed number of steps.
DEXP = 4, //!< Adaptive double exponential method.
GK21_ADAPTIVE = 5 //!< Adaptive Gauss-Kronrod method with 21 point rules.
};
/**
......@@ -34,8 +41,18 @@ public:
*/
IntegratorType1D();
/**
* Assignment constructor.
* @param type Type to be assigned.
*/
IntegratorType1D(Type type);
/**
* Assignment constructor trying to match integration type from given string. If unable to match set IntegratorType1D::UNDEFINED.
* @param integratorType1DString String to be matched.
*/
IntegratorType1D(const std::string& integratorType1DString);
/**
* Default destructor.
*/
......@@ -64,6 +81,10 @@ public:
*/
IntegratorType1D::Type getType() const;
/**
* Set the type of integration.
* @param type Integration type to be set.
*/
void setType(Type type);
private:
......
#include "../../../../include/NumA/integration/one_dimension/IntegratorType1D.h"
#include <ElementaryUtils/logger/LoggerManager.h>
#include <ElementaryUtils/string_utils/Formatter.h>
#include <ElementaryUtils/string_utils/StringUtils.h>
namespace NumA {
IntegratorType1D::IntegratorType1D() :
......@@ -10,6 +14,29 @@ IntegratorType1D::IntegratorType1D(Type type) :
m_type(type) {
}
IntegratorType1D::IntegratorType1D(const std::string& integratorType1DString) {
if (ElemUtils::StringUtils::equals(integratorType1DString, "TRAPEZOIDAL")) {
m_type = IntegratorType1D::TRAPEZOIDAL;
} else if (ElemUtils::StringUtils::equals(integratorType1DString,
"TRAPEZOIDALLOG")) {
m_type = IntegratorType1D::TRAPEZOIDALLOG;
} else if (ElemUtils::StringUtils::equals(integratorType1DString,
"GaussLegendre")) {
m_type = IntegratorType1D::GaussLegendre;
} else if (ElemUtils::StringUtils::equals(integratorType1DString, "DEXP")) {
m_type = IntegratorType1D::DEXP;
} else if (ElemUtils::StringUtils::equals(integratorType1DString,
"GK21_ADAPTIVE")) {
m_type = IntegratorType1D::GK21_ADAPTIVE;
} else {
ElemUtils::LoggerManager::getInstance()->warn("IntegratorType1D", __func__,
ElemUtils::Formatter()
<< "Cannot found IntegratorType1D for string = "
<< integratorType1DString);
}
}
IntegratorType1D::~IntegratorType1D() {
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment