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 34 of file properties.h.

Member Typedef Documentation

◆ PropertyMap

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

Definition at line 132 of file properties.h.

Constructor & Destructor Documentation

◆ Properties()

Properties::Properties ( )
inline

Definition at line 37 of file properties.h.

References A_DELETE_COPY.

37  :
38  mProperties()
39  {
40  }
PropertyMap mProperties
Definition: properties.h:133

◆ ~Properties()

virtual Properties::~Properties ( )
inlinevirtual

Destructor.

Definition at line 47 of file properties.h.

48  { }

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 96 of file properties.h.

References mProperties.

Referenced by Map::initializeAmbientLayers().

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  }
PropertyMap mProperties
Definition: properties.h:133

◆ 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 74 of file properties.h.

References mProperties.

Referenced by Map::initializeAmbientLayers().

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  }
PropertyMap mProperties
Definition: properties.h:133

◆ 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 58 of file properties.h.

References mProperties.

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

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

◆ 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 118 of file properties.h.

References mProperties.

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

119  { return (mProperties.find(name) != mProperties.end()); }
PropertyMap mProperties
Definition: properties.h:133

◆ 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 127 of file properties.h.

References mProperties.

Referenced by MapReader::addLayerToList(), MapReader::createEmptyMap(), loadReplaceLayer(), MapReader::readProperties(), Map::setMusicFile(), and MapReader::updateMusic().

128  { mProperties[name] = value; }
PropertyMap mProperties
Definition: properties.h:133

Field Documentation

◆ mProperties

PropertyMap Properties::mProperties
private

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