Skip to content
Snippets Groups Projects
Commit 292a9ef3 authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Fixed some attribute parsing errors

parent 8ce6134e
No related branches found
No related tags found
No related merge requests found
......@@ -7,18 +7,6 @@
namespace mjcf
{
ActuatorType toActuatorType(std::string str)
{
static const std::map<std::string, ActuatorType> map
{
{"motor", ActuatorType::MOTOR},
{"position", ActuatorType::POSITION},
{"velocity", ActuatorType::VELOCITY}
};
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
return map.at(str);
}
std::size_t commonPrefixLength(const std::string& a, const std::string& b)
{
const std::string* smaller = &a;
......@@ -40,6 +28,16 @@ namespace mjcf
return strings[int(b)];
}
void fromAttr(const std::string& valueStr, bool& value)
{
static const std::map<std::string, bool> map = {
{ "true", true },
{ "false", false },
{ "1", true },
{ "0", false },
};
value = map.at(valueStr);
}
Eigen::Vector2f strToVec2(const char* string)
{
......@@ -68,7 +66,7 @@ namespace mjcf
{
return strcmp(lhs, rhs) == 0;
}
}
bool std::operator==(const char* lhs, const std::string& rhs)
......
......@@ -41,13 +41,6 @@ namespace Eigen
namespace mjcf
{
enum class ActuatorType
{
MOTOR, POSITION, VELOCITY
};
ActuatorType toActuatorType(std::string str);
// Get lenght of common prefix of two strings (was used for mergin body names).
std::size_t commonPrefixLength(const std::string& a, const std::string& b);
......@@ -78,6 +71,14 @@ namespace mjcf
/// Single values via boost::lexical cast. Only enabled for non-Eigen types.
template <typename AttrT,
typename std::enable_if<!Eigen::is_eigen_expression<AttrT>::value, AttrT>::type* = nullptr>
void fromAttr(const std::string& valueStr, AttrT& value);
/// Bool
void fromAttr(const std::string& valueStr, bool& value);
/// Eigen Matrix and vectors
template <typename Derived>
void fromAttr(const std::string& valueStr, Eigen::MatrixBase<Derived>& value);
......@@ -85,10 +86,6 @@ namespace mjcf
template <typename Derived>
void fromAttr(const std::string& valueStr, Eigen::QuaternionBase<Derived>& value);
/// Single values via boost::lexical cast. Only enabled for non-Eigen types.
template <typename AttrT,
typename std::enable_if<!Eigen::is_eigen_expression<AttrT>::value, AttrT>::type* = nullptr>
void fromAttr(const std::string& valueStr, AttrT& value);
template <typename Scalar>
......@@ -109,9 +106,9 @@ namespace mjcf
template<typename Derived>
std::string toAttr(const Eigen::MatrixBase<Derived>& mat)
{
static const Eigen::IOFormat iof
static const Eigen::IOFormat iof
{
7, 0, "", " ", "", "", "", ""
Eigen::FullPrecision, Eigen::DontAlignCols, " ", " ", "", "", "", ""
};
std::stringstream ss;
......
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