Added nullpointer check, removed mistakenly added file.
This commit is contained in:
parent
5ddc6c6c97
commit
3d9ab86e72
2 changed files with 9 additions and 53 deletions
|
@ -68,13 +68,16 @@ namespace {
|
|||
template <typename T>
|
||||
T Yaml::get(const std::string& key, const T& defaultValue) const {
|
||||
try {
|
||||
const YAML::Node* node = mNode.FindValue(key);
|
||||
T value;
|
||||
*node >> value;
|
||||
return value;
|
||||
if (const YAML::Node* node = mNode.FindValue(key)) {
|
||||
T value;
|
||||
*node >> value;
|
||||
return value;
|
||||
}
|
||||
else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
catch (YAML::InvalidScalar&) {
|
||||
LOG_W("Failed to get key " << key << " from " << mFolder << mFilename);
|
||||
catch(YAML::Exception&) {
|
||||
return defaultValue;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Yaml.h
|
||||
*
|
||||
* Created on: 30.03.2013
|
||||
* Author: Felix
|
||||
*/
|
||||
|
||||
#include <SFML/System.hpp>
|
||||
|
||||
#include "Log.h"
|
||||
|
||||
/**
|
||||
* Stream output operators to specialize Yaml::get for other types.
|
||||
* Error handling is done in Yaml::get.
|
||||
*/
|
||||
namespace {
|
||||
void operator>>(const YAML::Node& node, sf::Vector2i& vector) {
|
||||
node[0] >> vector.x;
|
||||
node[1] >> vector.y;
|
||||
}
|
||||
|
||||
void operator>>(const YAML::Node& node, sf::Vector2f& vector) {
|
||||
node[0] >> vector.x;
|
||||
node[1] >> vector.y;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a value of a specified type by key. Returns default value on error.
|
||||
*
|
||||
* @param key The string by which to select the return value.
|
||||
* @tparam T The type of the return value.
|
||||
* @return The value of the specified key.
|
||||
*/
|
||||
template <typename T>
|
||||
T Yaml::get(const std::string& key, const T& defaultValue) const {
|
||||
try {
|
||||
const YAML::Node* node = mNode.FindValue(key);
|
||||
T value;
|
||||
*node >> value;
|
||||
return value;
|
||||
}
|
||||
catch (YAML::InvalidScalar&) {
|
||||
LOG_W("Failed to get key " << key << " from " << mFolder << mFilename);
|
||||
return defaultValue;
|
||||
}
|
||||
};
|
Reference in a new issue