Skip to content

Commit

Permalink
Documentation|libdeng2: Pimpl macros
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Mar 6, 2013
1 parent b3aeb0e commit ffb9e81
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions doomsday/libdeng2/include/de/libdeng2.h
Expand Up @@ -220,7 +220,11 @@
private: ClassName(ClassName const &);

/**
* Macro for starting the definition of a private implementation struct. Example:
* Macro for starting the definition of a private implementation struct. The
* struct holds a reference to the public instance, which must be specified in
* the call to the base class constructor. @see de::Private
*
* Example:
* <pre>
* DENG2_PIMPL(MyClass)
* {
Expand All @@ -235,11 +239,18 @@
typedef ClassName Public; \
struct ClassName::Instance : public de::Private<ClassName>

/**
* Macro for starting the definition of a private implementation struct without
* a reference to the public instance. This is useful for simpler classes where
* the private implementation mostly holds member variables.
*/
#define DENG2_PIMPL_NOREF(ClassName) \
struct ClassName::Instance : public de::IPrivate

/**
* Macro for publicly declaring a pointer to the private implementation.
* de::PrivateAutoPtr owns the private instance and will automatically delete
* it when the PrivateAutoPtr is destroyed.
*/
#define DENG2_PRIVATE(Var) \
struct Instance; \
Expand All @@ -258,7 +269,7 @@ struct IPrivate {
#ifdef DENG2_DEBUG
unsigned int _privateInstVerification;
IPrivate() : _privateInstVerification(0xdeadbeef) {}
unsigned int specialVerification() const { return _privateInstVerification; }
unsigned int privateInstVerification() const { return _privateInstVerification; }
#endif
};

Expand All @@ -283,7 +294,7 @@ class PrivateAutoPtr
IPrivate *ip = reinterpret_cast<IPrivate *>(ptr);
if(ip)
{
DENG2_ASSERT(ip->specialVerification() == 0xdeadbeef);
DENG2_ASSERT(ip->privateInstVerification() == 0xdeadbeef);
delete ip;
}
ptr = p;
Expand Down

0 comments on commit ffb9e81

Please sign in to comment.