public void generate(ClassNode root, PeerGenSettings peerGenSettings)
            throws java.io.IOException {
        this.peerGenSettings = peerGenSettings;

        String fullFileName = peerGenSettings.getProject().getCPPOutputDir() + File.separatorChar;
        if (root.getPackageName().equals("") == true) {
            fullFileName = root.getCPPClassName() + "Peer.h";
        } else {
            fullFileName = root.getPackageName().replace('.', File.separatorChar) + File.separatorChar + root.getCPPClassName() + "Peer.h";
        }

        FormattedFileWriter writer = new FormattedFileWriter(fullFileName, peerGenSettings.isDestructive() || peerGenSettings.getUseInheritance());
        String def = "__" + root.getPackageName().replace('.', '_') + "_" + root.getCPPClassName() + "Peer_H";
        writer.outputLine("#ifndef " + def);
        writer.outputLine("#define " + def);
        writer.newLine(2);

        generateIncludes(root, writer);

        Iterator it = root.getNamespaceElements();
        int nestedLevels = 0;
        while (it.hasNext() == true) {
            writer.outputLine("namespace " + (String) it.next());
            writer.outputLine("{");
            writer.incTabLevel();
            ++nestedLevels;
        }

        writer.outputLine("class " + root.getCPPClassName() + "Peer");
        writer.outputLine("{");
        writer.outputLine("private:");
        writer.incTabLevel();
        writer.decTabLevel();
        writer.newLine(1);
        writer.outputLine("public:");
        writer.incTabLevel();
        writer.outputLine(root.getCPPClassName() + "Peer();");
        writer.newLine(1);
        generateMethods(root, writer);
        writer.decTabLevel();
        writer.outputLine("};");

        for (int i = 0; i < nestedLevels; ++i) {
            writer.decTabLevel();
            writer.outputLine("};");
        }

        writer.newLine(2);
        writer.outputLine("#endif");
        writer.flush();
        writer.close();
    }