GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/map/tileset.h Lines: 0 15 0.0 %
Date: 2021-03-17 Branches: 0 4 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 RESOURCES_MAP_TILESET_H
25
#define RESOURCES_MAP_TILESET_H
26
27
#include "resources/imageset.h"
28
29
#include <map>
30
31
/**
32
 * A tileset, which is basically just an image set but it stores a firstgid.
33
 */
34
class Tileset final : public ImageSet
35
{
36
    public:
37
        /**
38
         * Constructor.
39
         */
40
        Tileset(Image *const img,
41
                const int w,
42
                const int h,
43
                const int firstGid,
44
                const int margin,
45
                const int spacing) :
46
            ImageSet(img, w, h, margin, spacing),
47
            mProperties(),
48
            mFirstGid(firstGid),
49
            mIsEmpty(false)
50
        {
51
        }
52
53
        A_DELETE_COPY(Tileset)
54
55
        /**
56
         * Returns the first gid.
57
         */
58
        int getFirstGid() const noexcept2 A_WARN_UNUSED
59
        { return mFirstGid; }
60
61
        /**
62
         * Set tileset property.
63
         */
64
        void setProperties(const std::map<std::string,
65
                           std::string> &props) noexcept2
66
        { mProperties = props; }
67
68
        /**
69
         * Returns property value.
70
         */
71
        std::string getProperty(const std::string &name) A_WARN_UNUSED
72
        {
73
            const std::map<std::string, std::string>::const_iterator
74
                it = mProperties.find(name);
75
            if (it == mProperties.end())
76
                return "";
77
            return mProperties[name];
78
        }
79
80
        int calcMemoryLocal() const override final
81
        {
82
            int sz = ImageSet::calcMemoryLocal() +
83
                static_cast<int>(sizeof(Tileset));
84
            const std::map<std::string, std::string>::const_iterator it_end =
85
                mProperties.end();
86
            std::map<std::string, std::string>::const_iterator it =
87
                mProperties.begin();
88
            while (it != it_end)
89
            {
90
                sz += static_cast<int>((*it).first.capacity() +
91
                    (*it).second.capacity());
92
                ++ it;
93
            }
94
            return sz;
95
        }
96
97
        void setEmpty(const bool b)
98
        { mIsEmpty = b; }
99
100
        bool isEmpty() const
101
        { return mIsEmpty; }
102
103
    private:
104
        std::map<std::string, std::string> mProperties;
105
        int mFirstGid;
106
        bool mIsEmpty;
107
};
108
109
#endif  // RESOURCES_MAP_TILESET_H