KMime

kmime_contentindex.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2006-2007 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6/**
7 @file
8 This file is part of the API for handling @ref MIME data and
9 defines the ContentIndex class.
10
11 @brief
12 Defines the ContentIndex class.
13
14 @authors Volker Krause <vkrause@kde.org>
15*/
16
17#include "kmime_contentindex.h"
18
19#include <QHash>
20#include <QList>
21#include <QSharedData>
22#include <QStringList>
23#include <QStringTokenizer>
24
25using namespace KMime;
26
27class ContentIndex::Private : public QSharedData
28{
29public:
30 Private() = default;
31 Private(const Private &other) : QSharedData(other) { index = other.index; }
32
34};
35
37{
38}
39
41{
42 for (auto s : QStringTokenizer{index, QLatin1Char('.')}) {
43 bool ok;
44 unsigned int i = s.toUInt(&ok);
45 if (!ok) {
46 d->index.clear();
47 break;
48 }
49 d->index.append(i);
50 }
51}
52
53ContentIndex::ContentIndex(const ContentIndex &other) = default;
54ContentIndex::ContentIndex(ContentIndex &&) noexcept = default;
55
56ContentIndex::~ContentIndex() = default;
57
58bool KMime::ContentIndex::isValid() const
59{
60 return !d->index.isEmpty();
61}
62
64{
65 return d->index.takeFirst();
66}
67
68void KMime::ContentIndex::push(unsigned int index)
69{
70 d->index.prepend(index);
71}
72
73unsigned int ContentIndex::up()
74{
75 return d->index.takeLast();
76}
77
79{
81 l.reserve(d->index.count());
82 for (unsigned int i : std::as_const(d->index)) {
84 }
85 return l.join(QLatin1Char('.'));
86}
87
89{
90 return d->index == index.d->index;
91}
92
94{
95 return d->index != index.d->index;
96}
97
100
101size_t KMime::qHash(const KMime::ContentIndex &index, size_t seed) noexcept
102{
103 return qHash(index.toString(), seed);
104}
A class to uniquely identify message parts (Content) in a hierarchy.
QString toString() const
Returns a string representation of this content index according to RFC3501 section 6....
bool operator==(const ContentIndex &index) const
Compares this with index for equality.
unsigned int pop()
Removes and returns the top-most index.
ContentIndex()
Creates an empty content index.
bool operator!=(const ContentIndex &index) const
Compares this with index for inequality.
ContentIndex & operator=(const ContentIndex &other)
Assignment operator.
void push(unsigned int index)
Adds index to the content index.
unsigned int up()
Removes and returns the bottom-most index.
This file is part of the API for handling MIME data and defines the ContentIndex class.
void append(const T &value)
void reserve(int alloc)
QString number(int n, int base)
QString join(const QString &separator) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:46:48 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.