2 # Perl script by DWK to create a new .cpp/.h combination template
4 if(scalar(@ARGV) < 1) {
5 die "Usage: $0 <C++-name-of-class>\n" .
6 "\te.g. $0 Engine::TerrainCoordinate\n";
9 process_class
($ARGV[0]);
15 while($class =~ /([^:]+)::/g) {
16 $prefix .= lc($1) . '/';
22 print "Class prefix: \"$prefix\"\n";
23 create_cpp_file
($class, $prefix . ".cpp");
24 create_h_file
($class, $prefix . ".h");
30 open(FILE
, ">$file") or die;
33 print FILE
"#include \"$1.h\"\n";
35 print FILE open_namespaces
(generate_namespaces
($class));
37 print FILE close_namespaces
(generate_namespaces
($class));
45 open(FILE
, ">$file") or die;
48 $guard =~ s/([A-Z]+)/substr($1, 0, 1) . lc(substr($1, 1))/eg;
50 $guard =~ s/([A-Z])/'_' . lc($1)/eg;
52 print FILE
"#ifndef AESALON$guard" . "_H\n";
53 print FILE
"#define AESALON$guard" . "_H\n";
55 print FILE open_namespaces
(generate_namespaces
($class));
58 print FILE
"class $1 {\n";
59 print FILE
"public:\n";
62 print FILE close_namespaces
(generate_namespaces
($class));
64 print FILE
"#endif\n";
69 sub generate_namespaces
{
71 my @spaces = ('Aesalon');
73 while($class =~ /([^:]+)::/g) {
82 for my $namespace (@_) {
83 $return .= "namespace $namespace {\n";
89 sub close_namespaces
{
91 for my $namespace (reverse @_) {
92 $return .= "} // namespace $namespace\n";