import items.*;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
public class CHeader {
public CHeader
(String filename
)
{
this.filename = filename;
}
public void build(Database db)
{
System.
out.
println("Trying to rebuild " +
this.
filename);
try
{
String formattedDate = formatter.
format(new Date());
out.write("// Built on " + formattedDate + " by CanIdManager\n");
out.write("\n");
this.outputClasses(out, db);
this.outputCommands(out, db);
this.outputModules(out, db);
out.close();
System.
out.
println("You will now need to recompile all you modules and applications ;)");
}
{
System.
err.
println("Failed to write " +
this.
filename);
System.
err.
println("Error: " + e.
getMessage());
}
}
{
out.write("//------------------ //\n");
out.write("// Class definitions //\n");
out.write("//------------------ //\n");
ArrayList<CanClass
> classes = db.
getClasses();
Iterator<CanClass
> iterator = classes.
iterator();
while (iterator.hasNext())
{
CanClass canClass = iterator.next();
out.write("#define " + canClass.getCDefineName() + "\t= " + canClass.getId() + " // " + canClass.getDescription() + "\n");
}
out.write("\n");
}
{
out.write("//-------------------- //\n");
out.write("// Command definitions //\n");
out.write("//-------------------- //\n");
ArrayList<Command
> commands = db.
getCommands();
Iterator<Command
> iterator = commands.
iterator();
while (iterator.hasNext())
{
Command command = iterator.next();
out.write("#define " + command.getCDefineName() + "\t= " + command.getId() + " // " + command.getDescription() + "\n");
}
out.write("\n");
}
{
out.write("//------------------- //\n");
out.write("// Module definitions //\n");
out.write("//------------------- //\n");
Iterator<Module
> iterator = modules.
iterator();
while (iterator.hasNext())
{
Module module = iterator.next();
out.write("#define " + module.getCDefineName() + "\t= " + module.getId() + " // " + module.getDescription() + "\n");
}
out.write("\n");
}
}