Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Commit

Permalink
Added C++ struct for xs:float in type generator to ease handling of m…
Browse files Browse the repository at this point in the history
…antissa and exponent in EXI module.
  • Loading branch information
Sascha Seidel committed Mar 26, 2012
1 parent d385862 commit e9dcab8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
@@ -1,4 +1,4 @@
/** 19.03.2012 11:46 */
/** 26.03.2012 12:19 */
package fabric.module.typegen.cpp;

import java.util.Map;
Expand Down Expand Up @@ -427,31 +427,31 @@ private String generateRestrictionChecks(final AttributeContainer.RestrictedElem
String.format(comment, "maxLength"));
}

if (member.isMinInclusiveRestricted())
if (member.isMinInclusiveRestricted() && !("xsd_float_t").equals(member.type)) // No restrictions on float struct in C++
{
result += CppRestrictionHelper.createCheckCode(
CppRestrictionHelper.minInclusiveExpression(member),
String.format(message, "minInclusive", member.name),
String.format(comment, "minInclusive"));
}

if (member.isMaxInclusiveRestricted())
if (member.isMaxInclusiveRestricted() && !("xsd_float_t").equals(member.type)) // No restrictions on float struct in C++
{
result += CppRestrictionHelper.createCheckCode(
CppRestrictionHelper.maxInclusiveExpression(member),
String.format(message, "maxInclusive", member.name),
String.format(comment, "maxInclusive"));
}

if (member.isMinExclusiveRestricted())
if (member.isMinExclusiveRestricted() && !("xsd_float_t").equals(member.type)) // No restrictions on float struct in C++
{
result += CppRestrictionHelper.createCheckCode(
CppRestrictionHelper.minExclusiveExpression(member),
String.format(message, "minExclusive", member.name),
String.format(comment, "minExclusive"));
}

if (member.isMaxExclusiveRestricted())
if (member.isMaxExclusiveRestricted() && !("xsd_float_t").equals(member.type)) // No restrictions on float struct in C++
{
result += CppRestrictionHelper.createCheckCode(
CppRestrictionHelper.maxExclusiveExpression(member),
Expand Down
Expand Up @@ -18,7 +18,7 @@ public class CppMapper extends Mapper
public void createMapping()
{
types.put("FBoolean", "bool");
types.put("FFloat", "float");
types.put("FFloat", "xsd_float_t");
types.put("FDouble", "double");
types.put("FByte", "int8");
types.put("FUnsignedByte", "uint8");
Expand Down
Expand Up @@ -374,7 +374,7 @@ public static String minExclusiveExpression(final AttributeContainer.RestrictedE
{
result = String.format("%s::compare(%s, \"%s\") <= 0",
CppUtilHelper.FILE_NAME, member.name, member.restrictions.minExclusive);
}
}
else
{
result = String.format("%s <= %d", member.name, Long.parseLong(member.restrictions.minExclusive));
Expand Down
@@ -1,4 +1,4 @@
/** 09.01.2012 17:24 */
/** 26.03.2012 11:51 */
package fabric.module.typegen.cpp;

import java.util.ArrayList;
Expand Down Expand Up @@ -114,7 +114,8 @@ private static CStruct[] createStructs() throws Exception
// xs:gDay is added as type definition
structs.add(CppTypeHelper.createDurationDefinition());
structs.add(CppTypeHelper.createNotationDefinition());
structs.add(CppTypeHelper.createQNameDefinition());
structs.add(CppTypeHelper.createQNameDefinition());
structs.add(CppTypeHelper.createFloatDefinition());

return structs.toArray(new CStruct[0]);
}
Expand Down Expand Up @@ -406,4 +407,27 @@ private static CStruct createQNameDefinition() throws Exception

return qNameDefinition;
}

/**
* Create struct definition for the xs:float type.
*
* typedef struct {
* int32 mantissa;
* int16 exponent;
* } xsd_float_t;
*
* @return Struct with xs:float definition
*
* @throws Exception Error during code generation
*/
private static CStruct createFloatDefinition() throws Exception
{
CParam mantissa = CParam.factory.create("int32", "mantissa");
CParam exponent = CParam.factory.create("int16", "exponent");

CStruct floatDefinition = CStruct.factory.create("", "xsd_float_t", true, mantissa, exponent);
floatDefinition.setComment(new CCommentImpl("xs:float"));

return floatDefinition;
}
}

0 comments on commit e9dcab8

Please sign in to comment.