1 /* |
|
2 * LDForge: LDraw parts authoring CAD |
|
3 * Copyright (C) 2013, 2014 Santeri Piippo |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation, either version 3 of the License, or |
|
8 * (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 */ |
|
18 |
|
19 #pragma once |
|
20 |
|
21 #include "../main.h" |
|
22 |
|
23 class LDSubfile; |
|
24 class LDDocument; |
|
25 |
|
26 //! |
|
27 //! \brief A reference-counting pointer to LDDocument. |
|
28 //! |
|
29 //! The LDDocumentPointer class defines a reference-counting pointer which |
|
30 //! points to LDDocument. |
|
31 //! |
|
32 class LDDocumentPointer |
|
33 { |
|
34 PROPERTY (private, LDDocument*, pointer, setPointer, STOCK_WRITE) |
|
35 |
|
36 public: |
|
37 //! Constructs a null LDDocumentPointer |
|
38 LDDocumentPointer(); |
|
39 |
|
40 //! Constructs a document pointer with the given pointer |
|
41 LDDocumentPointer (LDDocument* ptr); |
|
42 |
|
43 //! Copy-constructs a LDDocumentPointer. |
|
44 LDDocumentPointer (const LDDocumentPointer& other); |
|
45 |
|
46 //! Destructs the pointer. |
|
47 ~LDDocumentPointer(); |
|
48 |
|
49 //! \param ptr the new pointer to change to. |
|
50 LDDocumentPointer& operator= (LDDocument* ptr); |
|
51 |
|
52 //! Copy operator. |
|
53 //! \param other the pointer whose internal pointer to copy. |
|
54 inline LDDocumentPointer& operator= (LDDocumentPointer& other) |
|
55 { |
|
56 return operator= (other.pointer()); |
|
57 } |
|
58 |
|
59 //! Operator overload for a->b support. |
|
60 inline LDDocument* operator->() const |
|
61 { |
|
62 return pointer(); |
|
63 } |
|
64 |
|
65 //! Cast operator overload |
|
66 inline operator LDDocument*() const |
|
67 { |
|
68 return pointer(); |
|
69 } |
|
70 |
|
71 private: |
|
72 void addReference(); |
|
73 void removeReference(); |
|
74 }; |
|