diff --git a/source/util/Yaml.cpp b/source/util/Yaml.cpp index c0ca64f..fb29bbc 100644 --- a/source/util/Yaml.cpp +++ b/source/util/Yaml.cpp @@ -7,18 +7,27 @@ #include "Yaml.h" +#include "../util/Log.h" + String Yaml::mFolder = ""; /** * Creates a readable object from a YAML file. The path must be relative to the directory * set in setFolder(). */ -Yaml::Yaml(const String& filename) { - std::ifstream file(mFolder+filename); - YAML::Parser parser(file); +Yaml::Yaml(const String& filename) : + mFile(mFolder+filename) { + if (mFile.fail()) { + LOG_W("Failed to open YAML file: " << mFolder << filename); + } + YAML::Parser parser(mFile); parser.GetNextDocument(mNode); } +Yaml::~Yaml() { + mFile.close(); +} + /** * 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. diff --git a/source/util/Yaml.h b/source/util/Yaml.h index ca58e80..74d8c86 100644 --- a/source/util/Yaml.h +++ b/source/util/Yaml.h @@ -15,8 +15,6 @@ #include "../types/String.h" #include "../types/Vector.h" -namespace details {}; - /** * Interface to a YAML file. */ @@ -24,6 +22,7 @@ class Yaml { // Public functions. public: Yaml(const String& filename); + ~Yaml(); static void setFolder(const String& folder); @@ -33,6 +32,7 @@ public: // Private variables. private: static String mFolder; + std::ifstream mFile; YAML::Node mNode; };