8#include <QtCore/qhash.h>
13template <
class Key,
class T>
20 Value()
noexcept =
default;
21 Value(T *tt, qsizetype c)
noexcept
24 Value(Value &&other)
noexcept
30 Value &operator=(Value &&other)
noexcept
32 qt_ptr_swap(t, other.t);
33 std::swap(cost, other.cost);
36 ~Value() {
delete t; }
44 Chain()
noexcept : prev(
this), next(
this) { }
49 struct Node :
public Chain
52 using ValueType = Value;
57 Node(
const Key &k, Value &&t)
noexcept(std::is_nothrow_move_assignable_v<Key>)
63 Node(Key &&k, Value &&t)
noexcept(std::is_nothrow_move_assignable_v<Key>)
69 static void createInPlace(Node *n,
const Key &k, T *o, qsizetype cost)
71 new (n) Node{ Key(k), Value(o, cost) };
73 void emplace(T *o, qsizetype cost)
75 value = Value(o, cost);
80 key(std::move(other.key)),
81 value(std::move(other.value))
85 this->prev->next =
this;
86 this->next->prev =
this;
92 using Data = QHashPrivate::Data<Node>;
99 void unlink(Node *n)
noexcept(std::is_nothrow_destructible_v<Node>)
103 n->prev->next = n->next;
104 n->next->prev = n->prev;
105 total -= n->value.cost;
106 auto it = d.findBucket(n->key);
109 T *relink(
const Key &key)
const noexcept
113 Node *n = d.findNode(key);
117 if (chain.next != n) {
120 n->prev->next = n->next;
121 n->next->prev = n->prev;
122 n->next = chain.next;
123 chain.next->prev = n;
130 void trim(qsizetype m)
noexcept(std::is_nothrow_destructible_v<Node>)
132 while (chain.prev != &chain && total > m) {
133 Node *n =
static_cast<Node *>(chain.prev);
139 Q_DISABLE_COPY(QCache)
142 inline explicit QCache(qsizetype maxCost = 100)
noexcept
148 static_assert(std::is_nothrow_destructible_v<Key>,
"Types with throwing destructors are not supported in Qt containers.");
149 static_assert(std::is_nothrow_destructible_v<T>,
"Types with throwing destructors are not supported in Qt containers.");
154 inline qsizetype maxCost()
const noexcept {
return mx; }
155 void setMaxCost(qsizetype m)
noexcept(std::is_nothrow_destructible_v<Node>)
160 inline qsizetype totalCost()
const noexcept {
return total; }
162 inline qsizetype size()
const noexcept {
return qsizetype(d.size); }
163 inline qsizetype count()
const noexcept {
return qsizetype(d.size); }
164 inline bool isEmpty()
const noexcept {
return !d.size; }
165 inline QList<Key> keys()
const
170 for (
auto it = d.begin(); it != d.end(); ++it)
173 Q_ASSERT(k.size() == size());
177 void clear()
noexcept(std::is_nothrow_destructible_v<Node>)
185 bool insert(
const Key &key, T *object, qsizetype cost = 1)
193 auto result = d.findOrInsert(key);
194 Node *n = result.it.node();
195 if (result.initialized) {
196 auto prevCost = n->value.cost;
197 result.it.node()->emplace(object, cost);
201 Node::createInPlace(n, key, object, cost);
203 n->next = chain.next;
204 chain.next->prev = n;
210 T *object(
const Key &key)
const noexcept
214 T *operator[](
const Key &key)
const noexcept
218 inline bool contains(
const Key &key)
const noexcept
220 return !isEmpty() && d.findNode(key) !=
nullptr;
223 bool remove(
const Key &key)
noexcept(std::is_nothrow_destructible_v<Node>)
227 Node *n = d.findNode(key);
236 T *take(
const Key &key)
noexcept(std::is_nothrow_destructible_v<Key>)
240 Node *n = d.findNode(key);
245 n->value.t =
nullptr;
static bool readIniSection(const QSettingsKey §ion, QByteArrayView data, ParsedSettingsMap *settingsMap)
void set(const QString &key, const QVariant &value) override
QStringList children(const QString &prefix, ChildSpec spec) const override
~QConfFileSettingsPrivate()
virtual void initAccess()
bool readIniFile(QByteArrayView data, UnparsedSettingsMap *unparsedIniSections)
bool isWritable() const override
QString fileName() const override
QConfFileSettingsPrivate(QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application)
void remove(const QString &key) override
QConfFileSettingsPrivate(const QString &fileName, QSettings::Format format)
const QList< QConfFile * > & getConfFiles() const
static bool readIniLine(QByteArrayView data, qsizetype &dataPos, qsizetype &lineStart, qsizetype &lineLen, qsizetype &equalsPos)
std::optional< QVariant > get(const QString &key) const override
UnparsedSettingsMap unparsedIniSections
ParsedSettingsMap originalKeys
static Q_AUTOTEST_EXPORT void clearCache()
ParsedSettingsMap removedKeys
ParsedSettingsMap mergedKeyMap() const
static QConfFile * fromName(const QString &name, bool _userPerms)
ParsedSettingsMap addedKeys
QSettingsGroup(const QString &s, bool guessArraySize)
qsizetype arraySizeGuess() const
QSettingsGroup(const QString &s)
void setArrayIndex(qsizetype i)
QSettingsIniKey(const QString &str, qsizetype pos=-1)
QSettingsKey(const QString &key, Qt::CaseSensitivity cs, qsizetype=-1)
QString originalCaseKey() const
qsizetype originalKeyPosition() const
Combined button and popup list for selecting options.
static const char charTraits[256]
QMap< QString, QSettingsIniSection > IniMap
QList< QConfFileCustomFormat > CustomFormatVector
static bool operator<(const QSettingsIniKey &k1, const QSettingsIniKey &k2)
static constexpr QChar sep
static Path getPath(QSettings::Format format, QSettings::Scope scope)
QMap< QSettingsIniKey, QVariant > IniKeyMap
static int pathHashKey(QSettings::Format format, QSettings::Scope scope)
static QString make_user_path()
static std::unique_lock< QBasicMutex > initDefaultPaths(std::unique_lock< QBasicMutex > locker)
static QString make_user_path_without_qstandard_paths()
QHash< QString, QConfFile * > ConfFileHash
QHash< int, Path > PathHash
Q_DECLARE_TYPEINFO(QSettingsIniSection, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(QConfFileCustomFormat, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(QSettingsIniKey, Q_RELOCATABLE_TYPE)
QCache< QString, QConfFile > ConfFileCache
#define FLUSH_CURRENT_SECTION()
static void iniChopTrailingSpaces(QString &str, qsizetype limit)
Q_DECLARE_TYPEINFO(QSettingsGroup, Q_RELOCATABLE_TYPE)
static const Qt::CaseSensitivity IniCaseSensitivity
Q_DECLARE_TYPEINFO(QSettingsKey, Q_RELOCATABLE_TYPE)
QMap< QSettingsKey, QByteArray > UnparsedSettingsMap
QMap< QSettingsKey, QVariant > ParsedSettingsMap
#define QT_QSETTINGS_ALWAYS_CASE_SENSITIVE_AND_FORGET_ORIGINAL_KEY_ORDER