GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/models/namesmodel.cpp Lines: 14 20 70.0 %
Date: 2017-11-29 Branches: 6 16 37.5 %

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/namesmodel.h"
22
23
#include "utils/cast.h"
24
#include "utils/foreach.h"
25
#include "utils/gettext.h"
26
27
#include "debug.h"
28
29
82
NamesModel::NamesModel() :
30
    ListModel(),
31
246
    mNames()
32
{
33
82
}
34
35
82
NamesModel::~NamesModel()
36
{
37
82
}
38
39
2064
int NamesModel::getNumberOfElements()
40
{
41
7608
    return CAST_S32(mNames.size());
42
}
43
44
1740
std::string NamesModel::getElementAt(int i)
45
{
46

1740
    if (i >= getNumberOfElements() || i < 0)
47
        return "???";
48
3480
    return mNames[CAST_SIZE(i)];
49
}
50
51
54
void NamesModel::fillFromArray(const char *const *const arr,
52
                               const std::size_t sz)
53
{
54
54
    if (arr == nullptr)
55
        return;
56
502
    for (size_t f = 0; f < sz; f ++)
57
1120
        mNames.push_back(gettext(arr[f]));
58
}
59
60
void NamesModel::fillFromVector(const StringVect &vect)
61
{
62
    FOR_EACH(StringVectCIter, it, vect)
63
    {
64
        const std::string str = *it;
65
        if (!str.empty())
66
            mNames.push_back(str);
67
    }
68
}