~ubuntu-branches/debian/jessie/apper/jessie

« back to all changes in this revision

Viewing changes to libapper/AppStream/CategoryMatcher.cpp

  • Committer: Package Import Robot
  • Author(s): Matthias Klumpp
  • Date: 2013-07-30 12:34:46 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130730123446-cgzujaj03pc61drn
Tags: 0.8.1-1
* New upstream release: 0.8.1
* Depend on software-properties-kde instead of suggesting it (Closes: #696583)
* Add patch to make AppStream loading more failsafe

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2012 by Daniel Nicoletti                                *
3
 
 *   dantti12@gmail.com                                                    *
4
 
 *                                                                         *
5
 
 *   This program is free software; you can redistribute it and/or modify  *
6
 
 *   it under the terms of the GNU General Public License as published by  *
7
 
 *   the Free Software Foundation; either version 2 of the License, or     *
8
 
 *   (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 program; see the file COPYING. If not, write to       *
17
 
 *   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,  *
18
 
 *   Boston, MA 02110-1301, USA.                                           *
19
 
 ***************************************************************************/
20
 
 
21
 
#include "CategoryMatcher.h"
22
 
 
23
 
CategoryMatcher::CategoryMatcher(Kind kind, const QString &term) :
24
 
    m_kind(kind),
25
 
    m_term(term)
26
 
{
27
 
}
28
 
 
29
 
CategoryMatcher::CategoryMatcher(const CategoryMatcher &other) :
30
 
    m_kind(other.m_kind),
31
 
    m_term(other.m_term),
32
 
    m_child(other.m_child)
33
 
{
34
 
}
35
 
 
36
 
CategoryMatcher::~CategoryMatcher()
37
 
{
38
 
}
39
 
 
40
 
CategoryMatcher &CategoryMatcher::operator =(const CategoryMatcher &other)
41
 
{
42
 
    m_kind = other.m_kind;
43
 
    m_term = other.m_term;
44
 
    m_child = other.m_child;
45
 
    return *this;
46
 
}
47
 
 
48
 
bool CategoryMatcher::match(const QStringList &categories) const
49
 
{
50
 
    if (categories.isEmpty()) {
51
 
        return false;
52
 
    }
53
 
 
54
 
    bool ret = false;
55
 
    switch (m_kind) {
56
 
    case Term:
57
 
        ret = categories.contains(m_term);
58
 
        break;
59
 
    case And:
60
 
        foreach (const CategoryMatcher &parser, m_child) {
61
 
            if (!(ret = parser.match(categories))) {
62
 
                break;
63
 
            }
64
 
        }
65
 
        break;
66
 
    case Or:
67
 
        foreach (const CategoryMatcher &parser, m_child) {
68
 
            if ((ret = parser.match(categories))) {
69
 
                break;
70
 
            }
71
 
        }
72
 
        break;
73
 
    case Not:
74
 
        // We match like And but negating
75
 
        foreach (const CategoryMatcher &parser, m_child) {
76
 
            if (!(ret = !parser.match(categories))) {
77
 
                break;
78
 
            }
79
 
        }
80
 
        break;
81
 
    }
82
 
    return ret;
83
 
}
84
 
 
85
 
void CategoryMatcher::setChild(const QList<CategoryMatcher> &child)
86
 
{
87
 
    m_child = child;
88
 
}
89
 
 
90
 
QList<CategoryMatcher> CategoryMatcher::child() const
91
 
{
92
 
    return m_child;
93
 
}
94
 
 
95
 
QString CategoryMatcher::term() const
96
 
{
97
 
    return m_term;
98
 
}
99
 
 
100
 
CategoryMatcher::Kind CategoryMatcher::kind() const
101
 
{
102
 
    return m_kind;
103
 
}