Skip to content

Commit 11f88b3

Browse files
authored
Merge pull request #25 from phoppermann/patch-1
CppGenerator: fix include paths
2 parents 968dc26 + e91c969 commit 11f88b3

File tree

1 file changed

+21
-35
lines changed

1 file changed

+21
-35
lines changed

src/main/java/edu/nps/moves/xmlpg/CppGenerator.java

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -187,28 +187,21 @@ public void writeHeaderFile(GeneratedClass aClass) {
187187
// Write includes for any classes we may reference. this generates multiple #includes if we
188188
// use a class multiple times, but that's innocuous. We could sort and do a unqiue to prevent
189189
// this if so inclined.
190-
String namespace = languageProperties.getProperty("namespace");
191-
if (namespace == null) {
192-
namespace = "";
193-
} else {
194-
namespace = namespace + "/";
195-
}
196-
197190
boolean hasVariableLengthList = false;
198191

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

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

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

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

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

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

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

236229
if (msMacroFile != null) {
237-
pw.println("#include <" + namespace + msMacroFile + ".h>");
230+
pw.println("#include <" + msMacroFile + ".h>");
238231
}
239232

240233
pw.println();
241234

242235
pw.println();
243236

244237
// Print out namespace, if any
245-
namespace = languageProperties.getProperty("namespace");
238+
String namespace = languageProperties.getProperty("namespace");
246239
if (namespace != null) {
247240
pw.println("namespace " + namespace);
248241
pw.println("{");
@@ -290,7 +283,7 @@ public void writeHeaderFile(GeneratedClass aClass) {
290283
}
291284

292285
pw.println(
293-
" " + types.get(anAttribute.getType()) + " " + IVAR_PREFIX + anAttribute.getName() + "; ");
286+
" " + types.get(anAttribute.getType()) + " " + IVAR_PREFIX + anAttribute.getName() + ";");
294287
pw.println();
295288

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

303-
pw.println(" " + anAttribute.getType() + " " + IVAR_PREFIX + anAttribute.getName() + "; ");
296+
pw.println(" " + anAttribute.getType() + " " + IVAR_PREFIX + anAttribute.getName() + ";");
304297
pw.println();
305298
}
306299

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

312305
if (anAttribute.getUnderlyingTypeIsPrimitive())
313306
pw.println(" " + types.get(anAttribute.getType()) + " " + IVAR_PREFIX + anAttribute.getName()
314-
+ "[" + anAttribute.getListLength() + "]; ");
307+
+ "[" + anAttribute.getListLength() + "];");
315308
else
316309
pw.println(" " + anAttribute.getType() + " " + IVAR_PREFIX + anAttribute.getName() + "["
317-
+ anAttribute.getListLength() + "]; ");
310+
+ anAttribute.getListLength() + "];");
318311
pw.println();
319312
}
320313

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

326319
if (anAttribute.getUnderlyingTypeIsPrimitive())
327320
pw.println(" std::vector<" + types.get(anAttribute.getType()) + "> " + IVAR_PREFIX
328-
+ anAttribute.getName() + "; ");
321+
+ anAttribute.getName() + ";");
329322
else
330323
pw.println(" std::vector<" + anAttribute.getType() + "> " + IVAR_PREFIX + anAttribute.getName()
331-
+ "; ");
324+
+ ";");
332325
pw.println();
333326
}
334327
}
@@ -362,19 +355,19 @@ public void writeHeaderFile(GeneratedClass aClass) {
362355

363356
if (anAttribute.getAttributeKind() == ClassAttribute.ClassAttributeType.CLASSREF) {
364357
pw.println(" " + anAttribute.getType() + "& " + "get" + this.initialCap(anAttribute.getName())
365-
+ "(); ");
358+
+ "();");
366359
pw.println(" const " + anAttribute.getType() + "& get" + this.initialCap(anAttribute.getName())
367-
+ "() const; ");
360+
+ "() const;");
368361
pw.println(" void set" + this.initialCap(anAttribute.getName()) + "(const "
369362
+ anAttribute.getType() + " &pX);");
370363
}
371364

372365
if (anAttribute.getAttributeKind() == ClassAttribute.ClassAttributeType.FIXED_LIST) {
373366
// Sleaze. We need to figure out what type of array we are, and this is slightly complex.
374367
String arrayType = this.getArrayType(anAttribute.getType());
375-
pw.println(" " + arrayType + "* get" + this.initialCap(anAttribute.getName()) + "(); ");
368+
pw.println(" " + arrayType + "* get" + this.initialCap(anAttribute.getName()) + "();");
376369
pw.println(" const " + arrayType + "* get" + this.initialCap(anAttribute.getName())
377-
+ "() const; ");
370+
+ "() const;");
378371
pw.println(" void set" + this.initialCap(anAttribute.getName()) + "( const " + arrayType
379372
+ "* pX);");
380373
if (anAttribute.getCouldBeString() == true) {
@@ -392,9 +385,9 @@ public void writeHeaderFile(GeneratedClass aClass) {
392385
attributeType = anAttribute.getType();
393386
}
394387
pw.println(" std::vector<" + attributeType + ">& " + "get"
395-
+ this.initialCap(anAttribute.getName()) + "(); ");
388+
+ this.initialCap(anAttribute.getName()) + "();");
396389
pw.println(" const std::vector<" + attributeType + ">& " + "get"
397-
+ this.initialCap(anAttribute.getName()) + "() const; ");
390+
+ this.initialCap(anAttribute.getName()) + "() const;");
398391
pw.println(" void set" + this.initialCap(anAttribute.getName()) + "(const std::vector<"
399392
+ attributeType + ">& pX);");
400393
}
@@ -440,17 +433,10 @@ public void writeCppFile(GeneratedClass aClass) {
440433
outputFile.createNewFile();
441434
PrintWriter pw = new PrintWriter(outputFile);
442435

443-
String namespace = languageProperties.getProperty("namespace");
444-
if (namespace == null) {
445-
namespace = "";
446-
} else {
447-
namespace = namespace + "/";
448-
}
449-
450-
pw.println("#include <" + namespace + aClass.getName() + ".h> ");
436+
pw.println("#include <" + aClass.getName() + ".h>");
451437
pw.println();
452438

453-
namespace = languageProperties.getProperty("namespace");
439+
String namespace = languageProperties.getProperty("namespace");
454440
if (namespace != null) {
455441
pw.println("using namespace " + namespace + ";\n");
456442
}

0 commit comments

Comments
 (0)