On Fri, Jul 24, 2009 at 11:19:43AM +0800, ?????????
wrote:> Hi, I've got a problem while reading the xapian-core source code.
> I've begun from the include/xapian/base.h
Note that this isn't something you need to understand to use Xapian. So
the answers below are just for those interested in how Xapian is
implemented.
Most Xapian classes use the "PIMPL idiom", with a reference counted
internal object. Wikipedia has a reasonable page about PIMPL:
http://en.wikipedia.org/wiki/Opaque_pointer
> I found that in
> template <class T> RefCntPtr
> T must be RefCntBase or some type(possibly derived from RefCntBase I think)
> with a member called ref_count
At least for Xapian, T is derived from RefCntBase.
> But in include/xapian/database.h it declared class Database like below:
>
> 57 class XAPIAN_VISIBILITY_DEFAULT Database {
> 58 public:
> 59 class Internal;
> 60 /// @private @internal Reference counted internals.
> 61 std::vector<Xapian::Internal::RefCntPtr<Internal>
>
> internal;
> 62
> ...
> and similar for some other classes.
>
> I've searched the code but cannot find anything that describe/implement
> "class Internal" and I'm confused that how does class
Internal has a
> "ref_count" member and how does it work. Am I missed some
knowledge of c++?
The internal class is Database::Internal, and has a ref_count member
because it inherits from RefCntBase.
Cheers,
Olly