Merge "Fix simpleContent with extension" into main
diff --git a/src/main/java/com/android/xsdc/cpp/CppCodeGenerator.java b/src/main/java/com/android/xsdc/cpp/CppCodeGenerator.java
index 9bfbe56..a58647d 100644
--- a/src/main/java/com/android/xsdc/cpp/CppCodeGenerator.java
+++ b/src/main/java/com/android/xsdc/cpp/CppCodeGenerator.java
@@ -449,7 +449,7 @@
             }
         }
         if (valueType != null) {
-            parserHeaderFile.printf("const std::optional<%s> _value;\n", valueType.getName());
+            parserHeaderFile.printf("const std::optional<%s> value_;\n", valueType.getName());
         }
 
         parserHeaderFile.printf("public:\n");
@@ -556,12 +556,7 @@
             parserCppFile.printf("%s = _value;\n}\n", variableName);
         }
 
-        if (baseValueType != null) {
-            printSetRawWithElementText("root");
-            parserCppFile.print(baseValueType.getParsingExpression());
-            parserCppFile.printf("instance.setValue(_value);\n");
-            parserCppFile.printf("}\n");
-        } else if (!allElements.isEmpty()) {
+        if (!allElements.isEmpty()) {
             for (int i = 0; i < allElements.size(); ++i) {
                 CppType type = allElementTypes.get(i);
                 XsdElement element = allElements.get(i);
@@ -609,6 +604,10 @@
             }
             parserCppFile.printf("}\n}\n");
         }
+        if (baseValueType != null) {
+            printSetRawWithElementText("root");
+            parserCppFile.print(baseValueType.getParsingExpression());
+        }
         parserCppFile.printf("%s instance%s;\n",
                 fullName, args.length() > 0 ? "(" + args + ")" : "");
         parserCppFile.print("return instance;\n}\n");
@@ -905,6 +904,16 @@
             }
         }
 
+        CppSimpleType valueType = (complexType instanceof XsdSimpleContent) ?
+                getValueType((XsdSimpleContent) complexType, false) : null;
+        if (valueType != null) {
+            constructorArgs.append(String.format(", %s %s", valueType.getName(), "value"));
+            boolean isMultipleType = (valueType.isList() ? true : false);
+            constructor.append(String.format(", %s_(%s)", "value", "value"));
+            // getParsingExpression prepends with underscore, so set args for instantiation
+            args.append(String.format(", %s", "_value"));
+        }
+
         String constructorArgsString = constructorArgs.toString();
         String constructorString = constructor.toString();
         if (constructorArgsString.length() > 0) {