add ignore pattern for git
[web/konrad/chester.git] / dptr.h
1 //d-ptr header
2 //
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.
8
9 #include "dptr_base.h"
10
11
12 #ifndef DPTR_CLASS_0_1_H
13 #define DPTR_CLASS_0_1_H
14
15 //hide the namespace
16 /// \cond never
17 namespace Chester_0_1{
18 /// \endcond
19
20 /** \brief Base class of non-shared d-pointers.
21
22 Use in conjunction with DECLARE_DPTR and DEFINE_DPTR */
23 class DPtr
24 {
25         public:
26                 ///instantiates a non-shared d-pointer
27                 DPtr(){}
28                 ///deletes a non-shared d-pointer
29                 virtual ~DPtr(){}
30 };
31
32 //hide the namespace
33 /// \cond never
34 };
35 using namespace Chester_0_1;
36 /// \endcond
37 #endif
38
39 #ifdef DEFINE_DPTR
40 #undef DEFINE_DPTR
41 #endif
42
43 /** \brief Creates definitions for methods of the non-shared d-pointer wrapper. 
44
45 This variant is not shared between instances of the containing class, but it is able to copy its content (using the contents copy constructor and assignment operator). You cannot use this variant if any of the content classes have inaccessable copy constructors or assignment operators (like Qt's QObject and its subclasses).
46
47 To be used in implementation where the actual d-pointer class is implemented.
48
49 \param Class the base class within which the d-pointer was declared*/
50 #define DEFINE_DPTR(Class) \
51  Class::DPrivate::DPrivate(){d=new Class::Private;}\
52  Class::DPrivate::DPrivate(const Class::DPrivate&dp){d=new Class::Private(*(dp.d));}\
53  Class::DPrivate::~DPrivate(){delete d;}\
54  Class::DPrivate Class::DPrivate::clone()const{DPrivate r;*(r.d)=*d;return r;}\
55  Class::DPrivate& Class::DPrivate::operator=(const Class::DPrivate&dp)\
56  {if(d!=dp.d)*d=*(dp.d);return *this;}
57