All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.joynr.generator.cpp.communicationmodel.MapHTemplate Maven / Gradle / Ivy

There is a newer version: 1.25.0
Show newest version
package io.joynr.generator.cpp.communicationmodel;

import com.google.common.collect.Iterables;
import com.google.inject.assistedinject.Assisted;
import io.joynr.generator.cpp.util.CppStdTypeUtil;
import io.joynr.generator.cpp.util.JoynrCppGeneratorExtensions;
import io.joynr.generator.cpp.util.TemplateBase;
import io.joynr.generator.templates.MapTemplate;
import io.joynr.generator.templates.util.NamingUtil;
import java.util.Set;
import javax.inject.Inject;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Extension;
import org.franca.core.franca.FBasicTypeId;
import org.franca.core.franca.FMapType;
import org.franca.core.franca.FType;

@SuppressWarnings("all")
public class MapHTemplate extends MapTemplate {
  @Inject
  @Extension
  private JoynrCppGeneratorExtensions _joynrCppGeneratorExtensions;

  @Inject
  @Extension
  private CppStdTypeUtil _cppStdTypeUtil;

  @Inject
  @Extension
  private NamingUtil _namingUtil;

  @Inject
  @Extension
  private TemplateBase _templateBase;

  @Inject
  public MapHTemplate(@Assisted final FMapType type) {
    super(type);
  }

  @Override
  public CharSequence generate(final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    final String typeName = this._namingUtil.joynrName(this.type);
    _builder.newLineIfNotEmpty();
    String _packagePathWithJoynrPrefix = this._joynrCppGeneratorExtensions.getPackagePathWithJoynrPrefix(this.type, "_", true, generateVersion);
    String _plus = ("GENERATED_TYPE_" + _packagePathWithJoynrPrefix);
    String _plus_1 = (_plus + "_");
    String _plus_2 = (_plus_1 + typeName);
    final String headerGuard = (_plus_2 + "_H").toUpperCase();
    _builder.newLineIfNotEmpty();
    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();
    _builder.newLine();
    _builder.append("#include ");
    _builder.newLine();
    _builder.append("#include \"joynr/HashUtil.h\"");
    _builder.newLine();
    _builder.newLine();
    _builder.append("// include complex Datatype headers.");
    _builder.newLine();
    final Iterable typeDependencies = this._cppStdTypeUtil.getTypeDependencies(this.type);
    _builder.newLineIfNotEmpty();
    {
      Set _includesFor = this._cppStdTypeUtil.getIncludesFor(Iterables.filter(typeDependencies, FBasicTypeId.class));
      for(final String member : _includesFor) {
        _builder.append("#include ");
        _builder.append(member);
        _builder.newLineIfNotEmpty();
      }
    }
    {
      Iterable _filter = Iterables.filter(typeDependencies, FType.class);
      for(final FType member_1 : _filter) {
        _builder.append("#include ");
        String _includeOf = this._cppStdTypeUtil.getIncludeOf(member_1, generateVersion);
        _builder.append(_includeOf);
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    _builder.append("#include \"joynr/serializer/Serializer.h\"");
    _builder.newLine();
    _builder.newLine();
    String _namespaceStarter = this._joynrCppGeneratorExtensions.getNamespaceStarter(this.type, true, generateVersion);
    _builder.append(_namespaceStarter);
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    CharSequence _typeDefinition = this.getTypeDefinition(this.type, generateVersion);
    _builder.append(_typeDefinition);
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    String _namespaceEnder = this._joynrCppGeneratorExtensions.getNamespaceEnder(this.type, true, generateVersion);
    _builder.append(_namespaceEnder);
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("MUESLI_REGISTER_TYPE(");
    String _typeName = this._cppStdTypeUtil.getTypeName(this.type, generateVersion);
    _builder.append(_typeName);
    _builder.append(", \"");
    String _replace = this._cppStdTypeUtil.getTypeName(this.type, generateVersion).replace("::", ".");
    _builder.append(_replace);
    _builder.append("\")");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("#endif // ");
    _builder.append(headerGuard);
    _builder.newLineIfNotEmpty();
    return _builder;
  }

  private CharSequence getTypeDefinition(final FMapType type, final boolean generateVersion) {
    StringConcatenation _builder = new StringConcatenation();
    String _typeName = this._cppStdTypeUtil.getTypeName(type.getKeyType(), generateVersion);
    String _plus = ("std::map<" + _typeName);
    String _plus_1 = (_plus + ", ");
    String _typeName_1 = this._cppStdTypeUtil.getTypeName(type.getValueType(), generateVersion);
    String _plus_2 = (_plus_1 + _typeName_1);
    final String mapType = (_plus_2 + ">");
    _builder.newLineIfNotEmpty();
    _builder.append("/**");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @brief Map class ");
    String _joynrName = this._namingUtil.joynrName(type);
    _builder.append(_joynrName, " ");
    _builder.newLineIfNotEmpty();
    _builder.append(" ");
    _builder.append("*");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* @version ");
    _builder.append(this.majorVersion, " ");
    _builder.append(".");
    _builder.append(this.minorVersion, " ");
    _builder.newLineIfNotEmpty();
    _builder.append(" ");
    _builder.append("*/");
    _builder.newLine();
    _builder.append("class ");
    String _joynrName_1 = this._namingUtil.joynrName(type);
    _builder.append(_joynrName_1);
    _builder.append(" : public ");
    _builder.append(mapType);
    _builder.newLineIfNotEmpty();
    _builder.append("{");
    _builder.newLine();
    _builder.append("public:");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("/**");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("* @brief MAJOR_VERSION The major version of this struct as specified in the");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("* type collection or interface in the Franca model.");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("*/");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static const std::int32_t MAJOR_VERSION;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("/**");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("* @brief MINOR_VERSION The minor version of this struct as specified in the");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("* type collection or interface in the Franca model.");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("*/");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static const std::int32_t MINOR_VERSION;");
    _builder.newLine();
    _builder.newLine();
    _builder.append("private:");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("using ");
    _builder.append(mapType, "\t");
    _builder.append("::map;");
    _builder.newLineIfNotEmpty();
    _builder.append("};");
    _builder.newLine();
    return _builder;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy