Changed Yaml to log missing files, files are actually closed.
This commit is contained in:
parent
bb3ecf637b
commit
fe7909ea7b
2 changed files with 14 additions and 5 deletions
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
Reference in a new issue