1 | /* |
2 | SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org> |
3 | |
4 | SPDX-License-Identifier: MIT |
5 | */ |
6 | |
7 | #ifndef KSYNTAXHIGHLIGHTING_DEFINITIONREF_P_H |
8 | #define KSYNTAXHIGHLIGHTING_DEFINITIONREF_P_H |
9 | |
10 | #include "definition.h" |
11 | |
12 | #include <memory> |
13 | |
14 | namespace KSyntaxHighlighting |
15 | { |
16 | class Definition; |
17 | class DefinitionData; |
18 | |
19 | /** Weak reference for Definition instances. |
20 | * |
21 | * This must be used when holding Definition instances |
22 | * in objects hold directly or indirectly by Definition |
23 | * to avoid reference count loops and thus memory leaks. |
24 | * |
25 | * This class follows the rule of zero. It is implicitly movable and copyable. |
26 | * |
27 | * @internal |
28 | */ |
29 | class DefinitionRef |
30 | { |
31 | public: |
32 | DefinitionRef(); |
33 | explicit DefinitionRef(const Definition &def); |
34 | explicit DefinitionRef(Definition &&def); |
35 | DefinitionRef &operator=(const Definition &def); |
36 | DefinitionRef &operator=(Definition &&def); |
37 | |
38 | Definition definition() const; |
39 | |
40 | /** |
41 | * Checks two definition references for equality. |
42 | */ |
43 | bool operator==(const DefinitionRef &other) const; |
44 | |
45 | /** |
46 | * Checks two definition references for inequality. |
47 | */ |
48 | bool operator!=(const DefinitionRef &other) const |
49 | { |
50 | return !(*this == other); |
51 | } |
52 | |
53 | /** |
54 | * Checks two definition for equality. |
55 | */ |
56 | bool operator==(const Definition &other) const; |
57 | |
58 | /** |
59 | * Checks two definition for inequality. |
60 | */ |
61 | bool operator!=(const Definition &other) const |
62 | { |
63 | return !(*this == other); |
64 | } |
65 | |
66 | private: |
67 | friend class DefinitionData; |
68 | std::weak_ptr<DefinitionData> d; |
69 | }; |
70 | |
71 | } |
72 | |
73 | #endif |
74 | |