16

I've done enough Googling to know that if I have something like

class SubObject {

public:
//blah blah blah
};

class Aggregate {
public:
   boost::shared_ptr<SubObject>   m_ptr;
};

I can get Doxygen to create the "correct" collaboration diagram if I have a dummy declaration like

namespace boost { template<class T> class shared_ptr { T *dummy; }; }

in my header file.

My question is: how do I get that to work over all my projects and all my headers, without having to actually include that line in every file?

Eric H.
  • 2,566
  • 2
  • 23
  • 34

3 Answers3

12

Heh.... I feel stupid answering my own questions, but I figure this one out pretty much right after posting it:

Put the code snippet

namespace boost { template<class T> class shared_ptr { T *dummy; }; }

in a header file, called something like "doxygen_dummy.h", and make sure it's included in your project's workspace or directory. You don't need to actually #include it anywhere (in fact, you don't want to, to avoid violating the One Definition Rule). You just need for Doxygen to be able to see it when it scans all your files.

Eric H.
  • 2,566
  • 2
  • 23
  • 34
10

Thanks Eric, that worked. However I didn't like the extra dummy classes expanding my collaboration diagrams so brewed on this a little more. This Doxyfile setting changes all the boost::smart_ptr code to T*. This bypasses the smart_ptr and creates a direct link to the type in the collaboration diagram.

INPUT_FILTER = "sed 's/boost::shared_ptr<\(.*\)>/\1*/'"

This is probably not what you want for final docs since it really does hide all references to smart_ptr as plain pointer but the collaboration diagrams become much more readable.

MattiasF
  • 1,273
  • 1
  • 12
  • 15
  • 1
    I like this solution -- I'm currently only using doxygen for internal documentation and visualization of my SW design, so having a dummy header is cumbersome, especially if you frequently `git clean` the workspace. – arne May 30 '13 at 08:29
  • 1
    With the sed solution it's going to be difficult to get the s/// expressions to be right in all cases. Consider boost::shared_ptr >, for example. But you can easily add shared_ptr and vector (and whatever other library template classes you're using) to your doxygen_dummy.h. – Waxrat Dec 19 '13 at 16:22
3

The question may be out dated but I tried MattiasF's solution which where not perfect (I'm not blaming).

IMO, uses a doxygen_dummy header in not a proper solution for shared_ptr. The shared_ptr class is a memory management purpose only and is surely not needed in Doxygen documentation.

At work, I use an INPUT_FILTER with sed. I find a good pattern (mem:: is an namespace alias) :

INPUT_FILTER = "sed -e \"s/mem::shared_ptr<\([a-zA-Z0-9_]*\)> /\1* /g\" -e \"s/mem::shared_ptr<\(.*\)> /\1* /g\""

The first pattern matches all shared_ptr with simple templates, meaning a type with no template. The second pattern matches all other shared_ptr whatever templates are complex type (with template).

I found a drawback : full-qualified name as template, which includes '::', are not handled yet. The solution, I've not done yet, is to add a "character" :: in the first sed's pattern.

Germain D.
  • 173
  • 8