KMime

kmime_contentindex.cpp
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: 2006-2007 Volker Krause <[email protected]>
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 <[email protected]>
15 */
16 
17 #include "kmime_contentindex.h"
18 
19 #include <QHash>
20 #include <QSharedData>
21 #include <QStringList>
22 #include <QVector>
23 
24 using namespace KMime;
25 
26 class ContentIndex::Private : public QSharedData
27 {
28 public:
29  Private() {}
30  Private(const Private &other) : QSharedData(other)
31  {
32  index = other.index;
33  }
34 
36 };
37 
39 {
40 }
41 
42 KMime::ContentIndex::ContentIndex(const QString &index) : d(new Private)
43 {
44  const QStringList l = index.split(QLatin1Char('.'));
45  for (const QString &s : l) {
46  bool ok;
47  unsigned int i = s.toUInt(&ok);
48  if (!ok) {
49  d->index.clear();
50  break;
51  }
52  d->index.append(i);
53  }
54 }
55 
56 ContentIndex::ContentIndex(const ContentIndex &other) : d(other.d)
57 {
58 }
59 
61 {
62 }
63 
65 {
66  return !d->index.isEmpty();
67 }
68 
70 {
71  return d->index.takeFirst();
72 }
73 
74 void KMime::ContentIndex::push(unsigned int index)
75 {
76  d->index.prepend(index);
77 }
78 
79 unsigned int ContentIndex::up()
80 {
81  return d->index.takeLast();
82 }
83 
85 {
86  QStringList l;
87  l.reserve(d->index.count());
88  for (unsigned int i : std::as_const(d->index)) {
89  l.append(QString::number(i));
90  }
91  return l.join(QLatin1Char('.'));
92 }
93 
95 {
96  return d->index == index.d->index;
97 }
98 
100 {
101  return d->index != index.d->index;
102 }
103 
105 {
106  if (this != &other) {
107  d = other.d;
108  }
109  return *this;
110 }
111 
112 uint KMime::qHash(const KMime::ContentIndex &index)
113 {
114  return qHash(index.toString());
115 }
bool operator==(const ContentIndex &index) const
Compares this with index for equality.
void reserve(int alloc)
bool isValid() const
Returns true if this index is non-empty (valid).
unsigned int pop()
Removes and returns the top-most index.
void push(unsigned int index)
Adds index to the content index.
QString join(const QString &separator) const const
ContentIndex & operator=(const ContentIndex &other)
Assignment operator.
QString number(int n, int base)
void append(const T &value)
QStringList split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
bool operator!=(const ContentIndex &index) const
Compares this with index for inequality.
KCALENDARCORE_EXPORT uint qHash(const KCalendarCore::Period &key)
QString toString() const
Returns a string representation of this content index according to RFC3501 section 6...
ContentIndex()
Creates an empty 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.
A class to uniquely identify message parts (Content) in a hierarchy.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Sep 25 2021 23:14:46 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.