Created
March 12, 2011 00:32
-
-
Save jl2/866863 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##!/usr/bin/ruby | |
# Quick and dirty C++ inheritance tree using GraphViz's dot command | |
# Limitations: | |
# * Only handles single inheritance | |
# * Base classes must be specified on a single line: | |
# Such as "class Foo : public Bar" | |
require "find" | |
ofile = ARGV.shift | |
IO.popen("dot -Tsvg -o" + ofile, mode="w") do | dot | | |
dot.puts "digraph G {" | |
dot.puts "rankdir=BT;" | |
ARGV.each do | dir | | |
Find.find(dir) do | f | | |
Find.prune if f == "." | |
# puts "Processing \"" + f + "\"" | |
if f =~ /\.h$/ then | |
IO.foreach(f) do | ln | | |
if ln =~ /class *.* +(\w+)\s+:\s+public\s+(\w+)\s*$/ then | |
derived = $1 | |
base = $2 | |
dot.puts derived + " -> " + base + ";" | |
end | |
end | |
end | |
end | |
end | |
dot.puts "}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment