diff options
Diffstat (limited to 'src/libs/3rdparty/syntax-highlighting/src/lib/state_p.h')
-rw-r--r-- | src/libs/3rdparty/syntax-highlighting/src/lib/state_p.h | 90 |
1 files changed, 53 insertions, 37 deletions
diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/state_p.h b/src/libs/3rdparty/syntax-highlighting/src/lib/state_p.h index a99192b4c6..9971f7f660 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/state_p.h +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/state_p.h @@ -1,57 +1,47 @@ /* - Copyright (C) 2016 Volker Krause <vkrause@kde.org> - Copyright (C) 2018 Christoph Cullmann <cullmann@kde.org> - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org> + SPDX-FileCopyrightText: 2018 Christoph Cullmann <cullmann@kde.org> + + SPDX-License-Identifier: MIT */ #ifndef KSYNTAXHIGHLIGHTING_STATE_P_H #define KSYNTAXHIGHLIGHTING_STATE_P_H +#include <vector> + #include <QSharedData> -#include <QVector> +#include <QStringList> #include "definitionref_p.h" -QT_BEGIN_NAMESPACE -class QStringList; -QT_END_NAMESPACE - namespace KSyntaxHighlighting { - class Context; class StateData : public QSharedData { friend class State; friend class AbstractHighlighter; + friend std::size_t qHash(const StateData &, std::size_t); public: StateData() = default; - static StateData* get(State &state); - bool isEmpty() const; - void clear(); - int size() const; - void push(Context *context, const QStringList &captures); + static StateData *reset(State &state); + static StateData *detach(State &state); + + static StateData *get(const State &state) + { + return state.d.data(); + } + + std::size_t size() const + { + return m_contextStack.size(); + } + + void push(Context *context, QStringList &&captures); /** * Pop the number of elements given from the top of the current stack. @@ -61,21 +51,47 @@ public: */ bool pop(int popCount); - Context* topContext() const; - const QStringList &topCaptures() const; + Context *topContext() const + { + return m_contextStack.back().context; + } + + const QStringList &topCaptures() const + { + return m_contextStack.back().captures; + } + + struct StackValue { + Context *context; + QStringList captures; + + bool operator==(const StackValue &other) const + { + return context == other.context && captures == other.captures; + } + }; private: /** - * weak reference to the used definition to filter out invalid states + * definition id to filter out invalid states */ - DefinitionRef m_defRef; + uint64_t m_defId = 0; /** * the context stack combines the active context + valid captures */ - QVector<QPair<Context *, QStringList>> m_contextStack; + std::vector<StackValue> m_contextStack; }; +inline std::size_t qHash(const StateData::StackValue &stackValue, std::size_t seed = 0) +{ + return qHashMulti(seed, stackValue.context, stackValue.captures); +} + +inline std::size_t qHash(const StateData &k, std::size_t seed = 0) +{ + return qHashMulti(seed, k.m_defId, qHashRange(k.m_contextStack.begin(), k.m_contextStack.end(), seed)); +} } #endif |