Commit 1e707f18 authored by PONCELET's avatar PONCELET

Error while setting valid_min values in code generator and add getter

and setter
parent 8187c5c2
......@@ -832,7 +832,7 @@
"attributes": [
{
"name": "valid_range",
"value": "-180.0, 180.0",
"value": "-180.0f, 180.0f",
"type": "float "
},
{
......@@ -2523,12 +2523,12 @@
{
"name": "valid_min",
"value": "-90",
"type": "float"
"type": "double"
},
{
"name": "valid_max",
"value": "90",
"type": "float"
"type": "double"
},
{
"name": "standard_name",
......@@ -2556,12 +2556,12 @@
{
"name": "valid_min",
"value": "-180",
"type": "float"
"type": "double"
},
{
"name": "valid_max",
"value": "180",
"type": "float"
"type": "double"
},
{
"name": "standard_name",
......
......@@ -11,26 +11,26 @@ public class SCAttributeAdapter {
switch(variable.getType())
{
case "float":
return Arrays.asList(String.format("setFloatFillValue(%s);",attribute.value == null ? "0f":attribute.value));
return Arrays.asList(String.format("setFloatFillValue(%s);",formatAttribute(attribute, variable.getType())));
case "double":
return Arrays.asList(String.format("setDoubleFillValue(%s);",attribute.value == null ? "0":attribute.value));
return Arrays.asList(String.format("setDoubleFillValue(%s);",formatAttribute(attribute, variable.getType())));
case "short":
case "ushort":
return Arrays.asList(String.format("setShortDoubleValue((short)%s);",attribute.value == null ? "0":attribute.value));
return Arrays.asList(String.format("setShortDoubleValue((short)%s);",formatAttribute(attribute, variable.getType())));
case "byte":
return Arrays.asList(String.format("setByteFillValue((byte) %s);",attribute.value == null ? "0":attribute.value));
return Arrays.asList(String.format("setByteFillValue((byte) %s);",formatAttribute(attribute, variable.getType())));
case "uint":
case "int":
return Arrays.asList(String.format("setIntFillValue(%s);",attribute.value == null ? "0":attribute.value));
return Arrays.asList(String.format("setIntFillValue(%s);",formatAttribute(attribute, variable.getType())));
case "ulong":
case "long":
return Arrays.asList(String.format("setLongFillValue(%s);",attribute.value == null ? "0":attribute.value));
return Arrays.asList(String.format("setLongFillValue(%s);",formatAttribute(attribute, variable.getType())));
default:
throw new RuntimeException("Unsupported fill value type " + variable.getType() );
}
// retrieve the fill vale
// retrieve the fill value
} else if(attribute.getName().compareTo("valid_range")==0) {
switch(variable.getType())
{
......@@ -48,11 +48,48 @@ public class SCAttributeAdapter {
return getSourceCode(attribute);
}
} else if(attribute.getName().compareTo("valid_min")==0 || attribute.getName().compareTo("valid_max")==0) {
if(attribute.getType()==null)
{
//treat as String
return getSourceCode(attribute);
}
return Arrays.asList(String.format("addAttribute(\"%s\", %s);",attribute.name, formatAttribute(attribute,variable.getType())));
} else {
return getSourceCode(attribute);
if(attribute.getType()==null)
{
//treat as String
return getSourceCode(attribute);
}
return Arrays.asList(String.format("addAttribute(\"%s\", %s);",attribute.name, formatAttribute(attribute,attribute.getType())));
}
}
private static String formatAttribute(Attribute attribute, String expectedType)
{
switch(expectedType)
{
case "float":
return String.format("(float) %s",attribute.value == null ? "0f":attribute.value);
case "double":
return String.format("(double) %s", attribute.value == null ? "0":attribute.value);
case "short":
case "ushort":
return String.format("(short) %s",attribute.value == null ? "0":attribute.value);
case "byte":
return String.format("(byte) %s",attribute.value == null ? "0":attribute.value);
case "uint":
case "int":
return String.format("(short) %s",attribute.value == null ? "0" :attribute.value);
case "ulong":
case "long":
return String.format("(long) %s",attribute.value == null ? "0": attribute.value);
default:
return String.format("\"%s\"",attribute.value == null ? "":attribute.value);
}
}
public static List<String> getSourceCode(Attribute attribute) {
return Arrays.asList(String.format("addAttribute(\"%s\", \"%s\");",attribute.name, attribute.value == null ? "":attribute.value));
......
......@@ -13,6 +13,19 @@ public class SCDimensionAdapter {
String.format("\t\t%s = addDimension(%s, %s); //%s", getDimVariableName(dimension), getDimNameDeclaration(dimension), "100", dimension.comment==null ? "" : dimension.comment));
}
public static List<String> getSourceAccessor(Dimension dim) {
String name=getDimVariableName(dim);
return Arrays.asList(String.format("\t/**\n"
+ "\t * @return the %s\n"
+ "\t */\n"
+ "\tpublic NCDimension get%s() {\n"
+ "\t\treturn %s;"
+ "\n\t}\n", name,CamelCase(name),name));
}
private static String CamelCase(String name)
{
return name.substring(0, 1).toUpperCase()+name.substring(1);
}
/**
* return the variable declaration
* */
......
......@@ -49,7 +49,7 @@ public class SCGroupAdapter {
// Group name
sourceCode.add(String.format("\n\tpublic static final String GROUP_NAME = \"%s\";", group.name));
// Dimension name code generation
if(!group.dims.isEmpty())
{
......@@ -58,8 +58,8 @@ public class SCGroupAdapter {
sourceCode.add(String.format("\tpublic static final String %s=\"%s\";", SCDimensionAdapter.getDimNameDeclaration(d),SCDimensionAdapter.getDimVariableName(d))));
sourceCode.add("\n");
}
// Variable declaration
group.variables.forEach(v -> sourceCode.add(SCVariableAdapter.getSourceDeclaration(v)));
......@@ -110,6 +110,29 @@ public class SCGroupAdapter {
// End constructor
sourceCode.add("\t}");
// Variables Accessors
if (!group.variables.isEmpty()) {
// sourceCode.add("\n\t/** Accessors**/\n");
group.variables.forEach(v -> {
try {
sourceCode.addAll(SCVariableAdapter.getSourceAccessor(v));
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
// Variables declaration
if (!group.dims.isEmpty()) {
group.dims.forEach(v -> {
try {
sourceCode.addAll(SCDimensionAdapter.getSourceAccessor(v));
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
// End class
sourceCode.add("}");
......
package fr.ifremer.fr.xsf.generator.model;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import fr.ifremer.fr.xsf.generator.DataTypeConverter;
......@@ -8,9 +9,23 @@ import fr.ifremer.fr.xsf.generator.DataTypeConverter;
public class SCVariableAdapter {
public static String getSourceDeclaration(Variable variable) {
return String.format("\tpublic NCVariable %s;", variable.name);
return String.format("\tprivate NCVariable %s;", variable.name);
}
public static List<String> getSourceAccessor(Variable variable) {
return Arrays.asList(String.format("\t/**\n"
+ "\t * @return the %s\n"
+ "\t */\n"
+ "\tpublic NCVariable get%s() {\n"
+ "\t\treturn %s;"
+ "\n\t}\n", variable.name,CamelCase(variable.name),variable.name));
}
private static String CamelCase(String name)
{
return name.substring(0, 1).toUpperCase()+name.substring(1);
}
public static List<String> getSourceCode(Variable variable) throws Exception {
List<String> codeLines = new ArrayList<>();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment