GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/item/itemoptionslist.h Lines: 0 23 0.0 %
Date: 2017-11-29 Branches: 0 40 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-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#ifndef RESOURCES_ITEM_ITEMOPTIONSLIST_H
24
#define RESOURCES_ITEM_ITEMOPTIONSLIST_H
25
26
#include "const/resources/item/itemoptions.h"
27
28
#include "resources/item/itemoption.h"
29
30
#include "localconsts.h"
31
32
struct ItemOptionsList final
33
{
34
    explicit ItemOptionsList(const size_t amount0) :
35
        options(nullptr),
36
        amount(amount0),
37
        pointer(0U)
38
    {
39
        options = new ItemOption[amount];
40
    }
41
42
    ItemOptionsList() :
43
        options(nullptr),
44
        amount(maxItemOptions),
45
        pointer(0U)
46
    {
47
        options = new ItemOption[amount];
48
    }
49
50
    A_DELETE_COPY(ItemOptionsList)
51
52
    ~ItemOptionsList()
53
    {
54
        delete [] options;
55
        options = nullptr;
56
    }
57
58
    void add(const uint16_t index,
59
             const uint16_t value)
60
    {
61
        if (pointer >= amount)
62
            return;
63
        options[pointer].index = index;
64
        options[pointer].value = value;
65
        pointer ++;
66
    }
67
68
    static ItemOptionsList *copy(const ItemOptionsList *const options0)
69
    {
70
        if (options0 == nullptr)
71
            return nullptr;
72
73
        const size_t amount0 = options0->amount;
74
        ItemOptionsList *const obj = new ItemOptionsList(amount0);
75
        for (size_t f = 0; f < amount0; f ++)
76
        {
77
            obj->options[f].index = options0->options[f].index;
78
            obj->options[f].value = options0->options[f].value;
79
        }
80
        obj->amount = options0->amount;
81
        obj->pointer = options0->pointer;
82
        return obj;
83
    }
84
85
    size_t size() const
86
    {
87
        if (pointer < amount)
88
            return pointer;
89
        return amount;
90
    }
91
92
    const ItemOption &get(const size_t index) const
93
    {
94
        return options[index];
95
    }
96
97
    ItemOption *options;
98
    size_t amount;
99
    size_t pointer;
100
};
101
102
#endif  // RESOURCES_ITEM_ITEMOPTIONSLIST_H