Skip to content
Snippets Groups Projects
Commit 8cabc63e authored by Fabian Tërnava's avatar Fabian Tërnava
Browse files

add default initialization for enum values

parent e4253c36
No related branches found
No related tags found
1 merge request!336Fix/improve cppgen
......@@ -55,6 +55,8 @@ namespace armarx::aron::codegenerator::cpp::generator
// add legacy typedef
fields.push_back(std::make_shared<CppField>("using", std::string(IMPL_ENUM), simox::alg::to_lower(className) + "_details::Enum", "Legacy typedef of enum"));
ARMARX_CHECK(type.getAcceptedValueMap().size() > 0);
enum_to_name << "{" << std::endl;
name_to_enum << "{" << std::endl;
enum_to_value << "{" << std::endl;
......@@ -81,7 +83,7 @@ namespace armarx::aron::codegenerator::cpp::generator
fields.push_back(std::make_shared<CppField>("static inline const std::map<" + std::string(IMPL_ENUM) + ", int>", "EnumToValueMap", enum_to_value.str(), "Mapping enum values to a int value"));
fields.push_back(std::make_shared<CppField>("static inline const std::map<int, " + std::string(IMPL_ENUM) + ">", "ValueToEnumMap", value_to_enum.str(), "Mapping int values to a enum"));
fields.push_back(std::make_shared<CppField>(std::string(IMPL_ENUM), "value", "", "The current value of the enum object"));
fields.push_back(std::make_shared<CppField>(std::string(IMPL_ENUM), "value", type.getAcceptedValueNames()[0], "The current value of the enum object"));
return fields;
}
......@@ -162,12 +164,6 @@ namespace armarx::aron::codegenerator::cpp::generator
return c;
}*/
std::pair<std::vector<std::pair<std::string, std::string>>, bool> IntEnumClass::getCtorInitializers(const std::string&) const
{
ARMARX_CHECK(type.getAcceptedValueNames().size() > 0);
return {{{"value", type.getAcceptedValueNames()[0]}}, true};
}
CppCtorPtr IntEnumClass::toEnumCtor(const std::string& name) const
{
CppCtorPtr c = std::make_shared<CppCtor>(name + "(const " + std::string(IMPL_ENUM) + " e)");
......
......@@ -43,8 +43,6 @@ namespace armarx::aron::codegenerator::cpp::generator
// virtual implementations
std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const final;
std::pair<std::vector<std::pair<std::string, std::string>>, bool> getCtorInitializers(const std::string&) const final;
CppBlockPtr getResetHardBlock(const std::string& cppAccessor) const final;
CppBlockPtr getResetSoftBlock(const std::string& cppAccessor) const final;
CppBlockPtr getWriteTypeBlock(const std::string& typeAccessor, const std::string& cppAccessor, const Path&, std::string& variantAccessor) const final;
......
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