ManaPlus
properties.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_PROPERTIES_H
24 #define RESOURCES_MAP_PROPERTIES_H
25 
26 #include "localconsts.h"
27 
28 #include <map>
29 #include <sstream>
30 
35 {
36  public:
38  mProperties()
39  {
40  }
41 
43 
44 
47  virtual ~Properties()
48  { }
49 
58  const std::string getProperty(const std::string &name,
59  const std::string &def)
60  const A_WARN_UNUSED
61  {
62  const PropertyMap::const_iterator i = mProperties.find(name);
63  return (i != mProperties.end()) ? i->second : def;
64  }
65 
74  float getFloatProperty(const std::string &name,
75  const float def) const A_WARN_UNUSED
76  {
77  const PropertyMap::const_iterator i = mProperties.find(name);
78  float ret = def;
79  if (i != mProperties.end())
80  {
81  std::stringstream ss;
82  ss.str(i->second);
83  ss >> ret;
84  }
85  return ret;
86  }
87 
96  bool getBoolProperty(const std::string &name,
97  const bool def) const A_WARN_UNUSED
98  {
99  const PropertyMap::const_iterator i = mProperties.find(name);
100  bool ret = def;
101  if (i != mProperties.end())
102  {
103  if (i->second == "true")
104  ret = true;
105  if (i->second == "false")
106  ret = false;
107  }
108  return ret;
109  }
110 
118  bool hasProperty(const std::string &name) const A_WARN_UNUSED
119  { return (mProperties.find(name) != mProperties.end()); }
120 
127  void setProperty(const std::string &name, const std::string &value)
128  { mProperties[name] = value; }
129 
130 
131  private:
132  typedef std::map<std::string, std::string> PropertyMap;
134 };
135 
136 #endif // RESOURCES_MAP_PROPERTIES_H
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
bool hasProperty(const std::string &name) const
Definition: properties.h:118
#define A_WARN_UNUSED
Definition: localconsts.h:172
const std::string getProperty(const std::string &name, const std::string &def) const
Definition: properties.h:58
float getFloatProperty(const std::string &name, const float def) const
Definition: properties.h:74
PropertyMap mProperties
Definition: properties.h:133
void setProperty(const std::string &name, const std::string &value)
Definition: properties.h:127
#define notfinal
Definition: localconsts.h:289
std::map< std::string, std::string > PropertyMap
Definition: properties.h:132
bool getBoolProperty(const std::string &name, const bool def) const
Definition: properties.h:96