Browse Source

INIFile::Section::get() functions now more closely mirror the INIFile::get() functions.

release/0.19
JustinAJ 10 years ago
parent
commit
911d3fc122
  1. 65
      Jupiter/INIFile.cpp
  2. 76
      Jupiter/INIFile.h
  3. BIN
      Release/Jupiter.lib

65
Jupiter/INIFile.cpp

@ -122,12 +122,12 @@ const Jupiter::ReadableString &Jupiter::INIFile::Section::getName() const
return Jupiter::INIFile::Section::data_->name;
}
const Jupiter::ReadableString &Jupiter::INIFile::Section::getValue(size_t index) const
const Jupiter::ReadableString &Jupiter::INIFile::Section::get(size_t index) const
{
return Jupiter::INIFile::Section::data_->data.get(index)->data_->value;
}
const Jupiter::ReadableString &Jupiter::INIFile::Section::getValue(const Jupiter::ReadableString &key, const Jupiter::ReadableString &defaultValue) const
const Jupiter::ReadableString &Jupiter::INIFile::Section::get(const Jupiter::ReadableString &key, const Jupiter::ReadableString &defaultValue) const
{
Jupiter::INIFile::Section::KeyValuePair *pair;
const unsigned int keySum = key.calcChecksumi();
@ -141,6 +141,67 @@ const Jupiter::ReadableString &Jupiter::INIFile::Section::getValue(const Jupiter
return defaultValue;
}
bool Jupiter::INIFile::Section::getBool(const Jupiter::ReadableString &key, bool defaultValue) const
{
const Jupiter::ReadableString &val = Jupiter::INIFile::Section::get(key);
if (val.isEmpty() == false)
return val.asBool();
return defaultValue;
}
short Jupiter::INIFile::Section::getShort(const Jupiter::ReadableString &key, short defaultValue) const
{
return static_cast<short>(Jupiter::INIFile::Section::getInt(key, defaultValue));
}
int Jupiter::INIFile::Section::getInt(const Jupiter::ReadableString &key, int defaultValue) const
{
const Jupiter::ReadableString &val = Jupiter::INIFile::Section::get(key);
if (val.isEmpty() == false)
return val.asInt();
return defaultValue;
}
long Jupiter::INIFile::Section::getLong(const Jupiter::ReadableString &key, long defaultValue) const
{
const Jupiter::ReadableString &val = Jupiter::INIFile::Section::get(key);
if (val.isEmpty() == false)
return val.asInt();
return defaultValue;
}
long long Jupiter::INIFile::Section::getLongLong(const Jupiter::ReadableString &key, long long defaultValue) const
{
const Jupiter::ReadableString &val = Jupiter::INIFile::Section::get(key);
if (val.isEmpty() == false)
return val.asLongLong();
return defaultValue;
}
float Jupiter::INIFile::Section::getFloat(const Jupiter::ReadableString &key, float defaultValue) const
{
const Jupiter::ReadableString &val = Jupiter::INIFile::Section::get(key);
if (val.isEmpty() == false)
return float(val.asDouble());
return defaultValue;
}
double Jupiter::INIFile::Section::getDouble(const Jupiter::ReadableString &key, double defaultValue) const
{
const Jupiter::ReadableString &val = Jupiter::INIFile::Section::get(key);
if (val.isEmpty() == false)
return val.asDouble();
return defaultValue;
}
long double Jupiter::INIFile::Section::getLongDouble(const Jupiter::ReadableString &key, long double defaultValue) const
{
const Jupiter::ReadableString &val = Jupiter::INIFile::Section::get(key);
if (val.isEmpty() == false)
return val.asDouble();
return defaultValue;
}
Jupiter::INIFile::Section::KeyValuePair *Jupiter::INIFile::Section::getPair(size_t index) const
{
return Jupiter::INIFile::Section::data_->data.get(index);

76
Jupiter/INIFile.h

@ -118,7 +118,7 @@ namespace Jupiter
* @param index Index of the key-value pair.
* @return Value of a key-value pair at a specified index.
*/
const Jupiter::ReadableString &getValue(size_t index) const;
const Jupiter::ReadableString &get(size_t index) const;
/**
* @brief Fetches the value of a key-value pair.
@ -126,7 +126,79 @@ namespace Jupiter
* @param key Key of the key-value pair.
* @return Value of a key-value pair, or an empty string if none is found.
*/
const Jupiter::ReadableString &getValue(const Jupiter::ReadableString &key, const Jupiter::ReadableString &defaultValue = Jupiter::ReferenceString::empty) const;
const Jupiter::ReadableString &get(const Jupiter::ReadableString &key, const Jupiter::ReadableString &defaultValue = Jupiter::ReferenceString::empty) const;
/**
* @brief Translates and returns the value of a key-value pair as a boolean.
*
* @param key String containing key name.
* @param defaultValue Value to return if none is found.
* @return true if key exists and is not "false" or "0", defaultValue otherwise.
*/
bool getBool(const Jupiter::ReadableString &key, bool defaultValue = false) const;
/**
* @brief Translates and returns the value of a key-value pair as a short.
*
* @param key String containing key name.
* @param defaultValue Value to return if none is found.
* @return short value of the key if it exits, defaultValue otherwise.
*/
short getShort(const Jupiter::ReadableString &key, short defaultValue = 0) const;
/**
* @brief Translates and returns the value of a key-value pair as an int.
*
* @param key String containing key name.
* @param defaultValue Value to return if none is found.
* @return int value of the key if it exits, defaultValue otherwise.
*/
int getInt(const Jupiter::ReadableString &key, int defaultValue = 0) const;
/**
* @brief Translates and returns the value of a key-value pair as a long.
*
* @param key String containing key name.
* @param defaultValue Value to return if none is found.
* @return long value of the key if it exits, defaultValue otherwise.
*/
long getLong(const Jupiter::ReadableString &key, long defaultValue = 0) const;
/**
* @brief Translates and returns the value of a key-value pair as a long long.
*
* @param key String containing key name.
* @param defaultValue Value to return if none is found.
* @return long long value of the key if it exits, defaultValue otherwise.
*/
long long getLongLong(const Jupiter::ReadableString &key, long long defaultValue = 0) const;
/**
* @brief Translates and returns the value of a key-value pair as a float.
*
* @param key String containing key name.
* @param defaultValue Value to return if none is found.
* @return float value of the key if it exits, defaultValue otherwise.
*/
float getFloat(const Jupiter::ReadableString &key, float defaultValue = 0) const;
/**
* @brief Translates and returns the value of a key-value pair as a double.
*
* @param key String containing key name.
* @param defaultValue Value to return if none is found.
* @return double value of the key if it exits, defaultValue otherwise.
*/
double getDouble(const Jupiter::ReadableString &key, double defaultValue = 0) const;
/**
* @brief Translates and returns the value of a key-value pair as a long double.
*
* @param key String containing key name.
* @param defaultValue Value to return if none is found.
* @return long double value of the key if it exits, defaultValue otherwise.
*/
long double getLongDouble(const Jupiter::ReadableString &key, long double defaultValue = 0) const;
/**
* @brief Fetches a key-value pair at a specified index.

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save