ManaPlus
tileset.h
Go to the documentation of this file.
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 
34 class Tileset final : public ImageSet
35 {
36  public:
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 
54 
55 
59  { return mFirstGid; }
60 
64  void setProperties(const std::map<std::string,
65  std::string> &props) noexcept2
66  { mProperties = props; }
67 
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 
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;
106  bool mIsEmpty;
107 };
108 
109 #endif // RESOURCES_MAP_TILESET_H
int calcMemoryLocal() const
Definition: imageset.cpp:78
bool isEmpty() const
Definition: tileset.h:100
int getFirstGid() const
Definition: tileset.h:58
void setEmpty(const bool b)
Definition: tileset.h:97
bool mIsEmpty
Definition: tileset.h:106
std::map< std::string, std::string > mProperties
Definition: tileset.h:104
Tileset(Image *const img, const int w, const int h, const int firstGid, const int margin, const int spacing)
Definition: tileset.h:40
int calcMemoryLocal() const
Definition: tileset.h:80
int mFirstGid
Definition: tileset.h:105
void setProperties(const std::map< std::string, std::string > &props)
Definition: tileset.h:64
std::string getProperty(const std::string &name)
Definition: tileset.h:71
#define override
Definition: localconsts.h:47
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53