Skip to content

Commit

Permalink
Merge pull request #25 from phoppermann/patch-1
Browse files Browse the repository at this point in the history
CppGenerator: fix include paths
  • Loading branch information
leif81 authored Jan 22, 2021
2 parents 968dc26 + e91c969 commit 11f88b3
Showing 1 changed file with 21 additions and 35 deletions.
56 changes: 21 additions & 35 deletions src/main/java/edu/nps/moves/xmlpg/CppGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,28 +187,21 @@ public void writeHeaderFile(GeneratedClass aClass) {
// Write includes for any classes we may reference. this generates multiple #includes if we
// use a class multiple times, but that's innocuous. We could sort and do a unqiue to prevent
// this if so inclined.
String namespace = languageProperties.getProperty("namespace");
if (namespace == null) {
namespace = "";
} else {
namespace = namespace + "/";
}

boolean hasVariableLengthList = false;

for (int idx = 0; idx < aClass.getClassAttributes().size(); idx++) {
ClassAttribute anAttribute = (ClassAttribute) aClass.getClassAttributes().get(idx);

// If this attribute is a class, we need to do an import on that class
if (anAttribute.getAttributeKind() == ClassAttribute.ClassAttributeType.CLASSREF) {
pw.println("#include <" + namespace + anAttribute.getType() + ".h>");
pw.println("#include <" + anAttribute.getType() + ".h>");
}

// If this attribute is a list with class type, we also need to do an import on that class
if ((anAttribute.getAttributeKind() == ClassAttribute.ClassAttributeType.FIXED_LIST
|| anAttribute.getAttributeKind() == ClassAttribute.ClassAttributeType.VARIABLE_LIST)
&& !anAttribute.getUnderlyingTypeIsPrimitive()) {
pw.println("#include <" + namespace + anAttribute.getType() + ".h>");
pw.println("#include <" + anAttribute.getType() + ".h>");
}

// if this attribute is a variable-length list that holds a class, we need to
Expand All @@ -224,25 +217,25 @@ public void writeHeaderFile(GeneratedClass aClass) {

// if we inherit from another class we need to do an include on it
if (!(aClass.getParentClass().equalsIgnoreCase("root"))) {
pw.println("#include <" + namespace + aClass.getParentClass() + ".h>");
pw.println("#include <" + aClass.getParentClass() + ".h>");
}

// "the usual" includes.
pw.println("#include <" + namespace + "DataStream.h>");
pw.println("#include <utils/DataStream.h>");

// This is a macro file included only for microsoft compilers. set in the cpp properties tag.
String msMacroFile = "msLibMacro";
String msMacroFile = "dis6/msLibMacro";

if (msMacroFile != null) {
pw.println("#include <" + namespace + msMacroFile + ".h>");
pw.println("#include <" + msMacroFile + ".h>");
}

pw.println();

pw.println();

// Print out namespace, if any
namespace = languageProperties.getProperty("namespace");
String namespace = languageProperties.getProperty("namespace");
if (namespace != null) {
pw.println("namespace " + namespace);
pw.println("{");
Expand Down Expand Up @@ -290,7 +283,7 @@ public void writeHeaderFile(GeneratedClass aClass) {
}

pw.println(
" " + types.get(anAttribute.getType()) + " " + IVAR_PREFIX + anAttribute.getName() + "; ");
" " + types.get(anAttribute.getType()) + " " + IVAR_PREFIX + anAttribute.getName() + ";");
pw.println();

}
Expand All @@ -300,7 +293,7 @@ public void writeHeaderFile(GeneratedClass aClass) {
pw.println(" " + "/** " + anAttribute.getComment() + " */");
}

pw.println(" " + anAttribute.getType() + " " + IVAR_PREFIX + anAttribute.getName() + "; ");
pw.println(" " + anAttribute.getType() + " " + IVAR_PREFIX + anAttribute.getName() + ";");
pw.println();
}

Expand All @@ -311,10 +304,10 @@ public void writeHeaderFile(GeneratedClass aClass) {

if (anAttribute.getUnderlyingTypeIsPrimitive())
pw.println(" " + types.get(anAttribute.getType()) + " " + IVAR_PREFIX + anAttribute.getName()
+ "[" + anAttribute.getListLength() + "]; ");
+ "[" + anAttribute.getListLength() + "];");
else
pw.println(" " + anAttribute.getType() + " " + IVAR_PREFIX + anAttribute.getName() + "["
+ anAttribute.getListLength() + "]; ");
+ anAttribute.getListLength() + "];");
pw.println();
}

Expand All @@ -325,10 +318,10 @@ public void writeHeaderFile(GeneratedClass aClass) {

if (anAttribute.getUnderlyingTypeIsPrimitive())
pw.println(" std::vector<" + types.get(anAttribute.getType()) + "> " + IVAR_PREFIX
+ anAttribute.getName() + "; ");
+ anAttribute.getName() + ";");
else
pw.println(" std::vector<" + anAttribute.getType() + "> " + IVAR_PREFIX + anAttribute.getName()
+ "; ");
+ ";");
pw.println();
}
}
Expand Down Expand Up @@ -362,19 +355,19 @@ public void writeHeaderFile(GeneratedClass aClass) {

if (anAttribute.getAttributeKind() == ClassAttribute.ClassAttributeType.CLASSREF) {
pw.println(" " + anAttribute.getType() + "& " + "get" + this.initialCap(anAttribute.getName())
+ "(); ");
+ "();");
pw.println(" const " + anAttribute.getType() + "& get" + this.initialCap(anAttribute.getName())
+ "() const; ");
+ "() const;");
pw.println(" void set" + this.initialCap(anAttribute.getName()) + "(const "
+ anAttribute.getType() + " &pX);");
}

if (anAttribute.getAttributeKind() == ClassAttribute.ClassAttributeType.FIXED_LIST) {
// Sleaze. We need to figure out what type of array we are, and this is slightly complex.
String arrayType = this.getArrayType(anAttribute.getType());
pw.println(" " + arrayType + "* get" + this.initialCap(anAttribute.getName()) + "(); ");
pw.println(" " + arrayType + "* get" + this.initialCap(anAttribute.getName()) + "();");
pw.println(" const " + arrayType + "* get" + this.initialCap(anAttribute.getName())
+ "() const; ");
+ "() const;");
pw.println(" void set" + this.initialCap(anAttribute.getName()) + "( const " + arrayType
+ "* pX);");
if (anAttribute.getCouldBeString() == true) {
Expand All @@ -392,9 +385,9 @@ public void writeHeaderFile(GeneratedClass aClass) {
attributeType = anAttribute.getType();
}
pw.println(" std::vector<" + attributeType + ">& " + "get"
+ this.initialCap(anAttribute.getName()) + "(); ");
+ this.initialCap(anAttribute.getName()) + "();");
pw.println(" const std::vector<" + attributeType + ">& " + "get"
+ this.initialCap(anAttribute.getName()) + "() const; ");
+ this.initialCap(anAttribute.getName()) + "() const;");
pw.println(" void set" + this.initialCap(anAttribute.getName()) + "(const std::vector<"
+ attributeType + ">& pX);");
}
Expand Down Expand Up @@ -440,17 +433,10 @@ public void writeCppFile(GeneratedClass aClass) {
outputFile.createNewFile();
PrintWriter pw = new PrintWriter(outputFile);

String namespace = languageProperties.getProperty("namespace");
if (namespace == null) {
namespace = "";
} else {
namespace = namespace + "/";
}

pw.println("#include <" + namespace + aClass.getName() + ".h> ");
pw.println("#include <" + aClass.getName() + ".h>");
pw.println();

namespace = languageProperties.getProperty("namespace");
String namespace = languageProperties.getProperty("namespace");
if (namespace != null) {
pw.println("using namespace " + namespace + ";\n");
}
Expand Down

0 comments on commit 11f88b3

Please sign in to comment.