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.
dungeon-gunner/source/util/Yaml.cpp

47 lines
910 B
C++
Raw Normal View History

/*
* Yaml.cpp
*
* Created on: 06.10.2012
* Author: Felix
*/
#include "Yaml.h"
#include "../util/Log.h"
2012-12-22 14:10:26 +00:00
std::string Yaml::mFolder = "";
/**
* Creates a readable object from a YAML file. The path must be relative to the directory
* set in setFolder().
*/
2012-12-22 14:10:26 +00:00
Yaml::Yaml(const std::string& filename) :
mFilename(mFolder+filename),
mFile(mFilename) {
2013-04-04 21:13:08 +00:00
if (mFile.fail())
LOG_W("Failed to open YAML file: " << mFolder << filename);
YAML::Parser parser(mFile);
parser.GetNextDocument(mNode);
}
Yaml::~Yaml() {
mFile.close();
}
/**
* Return path and name of the file opened in this object.
*/
2012-12-22 14:10:26 +00:00
std::string
Yaml::getFilename() const {
return mFilename;
}
/**
* Sets the folder where YAML files are placed. Is added in front of each file name. Allows
* shorter strings as this does not have to be added everywhere.
*/
void
2012-12-22 14:10:26 +00:00
Yaml::setFolder(const std::string& folder) {
mFolder = folder;
}