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
14namespace KSyntaxHighlighting
15{
16class Definition;
17class 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 */
29class DefinitionRef
30{
31public:
32 DefinitionRef();
33 explicit DefinitionRef(const Definition &def) noexcept;
34 DefinitionRef &operator=(const Definition &def) noexcept;
35
36 Definition definition() const;
37
38 /**
39 * Checks two definition references for equality.
40 */
41 bool operator==(const DefinitionRef &other) const;
42
43 /**
44 * Checks two definition references for inequality.
45 */
46 bool operator!=(const DefinitionRef &other) const
47 {
48 return !(*this == other);
49 }
50
51 /**
52 * Checks two definition for equality.
53 */
54 bool operator==(const Definition &other) const;
55
56 /**
57 * Checks two definition for inequality.
58 */
59 bool operator!=(const Definition &other) const
60 {
61 return !(*this == other);
62 }
63
64private:
65 friend class DefinitionData;
66 std::weak_ptr<DefinitionData> d;
67};
68
69}
70
71#endif
72

source code of syntax-highlighting/src/lib/definitionref_p.h