GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/db/weaponsdb.cpp Lines: 11 26 42.3 %
Date: 2017-11-29 Branches: 2 30 6.7 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2014-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 "resources/db/weaponsdb.h"
22
23
#include "configuration.h"
24
#include "logger.h"
25
26
#include "utils/xmlutils.h"
27
28
#include "debug.h"
29
30
namespace
31
{
32
2
    WeaponsInfos mBows;
33
2
    WeaponsInfos mSwords;
34
2
    WeaponsInfos mShields;
35
    bool mLoaded = false;
36
}  // namespace
37
38
static void loadDB(const std::string &name,
39
                   WeaponsInfos &arr)
40
{
41
    readXmlIntVector(paths.getStringValue("weaponsFile"),
42
        "weapons",
43
        name,
44
        "item",
45
        "id",
46
        arr,
47
        SkipError_false);
48
}
49
50
void WeaponsDB::load()
51
{
52
    if (mLoaded)
53
        unload();
54
55
    logger->log1("Initializing weapon database...");
56
57
    loadDB("swords", mSwords);
58
    loadDB("bows", mBows);
59
    loadDB("shields", mShields);
60
}
61
62
384
void WeaponsDB::unload()
63
{
64
384
    logger->log1("Unloading weapon database...");
65
66
384
    mBows.clear();
67
384
    mSwords.clear();
68
384
    mShields.clear();
69
384
    mLoaded = false;
70
384
}
71
72
const WeaponsInfos &WeaponsDB::getBows()
73
{
74
    return mBows;
75
}
76
77
const WeaponsInfos &WeaponsDB::getSwords()
78
{
79
    return mSwords;
80
}
81
82
const WeaponsInfos &WeaponsDB::getShields()
83
{
84
    return mShields;
85

6
}