GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/models/extendednamesmodel.cpp Lines: 13 22 59.1 %
Date: 2017-11-29 Branches: 1 12 8.3 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2012-2017  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "gui/models/extendednamesmodel.h"
22
23
#include "utils/cast.h"
24
#include "utils/foreach.h"
25
26
#include "debug.h"
27
28
4
ExtendedNamesModel::ExtendedNamesModel() :
29
    mNames(),
30
16
    mImages()
31
{
32
4
}
33
34
18
ExtendedNamesModel::~ExtendedNamesModel()
35
{
36
4
    clear();
37
6
}
38
39
4
int ExtendedNamesModel::getNumberOfElements()
40
{
41
8
    return CAST_S32(mNames.size());
42
}
43
44
std::string ExtendedNamesModel::getElementAt(int i)
45
{
46
    if (i >= getNumberOfElements() || i < 0)
47
        return "???";
48
    return mNames[CAST_SIZE(i)];
49
}
50
51
const Image *ExtendedNamesModel::getImageAt(int i)
52
{
53
    if (i >= CAST_S32(mImages.size()) || i < 0)
54
        return nullptr;
55
56
    return mImages[CAST_SIZE(i)];
57
}
58
59
4
void ExtendedNamesModel::clear()
60
{
61
4
    mNames.clear();
62
16
    FOR_EACH (STD_VECTOR<Image*>::iterator, it, mImages)
63
    {
64
        if (*it != nullptr)
65
            (*it)->decRef();
66
    }
67
8
    mImages.clear();
68
4
}