Understanding C++ codebase with UML-tools
I am trying to understand a C++ codebase. I have used some free tools that will scan the code and produce diagrams, but they are not开发者_如何学Python so easy to understand.
What I think would be useful is to manually construct something assisted by the UML tool.
What i need is to create something that looks like the data structure at run-time. Ideally by pulling objects from the UML and arranging them. Also I would like to organise the classes in sub-packages - like those close to the DB, or towards the branches of the datastructures.
(I am partly doing this now with Folders in the Visual Studio Solution explorer)
This is a LINUX project with many Makesfiles, but many tools like Visual Studio, "understands" the code when I just create projects with the files in the main directory of the exe I am working on
Most tools will only give you a structural view (classes and packages), which honestly doesn't tell you that much of what goes on in runtime.
Enterprise Architect from Sparx Systems incorporates a Visual Execution Analyzer, which can generate sequence diagrams from a debug session. It supports C++ but only on Windows so you'd have to rebuild, but if I understand you correctly you've already got your code running in Visual Studio.
Here's a brief demo (in this case the code is in C#, but they do claim to support C++ as well). This isn't a full-roundtrip, write-the-code-in-UML kind of thing, but personally I think that's a pipe dream anyway. Use UML to document, use a programming language to code.
Honestly, you might have substantial problems getting anything useful out of a UML tool with regard to reverse generating code.
If the code is unusually clean and had a decent OO design, good containment, inheritance, and few associations theres a chance that it might look alright... but with most real projects, when you reverse generate into UML, the resulting diagrams are a spidery mess that will probably do more harm than good.
If you are going to stick with the reverse-model genreation though, try and configure the UML utility to show less items - keep it to the key relationships like aggregation and inheritance. When you start showing uses relationships rather than contains/aggregation relationships then everything tends to connect to everything unless the project was very well written, and that will just lead to more confusion and micsonceptions.
My best recommendation would be - if the tool makes it look incomprehensible, save yourself some time and do it yourself.
UML and C++ code that wasn't generated from UML don't play together that nicely. Especially as soon as templates are involved you might get into more trouble then you would actually like and you need to ask yourself if the time spent into getting those models isn't actually better invested in good old-fashioned source code reading. You will have to read the code eventually to understand what it does so just get started now.
Didn't understand if it's linux or windows (you say linux, but then say you're using visual studio).
If you want to understand the code, Source Insight is a good tool for that. Not necessarily UMLs, but produces nice graphs in real time.
精彩评论