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-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 
33 class Tileset final : public ImageSet
34 {
35  public:
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 
52 
53 
57  { return mFirstGid; }
58 
62  void setProperties(const std::map<std::string,
63  std::string> &props) noexcept2
64  { mProperties = props; }
65 
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 
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
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
int getFirstGid() const
Definition: tileset.h:56
std::string getProperty(const std::string &name)
Definition: tileset.h:69
#define A_WARN_UNUSED
Definition: localconsts.h:172
#define final
Definition: localconsts.h:45
Tileset(Image *const img, const int w, const int h, const int firstGid, const int margin, const int spacing)
Definition: tileset.h:39
int mFirstGid
Definition: tileset.h:96
int calcMemoryLocal() const
Definition: tileset.h:78
std::map< std::string, std::string > mProperties
Definition: tileset.h:98
void setProperties(const std::map< std::string, std::string > &props)
Definition: tileset.h:62
int calcMemoryLocal() const
Definition: imageset.cpp:77
Definition: image.h:61
#define override
Definition: localconsts.h:46
#define noexcept2
Definition: localconsts.h:49