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,53 +21,74 @@ namespace NumA {
*/
class IntegratorType1D {
public:
/**
* Type of integration.
*/
enum Type {
UNDEFINED = 0, TRAPEZOIDAL, TRAPEZOIDALLOG, GaussLegendre, DEXP, GK21_ADAPTIVE
};
/**
* Default constructor.
*/
IntegratorType1D();
IntegratorType1D(Type type);
/**
* Default destructor.
*/
virtual ~IntegratorType1D();
/**
* Operator that casts back into an enum.
*/
operator Type() const;
/**
* Returns a formatted string displaying the type.
* @return std::string
*/
std::string toString();
/**
* Returns a short name for the type.
* @return std::string
*/
std::string getShortName();
/**
* Returns the wrapped enum.
* @return IntegratorType1D::Type
*/
IntegratorType1D::Type getType() const;
void setType(Type type);
/**
* Type of integration.
*/
enum Type {
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.
};
/**
* Default constructor.
*/
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.
*/
virtual ~IntegratorType1D();
/**
* Operator that casts back into an enum.
*/
operator Type() const;
/**
* Returns a formatted string displaying the type.
* @return std::string
*/
std::string toString();
/**
* Returns a short name for the type.
* @return std::string
*/
std::string getShortName();
/**
* Returns the wrapped enum.
* @return IntegratorType1D::Type
*/
IntegratorType1D::Type getType() const;
/**
* Set the type of integration.
* @param type Integration type to be set.
*/
void setType(Type type);
private:
IntegratorType1D::Type m_type; ///< Type of integration (enum).
IntegratorType1D::Type m_type; ///< Type of integration (enum).
};
} /* namespace NumA */
......
#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() :
m_type(IntegratorType1D::UNDEFINED) {
m_type(IntegratorType1D::UNDEFINED) {
}
IntegratorType1D::IntegratorType1D(Type type) :
m_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")) {
  • Beware here, it's not the same string as in line 56.

  • Nice catch Nabil!

    Maybe we can change the type and all strings to GL, it is annoying that only this one is written with lowercases.

Please register or sign in to reply
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() {
}
IntegratorType1D::operator IntegratorType1D::Type() const {
return m_type;
return m_type;
}
std::string IntegratorType1D::toString() {
switch (m_type) {
case TRAPEZOIDAL:
return "TRAPEZOIDAL";
break;
case TRAPEZOIDALLOG:
return "TRAPEZOIDALLOG";
break;
case GaussLegendre:
return "Gauss-Legendre";
break;
case DEXP:
return "DEXP";
break;
case GK21_ADAPTIVE:
return "GK21_ADAPTIVE";
break;
default:
return "UNDEFINED";
}
switch (m_type) {
case TRAPEZOIDAL:
return "TRAPEZOIDAL";
break;
case TRAPEZOIDALLOG:
return "TRAPEZOIDALLOG";
break;
case GaussLegendre:
return "Gauss-Legendre";
break;
case DEXP:
return "DEXP";
break;
case GK21_ADAPTIVE:
return "GK21_ADAPTIVE";
break;
default:
return "UNDEFINED";
}
}
std::string IntegratorType1D::getShortName() {
switch (m_type) {
case TRAPEZOIDAL:
return "TRAPEZOIDAL";
break;
case TRAPEZOIDALLOG:
return "TRAPEZOIDALLOG";
break;
case GaussLegendre:
return "GL";
break;
case DEXP:
return "DEXP";
break;
case GK21_ADAPTIVE:
return "GK21_ADAPTIVE";
break;
default:
return "UNDEFINED";
}
switch (m_type) {
case TRAPEZOIDAL:
return "TRAPEZOIDAL";
break;
case TRAPEZOIDALLOG:
return "TRAPEZOIDALLOG";
break;
case GaussLegendre:
return "GL";
break;
case DEXP:
return "DEXP";
break;
case GK21_ADAPTIVE:
return "GK21_ADAPTIVE";
break;
default:
return "UNDEFINED";
}
}
IntegratorType1D::Type IntegratorType1D::getType() const {
return m_type;
return m_type;
}
void IntegratorType1D::setType(Type type) {
m_type = type;
m_type = type;
}
} /* namespace NumA */
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