Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class hierarchy/dependency diagram generator for C++ in Linux

Tags:

c++

linux

class

Is there some tool to generate class hierarchy/dependency diagrams by inspecting C++ code in Linux?

I have this big collection of C++ files given to me and such a tool would be invaluable to help me understand the source code. I am getting a little tangled up in understanding it.

like image 225
smilingbuddha Avatar asked Dec 14 '11 17:12

smilingbuddha


1 Answers

Try doxygen. It may also be shipped with your distribution.

You may need GraphViz to generate the graphs. There is a simple example and output.

And this is a more complicated example from the legend file generated by doxygen:

Code (NOTE: if you only want to generate the graphs, the comments are not required.):

/*! Invisible class because of truncation */
class Invisible { };

/*! Truncated class, inheritance relation is hidden */
class Truncated : public Invisible { };

/* Class not documented with doxygen comments */
class Undocumented { };

/*! Class that is inherited using public inheritance */
class PublicBase : public Truncated { };

/*! A template class */
template<class T> class Templ { };

/*! Class that is inherited using protected inheritance */
class ProtectedBase { };

/*! Class that is inherited using private inheritance */
class PrivateBase { };

/*! Class that is used by the Inherited class */
class Used { };

/*! Super class that inherits a number of other classes */
class Inherited : public PublicBase,
                  protected ProtectedBase,
                  private PrivateBase,
                  public Undocumented,
                  public Templ<int>
{
  private:
    Used *m_usedClass;
};

Result:

enter image description here

You do not need to comment your code to generate these graphs. The first example has no comments at all. The second example has one class without doxygen style comment. Just set the appropriate parameter (at least EXTRACT_ALL = YES should be set. I cannot recall whether this is all that is needed).

like image 53
fefe Avatar answered Oct 21 '22 17:10

fefe