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