1/*
2 Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19/**
20 @file
21 This file is part of the API for handling @ref MIME data and
22 defines the ContentIndex class.
23
24 @brief
25 Defines the ContentIndex class.
26
27 @authors Volker Krause \<vkrause@kde.org\>
28*/
29
30#include "kmime_contentindex.h"
31
32#include <QHash>
33#include <QSharedData>
34#include <QtCore/QStringList>
35
36using namespace KMime;
37
38class ContentIndex::Private : public QSharedData
39{
40 public:
41 Private() {}
42 Private( const Private &other ) : QSharedData( other )
43 {
44 index = other.index;
45 }
46
47 QList<unsigned int> index;
48};
49
50KMime::ContentIndex::ContentIndex() : d( new Private )
51{
52}
53
54KMime::ContentIndex::ContentIndex( const QString &index ) : d( new Private )
55{
56 const QStringList l = index.split( QLatin1Char( '.' ) );
57 foreach ( const QString &s, l ) {
58 bool ok;
59 unsigned int i = s.toUInt( &ok );
60 if ( !ok ) {
61 d->index.clear();
62 break;
63 }
64 d->index.append( i );
65 }
66}
67
68ContentIndex::ContentIndex(const ContentIndex & other) : d( other.d )
69{
70}
71
72ContentIndex::~ContentIndex()
73{
74}
75
76bool KMime::ContentIndex::isValid() const
77{
78 return !d->index.isEmpty();
79}
80
81unsigned int KMime::ContentIndex::pop()
82{
83 return d->index.takeFirst();
84}
85
86void KMime::ContentIndex::push( unsigned int index )
87{
88 d->index.prepend( index );
89}
90
91QString KMime::ContentIndex::toString() const
92{
93 QStringList l;
94 foreach ( unsigned int i, d->index ) {
95 l.append( QString::number( i ) );
96 }
97 return l.join( QLatin1String( "." ) );
98}
99
100bool KMime::ContentIndex::operator ==( const ContentIndex &index ) const
101{
102 return d->index == index.d->index;
103}
104
105bool KMime::ContentIndex::operator !=( const ContentIndex &index ) const
106{
107 return d->index != index.d->index;
108}
109
110ContentIndex& ContentIndex::operator =(const ContentIndex & other)
111{
112 if ( this != &other ) {
113 d = other.d;
114 }
115 return *this;
116}
117
118uint qHash( const KMime::ContentIndex &index )
119{
120 return qHash( index.toString() );
121}
122