no longer generate individual signalX.h file. now it's all in signal.h
* update generate.rb to generate one big file * remove signalX.h files (no longer generated, or used) * rename signal_template.h to signalx.h.tpl
This commit is contained in:
1 parent
6fd3ef36ab
commit
334d028e7b
20 files changed
+1606
-3782
No files matched your search
+87
-7
@@ -1,10 +1,49 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
##############################################################
|
||||
# script to generate signal*.h files from signal_template.h
|
||||
# script to generate signal.h files from signalx.h.tpl, etc. #
|
||||
##############################################################
|
||||
|
||||
def make_header_file(nargs)
|
||||
#
|
||||
# configuration
|
||||
#
|
||||
|
||||
# maximum size signal/slot (in parameters) to generate
|
||||
MaxParameters = 6
|
||||
|
||||
#
|
||||
# some templates
|
||||
#
|
||||
Header = <<ENDSTR
|
||||
#ifndef __signal_h__
|
||||
#define __signal_h__
|
||||
|
||||
#include "horrible_cast.h"
|
||||
#include "slot_base.h"
|
||||
#include "signal_base.h"
|
||||
|
||||
|
||||
/*
|
||||
* Begin signal[X] definitions
|
||||
*/
|
||||
|
||||
ENDSTR
|
||||
|
||||
Middle = <<ENDSTR
|
||||
/*
|
||||
* Begin signal template definitions and specilizations
|
||||
*/
|
||||
|
||||
ENDSTR
|
||||
|
||||
Footer = <<ENDSTR
|
||||
#endif // __signal_h__
|
||||
ENDSTR
|
||||
|
||||
#
|
||||
# make signalX, slotX, and associated definitions from template file
|
||||
#
|
||||
def make_signal(nargs)
|
||||
# hash to store our substitutions in
|
||||
subs = {}
|
||||
|
||||
@@ -16,15 +55,56 @@ def make_header_file(nargs)
|
||||
subs["===FORMAL_ARG==="] = nargs.times.map { |i| "a#{i}" }.join(", ")
|
||||
|
||||
# load template file
|
||||
text = IO.read("signal_template.h")
|
||||
text = IO.read("signalx.h.tpl")
|
||||
|
||||
# do substitutions
|
||||
subs.each { |k,v| text.gsub!(k,v) }
|
||||
|
||||
# write output file
|
||||
File.open("signal#{nargs}.h","w") { |f| f.write(text) }
|
||||
# return result
|
||||
text
|
||||
end
|
||||
|
||||
# generate [signal0.h,signal16.h]
|
||||
(0..16).each { |i| make_header_file(i) }
|
||||
#
|
||||
# make the template for signal, pointing it to signalX
|
||||
#
|
||||
def make_template(nargs)
|
||||
text = ""
|
||||
|
||||
nargs.downto(0).each do |i|
|
||||
if i == nargs
|
||||
text += "struct nilarg;\n\n"
|
||||
default_arg = "=nilarg"
|
||||
else
|
||||
default_arg = ""
|
||||
end
|
||||
template_params = ( ["typename T_return"] + i.times.map { |i| "typename T_arg#{i}#{default_arg}" } ).join(", ")
|
||||
template_args = ( ["T_return" ] + i.times.map { |i| "T_arg#{i}" } ).join(", ")
|
||||
|
||||
if i == nargs
|
||||
text += "// full template for signal<> (signal<> inherits signal#{i}<>)\n"
|
||||
else
|
||||
text += "// partial specialization for signal<> with #{i} parameters (signal<> inherits signal#{i}<>)\n"
|
||||
end
|
||||
|
||||
text += "template <#{template_params}>\n"
|
||||
if i == nargs
|
||||
text += "class signal: public signal#{i}<#{template_args} { /* empty class */ };\n"
|
||||
else
|
||||
text += "class signal<#{template_args}>: public signal#{i}<#{template_args}> { /* empty class */ };\n"
|
||||
end
|
||||
text += "\n"
|
||||
end
|
||||
text
|
||||
end
|
||||
|
||||
#
|
||||
# main program
|
||||
#
|
||||
File.open("signal.h","wt") do |f|
|
||||
f.puts Header
|
||||
(0..MaxParameters).each { |i| f.puts make_signal(i) }
|
||||
f.puts Middle
|
||||
f.puts make_template(MaxParameters)
|
||||
f.puts Footer
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user