File indexing completed on 2024-05-12 15:50:04
0001 /* 0002 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #ifndef KSYNTAXHIGHLIGHTING_DEFINITIONREF_P_H 0008 #define KSYNTAXHIGHLIGHTING_DEFINITIONREF_P_H 0009 0010 #include "definition.h" 0011 0012 #include <memory> 0013 0014 namespace KSyntaxHighlighting 0015 { 0016 class Definition; 0017 class DefinitionData; 0018 0019 /** Weak reference for Definition instances. 0020 * 0021 * This must be used when holding Definition instances 0022 * in objects hold directly or indirectly by Definition 0023 * to avoid reference count loops and thus memory leaks. 0024 * 0025 * This class follows the rule of zero. It is implicitly movable and copyable. 0026 * 0027 * @internal 0028 */ 0029 class DefinitionRef 0030 { 0031 public: 0032 DefinitionRef(); 0033 explicit DefinitionRef(const Definition &def); 0034 explicit DefinitionRef(Definition &&def); 0035 DefinitionRef &operator=(const Definition &def); 0036 DefinitionRef &operator=(Definition &&def); 0037 0038 Definition definition() const; 0039 0040 /** 0041 * Checks two definition references for equality. 0042 */ 0043 bool operator==(const DefinitionRef &other) const; 0044 0045 /** 0046 * Checks two definition references for inequality. 0047 */ 0048 bool operator!=(const DefinitionRef &other) const 0049 { 0050 return !(*this == other); 0051 } 0052 0053 /** 0054 * Checks two definition for equality. 0055 */ 0056 bool operator==(const Definition &other) const; 0057 0058 /** 0059 * Checks two definition for inequality. 0060 */ 0061 bool operator!=(const Definition &other) const 0062 { 0063 return !(*this == other); 0064 } 0065 0066 private: 0067 friend class DefinitionData; 0068 std::weak_ptr<DefinitionData> d; 0069 }; 0070 0071 } 0072 0073 #endif