template based d pointer class
Luis Pedro Coelho
luis_pedro at netcabo.pt
Sat May 17 21:25:22 BST 2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Le Samedi 17 Mai 2003 21:35, Ravikiran Rajagopal a écrit :
> This seems like a fairly complicated way to store extra data members. As
It seems to me to be the same. It is, of course, a hack, but it is probably
needed if there is no d-ptr. For that situation, it's probably a good
solution.
> One simpler(?) solution would be to define a generic singleton pattern
> template class [1] that would be usable much more widely in KDE. Then,
I don't know Loki [1-mine]. I can more or less guess what you are hinting at,
though. And I think that it isn't needed here, so we might as well just solve
this one problem. Maybe a generic singleton would be nice to deal with all
the problems dumb singletons can have when you dlopen/dlcose them, for
example.
> A nitpick: instead of the #define, it would be better to add a private
> const member function.
non-const flavour as well, probably. This should be binary compatible (adding
inline private functions is binary compatible, no?).
> See http://www.gotw.ca/gotw/012.htm for a similarly flavored example.
I cannot see the connection, sorry.
> Anyway, are there any classes with publicly available API without
> d-pointers?
I think this was about a concrete problem Alex is dealing with..
Overall, I think that the code that Alex posted is a clever solution to the
problem in a "this is an ugly hack but we cannot break binary compatibility"
sort of way. I agree with you on the private inline members, though.
Also, I would say one should do (marked changes with "*********") to get rid
of explicit references to the implementation:
class KBookmarkBarPrivate : public Private<KBookmarkBar, KBookmarkBarPrivate>
{
public:
QPtrList<KAction> m_actions;
};
*****
KBookmarkBarPrivate::neededType KBookmarkBarPrivate::base::d_ptr = 0;
*****
IMPLEMENTATION: (most code from seli's developer.kde.org page on bic)
- ---------------
template<class KBookmarkBar, class KBookmarkBarPrivate>
class Private {
public:
*******
typedef Private<KBookmarkBar,KBookmarBarPrivate> base;
typedef QPtrDict<KBookmarkBar,KBookmarkBarPrivate>* neededType;
*******
private:
static neededType d_ptr;
};
- --------------------
The overall idea looks fine, though. Don't forget to leave a comment saying
how this all should go away for KDE 4.
[1-mine]: If you have a copy of "Modern C++ Design" you want to sell cheaply
in Vienna, tell me ;-)
Regards,
- --
Luis Pedro Coelho
"Technology does not always equal progress."
Douglas Coupland
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE+xpq6GpBAvyRwXdgRAvo1AJ9pzW7UVMXiusUDW4X3jl5ocEUz8wCfSmW9
jdwmAMxVK51Bi7DxCky0P6Q=
=oERQ
-----END PGP SIGNATURE-----
More information about the kde-core-devel
mailing list