#
# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
#

class TypeParserGenerator(object):
    def __init__(self, cTypeDict):
        self._cTypeDict = cTypeDict
        pass

    def GenerateTypeParser(self, file, ctype):
        print "generating parser for %s" %ctype.getName()
        start = """
bool %s::XmlParse(const xml_node &parent) {
    for (xml_node node = parent.first_child(); node;
         node = node.next_sibling()) {
""" % ctype.getName()
        file.write(start)
        for member in ctype.getDataMembers():
            file.write('        if (strcmp(node.name(), "%s") == 0) {\n' %
                       member.xsd_object.getName())
            indent = ' ' * 12
            cpptype = member.ctypename
            if cpptype == 'int':
                fmt = 'if (!ParseInteger(node, &%s)) return false;\n'
                file.write(indent + fmt % member.membername)
            elif cpptype == 'uint64_t':