~ubuntu-branches/ubuntu/wily/psi/wily-proposed

« back to all changes in this revision

Viewing changes to src/capabilities/capsspec.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-08-28 18:46:52 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080828184652-iiik12dl91nq7cdi
Tags: 0.12-2
Uploading to unstable (Closes: Bug#494352)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * capsspec.cpp
 
3
 * Copyright (C) 2006  Remko Troncon
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License
 
7
 * as published by the Free Software Foundation; either version 2
 
8
 * of the License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this library; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 *
 
19
 */
 
20
 
 
21
#include <QString>
 
22
#include <QStringList>
 
23
 
 
24
#include "capsspec.h"
 
25
 
 
26
/**
 
27
 * \class CapsSpec
 
28
 * \brief A class representing an entity capability specification.
 
29
 * An entity capability is a combination of a node, a version, and a set of
 
30
 * extensions.
 
31
 */
 
32
 
 
33
/**
 
34
 * Default constructor.
 
35
 */
 
36
CapsSpec::CapsSpec()
 
37
{
 
38
}
 
39
 
 
40
 
 
41
/**
 
42
 * \brief Basic constructor.
 
43
 * @param node the node
 
44
 * @param ven the version
 
45
 * @param ext the list of extensions (separated by spaces)
 
46
 */
 
47
CapsSpec::CapsSpec(const QString& node, const QString& ver, const QString& ext) : node_(node), ver_(ver), ext_(ext) 
 
48
{
 
49
}
 
50
 
 
51
 
 
52
/**
 
53
 * \brief Returns the node of the capabilities specification.
 
54
 */
 
55
const QString& CapsSpec::node() const 
 
56
 
57
        return node_; 
 
58
}
 
59
 
 
60
 
 
61
/**
 
62
 * \brief Returns the version of the capabilities specification.
 
63
 */
 
64
const QString& CapsSpec::version() const 
 
65
 
66
        return ver_; 
 
67
}
 
68
 
 
69
 
 
70
/**
 
71
 * \brief Returns the extensions of the capabilities specification.
 
72
 */
 
73
const QString& CapsSpec::extensions() const 
 
74
 
75
        return ext_; 
 
76
}
 
77
 
 
78
 
 
79
/**
 
80
 * \brief Flattens the caps specification into the set of 'simple' 
 
81
 * specifications.
 
82
 * A 'simple' specification is a specification with exactly one extension,
 
83
 * or with the version number as the extension.
 
84
 *
 
85
 * Example: A caps specification with node=http://psi-im.org, version=0.10,
 
86
 * and ext='achat vchat' would be expanded into the following list of specs:
 
87
 *      node=http://psi-im.org, ver=0.10, ext=0.10
 
88
 *      node=http://psi-im.org, ver=0.10, ext=achat
 
89
 *      node=http://psi-im.org, ver=0.10, ext=vchat
 
90
 */
 
91
CapsSpecs CapsSpec::flatten() const 
 
92
{
 
93
        CapsSpecs l;
 
94
        l.append(CapsSpec(node(),version(),version()));
 
95
        QStringList exts(extensions().split(" ",QString::SkipEmptyParts));
 
96
        for (QStringList::ConstIterator i = exts.begin(); i != exts.end(); ++i) {
 
97
                l.append(CapsSpec(node(),version(),*i));
 
98
        }
 
99
        return l;
 
100
}
 
101
 
 
102
bool CapsSpec::operator==(const CapsSpec& s) const 
 
103
{
 
104
        return (node() == s.node() && version() == s.version() && extensions() == s.extensions());
 
105
}
 
106
 
 
107
bool CapsSpec::operator!=(const CapsSpec& s) const 
 
108
{
 
109
        return !((*this) == s);
 
110
}
 
111
 
 
112
bool CapsSpec::operator<(const CapsSpec& s) const 
 
113
{
 
114
        return (node() != s.node() ? node() < s.node() :
 
115
                        (version() != s.version() ? version() < s.version() : 
 
116
                         extensions() < s.extensions()));
 
117
}
 
118