3 // (c) Konrad Rosenbaum, 2010-2011
4 // Copying and distribution of this file, with or without modification,
5 // are permitted in any medium without royalty provided the copyright
6 // notice and this notice are preserved. This file is offered as-is,
7 // without any warranty.
10 #ifdef DPTR_CLASS_NAME
11 #undef DPTR_CLASS_NAME
18 #ifdef DPTR_WRAPPER_NAME
19 #undef DPTR_WRAPPER_NAME
22 /** \def DPTR_CLASS_NAME(Class)
23 \brief Expands to the fully qualified name of the d-pointer class.
24 \param Class the fully qualified name of the class the d-pointer was declared in.*/
25 #define DPTR_CLASS_NAME(Class) Class::Private
28 \brief Expands to the local name of d-pointer classes (Private).
30 #define DPTR_NAME Private
32 /** \def DPTR_WRAPPER_NAME
33 Expands to the local name of the d-pointer wrapper class (DPrivate).
35 #define DPTR_WRAPPER_NAME DPrivate
41 /** \def DECLARE_DPTR(dp)
42 \brief Declares a smart non-shared d-pointer, to be used inside class declaration.
44 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.
46 The wrapper DPointer class contains these methods:
47 - constructor, copy constructor for creating instances of Private
48 - used by automatic and explicit constructors of the containing class
49 - destructor for deallocation of Private
50 - used by the destructor of the containing class
51 - assignment operator to copy the content of Private
52 - used by the assignment operator of the containing class
53 - pointer operator to actually access the Private data
55 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.
57 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.
59 \param dp name of the d-pointer*/
60 #define DECLARE_DPTR(dp) \
64 public:DPrivate();DPrivate(const DPrivate&);~DPrivate();\
65 DPrivate&operator=(const DPrivate&);\
66 const Private*operator->()const{return d;}\
67 Private*operator->(){return d;}\
68 DPrivate clone()const;\
73 #ifdef DECLARE_SHARED_DPTR
74 #undef DECLARE_SHARED_DPTR
77 /** \brief Declares a smart shared d-pointer, to be used inside class declaration.
79 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.
81 The wrapper DPointer class contains these methods:
82 - constructor, copy constructor for creating instances of Private
83 - used by automatic and explicit constructors of the containing class
84 - destructor for deallocation of Private
85 - used by the destructor of the containing class
86 - assignment operator to copy the content of Private
87 - used by the assignment operator of the containing class
88 - pointer operator to actually access the Private data
90 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.
92 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.
94 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.
96 \param dp name of the d-pointer*/
97 #define DECLARE_SHARED_DPTR(dp) DECLARE_DPTR(dp)
100 #ifdef DECLARE_NONCOPY_DPTR
101 #undef DECLARE_NONCOPY_DPTR
104 /** \brief Declares a smart non-shared and non-copyable d-pointer, to be used inside class declaration.
106 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).
108 The wrapper DPointer class contains these methods:
109 - constructor for creating instances of Private
110 - used by automatic and explicit constructors of the containing class
111 - destructor for deallocation of Private
112 - used by the destructor of the containing class
113 - private assignment operator and copy constructor
114 - effectively hiding and blocking them
115 - pointer operator to actually access the Private data
117 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.
119 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.
121 \param dp name of the d-pointer*/
122 #define DECLARE_NONCOPY_DPTR(dp) \
126 public:DPrivate();~DPrivate();\
127 const Private*operator->()const{return d;}\
128 Private*operator->(){return d;}\
130 DPrivate(const DPrivate&);DPrivate&operator=(const DPrivate&);\