ManaPlus
Public Member Functions | Private Types | Private Attributes
Properties Class Reference

#include <properties.h>

Inheritance diagram for Properties:
Map

Public Member Functions

 Properties ()
 
virtual ~Properties ()
 
const std::string getProperty (const std::string &name, const std::string &def) const
 
float getFloatProperty (const std::string &name, const float def) const
 
bool getBoolProperty (const std::string &name, const bool def) const
 
bool hasProperty (const std::string &name) const
 
void setProperty (const std::string &name, const std::string &value)
 

Private Types

typedef std::map< std::string, std::string > PropertyMap
 

Private Attributes

PropertyMap mProperties
 

Detailed Description

A class holding a set of properties.

Definition at line 35 of file properties.h.

Member Typedef Documentation

◆ PropertyMap

typedef std::map<std::string, std::string> Properties::PropertyMap
private

Definition at line 133 of file properties.h.

Constructor & Destructor Documentation

◆ Properties()

Properties::Properties ( )
inline

Definition at line 38 of file properties.h.

38  :
39  mProperties()
40  {
41  }
PropertyMap mProperties
Definition: properties.h:134

◆ ~Properties()

virtual Properties::~Properties ( )
inlinevirtual

Destructor.

Definition at line 48 of file properties.h.

49  { }

Member Function Documentation

◆ getBoolProperty()

bool Properties::getBoolProperty ( const std::string &  name,
const bool  def 
) const
inline

Gets a map property as a boolean.

Parameters
nameThe name of the property.
defDefault value, false by default.
Returns
the value of the given property or the given default when it doesn't exist.

Definition at line 97 of file properties.h.

99  {
100  const PropertyMap::const_iterator i = mProperties.find(name);
101  bool ret = def;
102  if (i != mProperties.end())
103  {
104  if (i->second == "true")
105  ret = true;
106  if (i->second == "false")
107  ret = false;
108  }
109  return ret;
110  }

References mProperties.

Referenced by Map::initializeAmbientLayers().

◆ getFloatProperty()

float Properties::getFloatProperty ( const std::string &  name,
const float  def 
) const
inline

Gets a map property as a float.

Parameters
nameThe name of the property.
defDefault value, 0.0F by default.
Returns
the value of the given property or the given default when it doesn't exist.

Definition at line 75 of file properties.h.

77  {
78  const PropertyMap::const_iterator i = mProperties.find(name);
79  float ret = def;
80  if (i != mProperties.end())
81  {
82  std::stringstream ss;
83  ss.str(i->second);
84  ss >> ret;
85  }
86  return ret;
87  }

References mProperties.

Referenced by Map::initializeAmbientLayers().

◆ getProperty()

const std::string Properties::getProperty ( const std::string &  name,
const std::string &  def 
) const
inline

Get a map property.

Parameters
nameThe name of the property.
defDefault value, empty string by default.
Returns
the value of the given property or the given default when it doesn't exist.

Definition at line 59 of file properties.h.

62  {
63  const PropertyMap::const_iterator i = mProperties.find(name);
64  return (i != mProperties.end()) ? i->second : def;
65  }

References mProperties.

Referenced by Map::getFilename(), Map::getGatName(), Map::getMusicFile(), Map::getName(), Map::getUserMapDirectory(), Map::initializeAmbientLayers(), MapDebugTab::logic(), LocalPlayer::moveToHome(), LocalPlayer::removeHome(), LocalPlayer::setHome(), Minimap::setMap(), QuestsWindow::setMap(), MapReader::updateMusic(), and LocalPlayer::updateNavigateList().

◆ hasProperty()

bool Properties::hasProperty ( const std::string &  name) const
inline

Returns whether a certain property is available.

Parameters
nameThe name of the property.
Returns
true when a property is defined, false otherwise.

Definition at line 119 of file properties.h.

120  { return (mProperties.find(name) != mProperties.end()); }

References mProperties.

Referenced by Map::getName(), and Map::initializeAmbientLayers().

◆ setProperty()

void Properties::setProperty ( const std::string &  name,
const std::string &  value 
)
inline

Set a map property.

Parameters
nameThe name of the property.
valueThe value of the property.

Definition at line 128 of file properties.h.

129  { mProperties[name] = value; }

References mProperties.

Referenced by MapReader::createEmptyMap(), and MapReader::updateMusic().

Field Documentation

◆ mProperties

PropertyMap Properties::mProperties
private

The documentation for this class was generated from the following file: