swift
Loading...
Searching...
No Matches
propertyindexref.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
7
8#include <QtGlobal>
9
10#include "misc/verify.h"
11
12namespace swift::misc
13{
14 CPropertyIndexRef::CPropertyIndexRef(int index) : m_sizeOrIndex(index) {}
15
17 : m_begin(indexes.data()), m_sizeOrIndex(indexes.size())
18 {}
19
21 {
22 SWIFT_VERIFY_X(!this->isEmpty(), Q_FUNC_INFO, "Empty index");
23 if (this->isEmpty() || !m_begin)
24 {
25 return -1;
26 }
27 CPropertyIndexRef copy = *this;
28 ++copy.m_begin;
29 --copy.m_sizeOrIndex;
30 return copy;
31 }
32
33 bool CPropertyIndexRef::isNested() const { return m_begin && m_sizeOrIndex > 1; }
34
35 bool CPropertyIndexRef::isMyself() const { return this->isEmpty(); }
36
37 bool CPropertyIndexRef::isEmpty() const { return m_begin ? m_sizeOrIndex < 1 : m_sizeOrIndex < 0; }
38
40 {
41 Q_ASSERT_X(!this->isEmpty(), Q_FUNC_INFO, "No index");
42 return m_begin ? *m_begin : m_sizeOrIndex;
43 }
44
45 bool CPropertyIndexRef::startsWith(int index) const
46 {
47 if (this->isEmpty())
48 {
49 return false;
50 }
51 return this->frontToInt() == index;
52 }
53
55 {
56 Q_UNUSED(i18n);
57 QString s;
58 if (this->isEmpty())
59 {
60 return s;
61 }
62
63 auto it = m_begin ? m_begin : &m_sizeOrIndex;
64 auto end = it + (m_begin ? m_sizeOrIndex : 1);
65 for (; it != end; ++it)
66 {
67 Q_ASSERT(*it >= static_cast<int>(CPropertyIndexRef::GlobalIndexCValueObject));
68 if (!s.isEmpty())
69 {
70 s.append(";");
71 }
72 s.append(QString::number(*it));
73 }
74 return s;
75 }
76} // namespace swift::misc
bool startsWith(int index) const
Starts with given index?
int frontToInt() const
Front to integer.
Q_REQUIRED_RESULT CPropertyIndexRef copyFrontRemoved() const
Copy with first element removed.
bool isNested() const
Is nested index?
CPropertyIndexRef(int index)
Construct from a single index.
QString toQString(bool i18n=false) const
Cast as QString.
bool isMyself() const
Myself index, used with nesting.
Free functions in swift::misc.
T::const_iterator end(const LockFreeReader< T > &reader)
Non-member begin() and end() for so LockFree containers can be used in ranged for loops.
Definition lockfree.h:264
QString & append(QChar ch)
bool isEmpty() const const
QString number(double n, char format, int precision)
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.
Definition verify.h:26