Skip to content

Feature Request: Enum-to-String and String-to-Enum Mapping #433

@harinaathgobi1998

Description

@harinaathgobi1998

It would be very helpful if Fast-DDS-Gen could generate enum-to-string and string-to-enum mappings automatically for enums defined in IDL files.

Proposed Solution:

  • Extend the EnumTypeCode.java file to include methods for generating mappings.
  • Modify the CommonEnumType.stg template to generate helper functions like enumToString and stringToEnum.

Example Output:

inline const char* enumToString(MyEnum value) {
    switch (value) {
        case MyEnum::Value1: return "Value1";
        case MyEnum::Value2: return "Value2";
        // ...
        default: return "UNKNOWN";
    }
}

inline MyEnum stringToEnum(const std::string& str) {
    if (str == "Value1") return MyEnum::Value1;
    if (str == "Value2") return MyEnum::Value2;
    // ...
    return MyEnum::UNKNOWN;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions