tags:

views:

75

answers:

3

I need various UML diagrams (sequence/collaboration, class, package, and system component) from some C++ files. However, these files are plugins in a larger programming framework. I have tried generating UML from Rational Rose 7 (2002 version), but I am not very experienced and I am unsure if RR simply cannot produce the diagram, I am doing something wrong, or the diagrams are not rendering correctly because the source files are plugins instead of standalone programs. I have also tried Star Modeler with little success and there seem to be no tutorials on how to generate these models.

Is there a simple, bulletproof way to get UML diagrams for C++ files?

A: 

I know this isn't answering the question, but you can mock something up with graphviz dot. To motivate, here's a Ruby script that generates a dot script, which itself can be used to generate an image that expresses header dependencies:

puts "digraph {"
ARGV.each_index do |i|
  File.open ARGV[i] do |f|
    while line = f.gets
      if line =~ /^#\s*include\s*[<"](.*)[>"]/
        puts "  \"#{File.basename ARGV[i]}\"->\"#{$1}\";"
      end
    end
  end
end
puts "}"

If the script is named headers.rb and you're using Bash for your shell then You can use it like so:

ruby headers.rb *.cc |dot -Tpng >header_deps.png

That will result in a png image of the header dependencies. You could do similar stuff with class inheritance. You might take advantage of ctags for more complex scenarios.

End result? You re-invented the wheel and had fun doing so. :p

wilhelmtell
This is a little helpful, but I need those formal UML diagrams, not a mockup.
Can anyone help me? Even something that only does class diagrams, or a tutorial on how to use a program to get what I need, would be very useful!
A: 

If you're a Windows user, you could try StarUML. Though as the discussion here says, the project seems to be dead, the program runs just fine on my Windows 7 machine.

I've found that StarUML can produce a good class diagram of the classes and their inheritance relationships in a set of C++ source-code files. However, I haven't been able to get it to produce any association links between the classes. I'm still learning StarUML, so I might be doing something wrong there.

Also, I don't think it can reverse engineer anything but class diagrams, but it might be a start for you.

Gordon Brandly
+1  A: 

Most UML tools only support a subset of C++. Any UML tool which does not include a C preprocessor will miss a substantial amount of information, and because of C++ complexity is is very easy to confuse them.

The primary use case of reverse engineering in UML tools is round-trip engineering - first create the UML model, then generate code, then tweak it a little but not too much, then import the changes again.

It is also worth noting that there are many, many constructs in C++ which simply do not have any direct representation in UML. C++ is a multi-paradigm language; UML is an OO modelling language. There are many C++ idioms which map to the same UML constructs (is a composite an auto_ptr or a value? Is a std::vector<int> member variable an association to a parametrized class, or a property of type int[0..*] )

So the short answer is no, there is no simple, bulletproof way to get UML diagrams from C++.

Pete Kirkham