This repository has been archived on 2019-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
2012-10-12 17:04:03 +00:00
|
|
|
/*
|
|
|
|
* Yaml.h
|
|
|
|
*
|
|
|
|
* Created on: 06.10.2012
|
|
|
|
* Author: Felix
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DG_YAML_H_
|
|
|
|
#define DG_YAML_H_
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include <yaml-cpp/yaml.h>
|
|
|
|
|
|
|
|
#include "String.h"
|
2012-10-13 10:22:18 +00:00
|
|
|
#include "Vector.h"
|
|
|
|
|
|
|
|
namespace details {};
|
2012-10-12 17:04:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Interface to a YAML file.
|
|
|
|
*/
|
|
|
|
class Yaml {
|
|
|
|
// Public functions.
|
|
|
|
public:
|
|
|
|
Yaml(const String& filename);
|
|
|
|
|
|
|
|
static void setFolder(const String& folder);
|
2012-10-13 10:22:18 +00:00
|
|
|
|
2012-10-12 17:04:03 +00:00
|
|
|
template <typename T>
|
2012-10-13 11:11:43 +00:00
|
|
|
T get(const String& key) const;
|
2012-10-12 17:04:03 +00:00
|
|
|
|
|
|
|
// Private variables.
|
|
|
|
private:
|
|
|
|
static String mFolder;
|
|
|
|
YAML::Node mNode;
|
|
|
|
};
|
|
|
|
|
2012-10-13 10:22:18 +00:00
|
|
|
/**
|
|
|
|
* Stream output operators to specialize Yaml::get for other types.
|
|
|
|
*/
|
|
|
|
namespace {
|
|
|
|
void operator>>(const YAML::Node& node, Vector2i& vector) {
|
|
|
|
node[0] >> vector.x;
|
|
|
|
node[1] >> vector.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator>>(const YAML::Node& node, Vector2f& vector) {
|
|
|
|
node[0] >> vector.x;
|
|
|
|
node[1] >> vector.y;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-10-13 11:11:43 +00:00
|
|
|
/**
|
|
|
|
* Gets a value of a specified type by key. Throws exception if key not found.
|
|
|
|
*
|
|
|
|
* @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 String& key) const {
|
|
|
|
T tmp;
|
|
|
|
mNode[key] >> tmp;
|
|
|
|
return tmp;
|
|
|
|
};
|
|
|
|
|
2012-10-12 17:04:03 +00:00
|
|
|
#endif /* DG_YAML_H_ */
|