io.joynr.generator.cpp.communicationmodel.EnumHTemplate Maven / Gradle / Ivy
package io.joynr.generator.cpp.communicationmodel;
import com.google.inject.Inject;
import io.joynr.generator.cpp.util.JoynrCppGeneratorExtensions;
import io.joynr.generator.cpp.util.TemplateBase;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Extension;
import org.franca.core.franca.FEnumerationType;
import org.franca.core.franca.FEnumerator;
@SuppressWarnings("all")
public class EnumHTemplate {
@Inject
@Extension
private TemplateBase _templateBase;
@Inject
@Extension
private JoynrCppGeneratorExtensions _joynrCppGeneratorExtensions;
public CharSequence generate(final FEnumerationType type) {
CharSequence _xblockexpression = null;
{
final String typeName = this._joynrCppGeneratorExtensions.joynrName(type);
String _packagePathWithJoynrPrefix = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(type, "_");
String _plus = ("GENERATED_ENUM_" + _packagePathWithJoynrPrefix);
String _plus_1 = (_plus + "_");
String _plus_2 = (_plus_1 + typeName);
String _plus_3 = (_plus_2 + "_h");
final String headerGuard = _plus_3.toUpperCase();
StringConcatenation _builder = new StringConcatenation();
CharSequence _warning = this._templateBase.warning();
_builder.append(_warning, "");
_builder.newLineIfNotEmpty();
_builder.append("#ifndef ");
_builder.append(headerGuard, "");
_builder.newLineIfNotEmpty();
_builder.append("#define ");
_builder.append(headerGuard, "");
_builder.newLineIfNotEmpty();
_builder.newLine();
String _dllExportIncludeStatement = this._joynrCppGeneratorExtensions.getDllExportIncludeStatement();
_builder.append(_dllExportIncludeStatement, "");
_builder.newLineIfNotEmpty();
_builder.append("#include ");
_builder.newLine();
_builder.append("#include ");
_builder.newLine();
_builder.newLine();
String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(type);
_builder.append(_namespaceStarter, "");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("class ");
String _dllExportMacro = this._joynrCppGeneratorExtensions.getDllExportMacro();
_builder.append(_dllExportMacro, "");
_builder.append(" ");
_builder.append(typeName, "");
_builder.append(" : public QObject {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("Q_OBJECT");
_builder.newLine();
_builder.append("\t");
_builder.append("Q_ENUMS(");
String _nestedEnumName = this._joynrCppGeneratorExtensions.getNestedEnumName();
_builder.append(_nestedEnumName, " ");
_builder.append(")");
_builder.newLineIfNotEmpty();
_builder.append("public:");
_builder.newLine();
_builder.append("\t");
_builder.append("enum ");
String _nestedEnumName_1 = this._joynrCppGeneratorExtensions.getNestedEnumName();
_builder.append(_nestedEnumName_1, " ");
_builder.append(" {");
_builder.newLineIfNotEmpty();
{
EList _enumElements = this._joynrCppGeneratorExtensions.getEnumElements(type);
boolean _hasElements = false;
for(final FEnumerator enumtype : _enumElements) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate(",", " ");
}
_builder.append("\t\t");
String _joynrName = this._joynrCppGeneratorExtensions.joynrName(enumtype);
_builder.append(_joynrName, " ");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.append("};");
_builder.newLine();
_builder.append("\t");
_builder.append("// Constructors required by QT metatype system");
_builder.newLine();
_builder.append("\t");
_builder.append(typeName, " ");
_builder.append("() : QObject() {}");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append(typeName, " ");
_builder.append("(const ");
_builder.append(typeName, " ");
_builder.append("& o) : QObject() { Q_UNUSED(o); }");
_builder.newLineIfNotEmpty();
_builder.append("};");
_builder.newLine();
_builder.newLine();
String _namespaceEnder = this._joynrCppGeneratorExtensions.getNamespaceEnder(type);
_builder.append(_namespaceEnder, "");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.newLine();
_builder.append("// Metatype for the wrapper class\t");
_builder.newLine();
_builder.append("typedef ");
String _packagePathWithJoynrPrefix_1 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(type, "::");
_builder.append(_packagePathWithJoynrPrefix_1, "");
_builder.append("::");
_builder.append(typeName, "");
_builder.append(" ");
String _packagePathWithJoynrPrefix_2 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(type, "__");
_builder.append(_packagePathWithJoynrPrefix_2, "");
_builder.append("__");
_builder.append(typeName, "");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("Q_DECLARE_METATYPE(");
String _packagePathWithJoynrPrefix_3 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(type, "__");
_builder.append(_packagePathWithJoynrPrefix_3, "");
_builder.append("__");
_builder.append(typeName, "");
_builder.append(")");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("// Metatypes for the ");
String _nestedEnumName_2 = this._joynrCppGeneratorExtensions.getNestedEnumName();
_builder.append(_nestedEnumName_2, "");
_builder.newLineIfNotEmpty();
_builder.append("typedef ");
String _packagePathWithJoynrPrefix_4 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(type, "::");
_builder.append(_packagePathWithJoynrPrefix_4, "");
_builder.append("::");
_builder.append(typeName, "");
_builder.append("::");
String _nestedEnumName_3 = this._joynrCppGeneratorExtensions.getNestedEnumName();
_builder.append(_nestedEnumName_3, "");
_builder.append(" ");
String _packagePathWithJoynrPrefix_5 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(type, "__");
_builder.append(_packagePathWithJoynrPrefix_5, "");
_builder.append("__");
_builder.append(typeName, "");
_builder.append("__");
String _nestedEnumName_4 = this._joynrCppGeneratorExtensions.getNestedEnumName();
_builder.append(_nestedEnumName_4, "");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("Q_DECLARE_METATYPE(");
String _packagePathWithJoynrPrefix_6 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(type, "__");
_builder.append(_packagePathWithJoynrPrefix_6, "");
_builder.append("__");
_builder.append(typeName, "");
_builder.append("__");
String _nestedEnumName_5 = this._joynrCppGeneratorExtensions.getNestedEnumName();
_builder.append(_nestedEnumName_5, "");
_builder.append(")");
_builder.newLineIfNotEmpty();
_builder.append("Q_DECLARE_METATYPE(QList<");
String _packagePathWithJoynrPrefix_7 = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(type, "__");
_builder.append(_packagePathWithJoynrPrefix_7, "");
_builder.append("__");
_builder.append(typeName, "");
_builder.append("__");
String _nestedEnumName_6 = this._joynrCppGeneratorExtensions.getNestedEnumName();
_builder.append(_nestedEnumName_6, "");
_builder.append(">)");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("#endif // ");
_builder.append(headerGuard, "");
_builder.newLineIfNotEmpty();
_xblockexpression = (_builder);
}
return _xblockexpression;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy