GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/equipment.h Lines: 4 9 44.4 %
Date: 2021-03-17 Branches: 0 14 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2019  The ManaPlus Developers
6
 *  Copyright (C) 2019-2021  Andrei Karas
7
 *
8
 *  This file is part of The ManaPlus Client.
9
 *
10
 *  This program is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; either version 2 of the License, or
13
 *  any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
21
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 */
23
24
#ifndef EQUIPMENT_H
25
#define EQUIPMENT_H
26
27
#include "localconsts.h"
28
29
class Item;
30
31
class Equipment final
32
{
33
    public:
34
        /**
35
         * Constructor.
36
         */
37
1
        Equipment() :
38
1
            mBackend(nullptr)
39
        { }
40
41
        A_DELETE_COPY(Equipment)
42
43
        /**
44
         * Destructor.
45
         */
46
        ~Equipment()
47
1
        { mBackend = nullptr; }
48
49
        class Backend notfinal
50
        {
51
            public:
52
                Backend()
53
1
                { }
54
55
                A_DELETE_COPY(Backend)
56
57
                virtual const Item *getEquipment(const int index)
58
                                                 const A_WARN_UNUSED = 0;
59
60
                virtual void clear() = 0;
61
62
                virtual ~Backend()
63
                { }
64
        };
65
66
        /**
67
         * Get equipment at the given slot.
68
         */
69
        const Item *getEquipment(const int index) const A_WARN_UNUSED
70
        {
71
            return mBackend != nullptr ?
72
                mBackend->getEquipment(index) : nullptr;
73
        }
74
75
        /**
76
         * Clears equipment.
77
         */
78
        void clear()
79
        { if (mBackend != nullptr) mBackend->clear(); }
80
81
        /**
82
         * Set equipment at the given slot.
83
         */
84
        void setEquipment(int index,
85
                          int id,
86
                          int quantity);
87
88
        void setBackend(Backend *const backend)
89
        { mBackend = backend; }
90
91
        const Backend *getBackend() const noexcept2 A_WARN_UNUSED
92
        { return mBackend; }
93
94
    private:
95
        Backend *mBackend;
96
};
97
98
#endif  // EQUIPMENT_H