开发者

Getting shared_ptr refs to appear in doxygen collaboration diagrams

开发者 https://www.devze.com 2022-12-21 19:09 出处:网络
I\'ve done enough Googling to know that if I have something like class SubObject { public: //blah blah blah

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

namespa开发者_如何学编程ce 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?


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号