diff --git a/code_generation/enum.cpp b/code_generation/enum.cpp index 934a4c9..4dfdb2b 100644 --- a/code_generation/enum.cpp +++ b/code_generation/enum.cpp @@ -32,6 +32,7 @@ class Enum::Private QString mName; QStringList mEnums; bool mCombinable = false; + bool mTypedef = false; bool mIsQENUM = false; }; @@ -71,7 +72,10 @@ QString Enum::name() const void Enum::printDeclaration(Code &code) const { - code.addLine(QStringLiteral("enum %1 {").arg(d->mName)); + if (d->mTypedef) + code.addLine(QStringLiteral("typedef enum {")); + else + code.addLine(QStringLiteral("enum %1 {").arg(d->mName)); code.indent(); auto last = (d->mEnums.count() - 1); for (int value = 0; value <= last; value++) { @@ -88,7 +92,11 @@ void Enum::printDeclaration(Code &code) const } } code.unindent(); - code.addLine("};"); + if (d->mTypedef) + code.addLine(QString("} %1;").arg(d->mName)); + else + code.addLine("};"); + if (d->mIsQENUM) code.addLine(QStringLiteral("Q_ENUM(%1)").arg(d->mName)); code.newLine(); @@ -98,3 +106,8 @@ void Enum::setIsQENUM(bool qenum) { d->mIsQENUM = qenum; } + +void Enum::setTypedef(bool typeDef) +{ + d->mTypedef = typeDef; +} diff --git a/code_generation/enum.h b/code_generation/enum.h index 1b2ed37..84a80c7 100644 --- a/code_generation/enum.h +++ b/code_generation/enum.h @@ -84,6 +84,14 @@ class KODE_EXPORT Enum */ void setIsQENUM(bool qenum = true); + /** + * @brief setTypedef + * This method can be used to generate typedef for the given enum. + * Using typedefs is mostly useful for C code and not recommended in C++ code. + * @param typeDef + */ + void setTypedef(bool typeDef = true); + private: class Private; Private *d;