GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/map/tileset.h Lines: 0 15 0.0 %
Date: 2018-05-23 22:10:27 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-2018  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
            mProperties(),
47
            mFirstGid(firstGid),
48
            mIsEmpty(false)
49
        {
50
        }
51
52
        A_DELETE_COPY(Tileset)
53
54
        /**
55
         * Returns the first gid.
56
         */
57
        int getFirstGid() const noexcept2 A_WARN_UNUSED
58
        { return mFirstGid; }
59
60
        /**
61
         * Set tileset property.
62
         */
63
        void setProperties(const std::map<std::string,
64
                           std::string> &props) noexcept2
65
        { mProperties = props; }
66
67
        /**
68
         * Returns property value.
69
         */
70
        std::string getProperty(const std::string &name) A_WARN_UNUSED
71
        {
72
            const std::map<std::string, std::string>::const_iterator
73
                it = mProperties.find(name);
74
            if (it == mProperties.end())
75
                return "";
76
            return mProperties[name];
77
        }
78
79
        int calcMemoryLocal() const override final
80
        {
81
            int sz = ImageSet::calcMemoryLocal() +
82
                static_cast<int>(sizeof(Tileset));
83
            const std::map<std::string, std::string>::const_iterator it_end =
84
                mProperties.end();
85
            std::map<std::string, std::string>::const_iterator it =
86
                mProperties.begin();
87
            while (it != it_end)
88
            {
89
                sz += static_cast<int>((*it).first.capacity() +
90
                    (*it).second.capacity());
91
                ++ it;
92
            }
93
            return sz;
94
        }
95
96
        void setEmpty(const bool b)
97
        { mIsEmpty = b; }
98
99
        bool isEmpty() const
100
        { return mIsEmpty; }
101
102
    private:
103
        std::map<std::string, std::string> mProperties;
104
        int mFirstGid;
105
        bool mIsEmpty;
106
};
107
108
#endif  // RESOURCES_MAP_TILESET_H