code4game/libgltf

View on GitHub
tools/jsonschematoc11/c11types/__init__.py

Summary

Maintainability
A
2 hrs
Test Coverage
"""Build C11 types."""

from .c11typebool import C11TypeBool
from .c11typeinteger import C11TypeInteger
from .c11typenumber import C11TypeNumber
from .c11typestring import C11TypeString
from .c11typearray import C11TypeArray
from .c11typestruct import C11TypeStruct

def BuildC11Type(schemaName, schemaValue, isSchema=False, manualCodeHeaders=None, manualCodeSourcesVariable=None, manualCodeSourcesFunction=None, manualCodeParsersFrom=None, manualCodeParsersTo=None):
    if u'title' not in schemaValue:
        return (None, 1, u'can\'t get the attribute `title` in %s' % schemaName)
    c11Type = None
    if not isSchema and u'type' in schemaValue:
        schemaValueType = schemaValue[u'type']
        if schemaValueType == u'bool' or schemaValueType == u'boolean':
            c11Type = C11TypeBool()
        elif schemaValueType == u'integer':
            c11Type = C11TypeInteger()
        elif schemaValueType == u'number':
            c11Type = C11TypeNumber()
        elif schemaValueType == u'string':
            c11Type = C11TypeString()
        elif schemaValueType == u'array':
            c11Type = C11TypeArray()
        #elif schemaValueType == u'object':
        #    c11Type = C11TypeMap()
    if c11Type is None:
        c11Type = C11TypeStruct()
    c11Type.setSchema(schemaName, schemaValue)
    c11Type.setCodes(manualCodeHeaders, manualCodeSourcesVariable, manualCodeSourcesFunction, manualCodeParsersFrom, manualCodeParsersTo)
    return (c11Type, 0, None)