Defines

dptr_base.h File Reference

Go to the source code of this file.

Defines

#define DPTR_CLASS_NAME(Class)   Class::Private
 Expands to the fully qualified name of the d-pointer class.
#define DPTR_NAME   Private
 Expands to the local name of d-pointer classes (Private).
#define DPTR_WRAPPER_NAME   DPrivate
 Expands to the local name of the d-pointer wrapper class (DPrivate).
#define DECLARE_DPTR(dp)
 Declares a smart non-shared d-pointer, to be used inside class declaration.
#define DECLARE_SHARED_DPTR(dp)
 Declares a smart shared d-pointer, to be used inside class declaration.
#define DECLARE_NONCOPY_DPTR(dp)
 Declares a smart non-shared and non-copyable d-pointer, to be used inside class declaration.

Define Documentation

#define DECLARE_DPTR (   dp  ) 
Value:
private:\
 class Private; \
 class DPrivate{\
  public:DPrivate();DPrivate(const DPrivate&);~DPrivate();\
  DPrivate&operator=(const DPrivate&);\
  const Private*operator->()const{return d;}\
  Private*operator->(){return d;}\
  DPrivate clone()const;\
  private:Private*d;\
 }; \
 DPrivate dp;

Declares a smart non-shared d-pointer, to be used inside class declaration.

It also declares the internal nested classes DPrivate and Private - Private is the actual d-pointer class, while DPrivate is a wrapper that automatically allocates, copies and deallocates the d-pointer.

The wrapper DPointer class contains these methods:

  • constructor, copy constructor for creating instances of Private
    • used by automatic and explicit constructors of the containing class
  • destructor for deallocation of Private
    • used by the destructor of the containing class
  • assignment operator to copy the content of Private
    • used by the assignment operator of the containing class
  • pointer operator to actually access the Private data

You can use DEFINE_DPTR to define the necessary methods for a non-shared d-pointer. It is recommended (but not necessary) that non-shared d-pointer classes (Private) are derived from DPtr.

The d-pointer class Private is only forward declared, you have to fully declare and implement it in the code where you are using it, i.e. where you are implementing the containing class.

Parameters:
dp name of the d-pointer
#define DECLARE_NONCOPY_DPTR (   dp  ) 
Value:
private:\
 class Private; \
 class DPrivate{\
  public:DPrivate();~DPrivate();\
  const Private*operator->()const{return d;}\
  Private*operator->(){return d;}\
  private:Private*d;\
  DPrivate(const DPrivate&);DPrivate&operator=(const DPrivate&);\
 }; \
 DPrivate dp;

Declares a smart non-shared and non-copyable d-pointer, to be used inside class declaration.

It also declares the internal nested classes DPrivate and Private - Private is the actual d-pointer class, while DPrivate is a wrapper that automatically allocates, and deallocates the d-pointer. These are usable for content classes that do not allow copying (e.g. Qt's QObject and its subclasses).

The wrapper DPointer class contains these methods:

  • constructor for creating instances of Private
    • used by automatic and explicit constructors of the containing class
  • destructor for deallocation of Private
    • used by the destructor of the containing class
  • private assignment operator and copy constructor
    • effectively hiding and blocking them
  • pointer operator to actually access the Private data

You can use DEFINE_NONCOPY_DPTR to define the necessary methods for a non-shared, non-copy d-pointer. It is recommended that d-pointer classes (Private) are derived from NonCopyDPtr.

The d-pointer class Private is only forward declared, you have to fully declare and implement it in the code where you are using it, i.e. where you are implementing the containing class.

Parameters:
dp name of the d-pointer
#define DECLARE_SHARED_DPTR (   dp  ) 
Value:
private:\
 class Private; \
 class DPrivate{\
  public:DPrivate();DPrivate(const DPrivate&);~DPrivate();\
  DPrivate&operator=(const DPrivate&);\
  const Private*operator->()const{return d;}\
  Private*operator->(){return d;}\
  DPrivate clone()const;\
  void decouple();\
  private:Private*d;\
 }; \
 DPrivate dp;

Declares a smart shared d-pointer, to be used inside class declaration.

It also declares the internal nested classes DPrivate and Private - Private is the actual d-pointer class, while DPrivate is a wrapper that automatically allocates, copies and deallocates the d-pointer.

The wrapper DPointer class contains these methods:

  • constructor, copy constructor for creating instances of Private
    • used by automatic and explicit constructors of the containing class
  • destructor for deallocation of Private
    • used by the destructor of the containing class
  • assignment operator to copy the content of Private
    • used by the assignment operator of the containing class
  • pointer operator to actually access the Private data

You can use DEFINE_DPTR to define the necessary methods for a non-shared d-pointer or DEFINE_SHARED_DPTR if you want to share d-pointer data between instances of the containing class. It is recommended that non-shared d-pointer classes (Private) are derived from DPtr and the shared variants be derived from SharedDPtr.

The d-pointer class Private is only forward declared, you have to fully declare and implement it in the code where you are using it, i.e. where you are implementing the containing class.

Warning: shared d-pointers are not thread safe and they are only re-entrant if instances sharing the same d-pointer are only located in one thread, while instances with different d-pointers may be spread over different threads.

Parameters:
dp name of the d-pointer
#define DPTR_CLASS_NAME (   Class  )     Class::Private

Expands to the fully qualified name of the d-pointer class.

Parameters:
Class the fully qualified name of the class the d-pointer was declared in.
#define DPTR_NAME   Private

Expands to the local name of d-pointer classes (Private).

#define DPTR_WRAPPER_NAME   DPrivate

Expands to the local name of the d-pointer wrapper class (DPrivate).

 All Classes Files Functions Variables Defines