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 "Yaml.h"
|
||||||
|
|
||||||
|
#include "../util/Log.h"
|
||||||
|
|
||||||
String Yaml::mFolder = "";
|
String Yaml::mFolder = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a readable object from a YAML file. The path must be relative to the directory
|
* Creates a readable object from a YAML file. The path must be relative to the directory
|
||||||
* set in setFolder().
|
* set in setFolder().
|
||||||
*/
|
*/
|
||||||
Yaml::Yaml(const String& filename) {
|
Yaml::Yaml(const String& filename) :
|
||||||
std::ifstream file(mFolder+filename);
|
mFile(mFolder+filename) {
|
||||||
YAML::Parser parser(file);
|
if (mFile.fail()) {
|
||||||
|
LOG_W("Failed to open YAML file: " << mFolder << filename);
|
||||||
|
}
|
||||||
|
YAML::Parser parser(mFile);
|
||||||
parser.GetNextDocument(mNode);
|
parser.GetNextDocument(mNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Yaml::~Yaml() {
|
||||||
|
mFile.close();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the folder where YAML files are placed. Is added in front of each file name. Allows
|
* 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.
|
* shorter strings as this does not have to be added everywhere.
|
||||||
|
|
|
@ -15,8 +15,6 @@
|
||||||
#include "../types/String.h"
|
#include "../types/String.h"
|
||||||
#include "../types/Vector.h"
|
#include "../types/Vector.h"
|
||||||
|
|
||||||
namespace details {};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface to a YAML file.
|
* Interface to a YAML file.
|
||||||
*/
|
*/
|
||||||
|
@ -24,6 +22,7 @@ class Yaml {
|
||||||
// Public functions.
|
// Public functions.
|
||||||
public:
|
public:
|
||||||
Yaml(const String& filename);
|
Yaml(const String& filename);
|
||||||
|
~Yaml();
|
||||||
|
|
||||||
static void setFolder(const String& folder);
|
static void setFolder(const String& folder);
|
||||||
|
|
||||||
|
@ -33,6 +32,7 @@ public:
|
||||||
// Private variables.
|
// Private variables.
|
||||||
private:
|
private:
|
||||||
static String mFolder;
|
static String mFolder;
|
||||||
|
std::ifstream mFile;
|
||||||
YAML::Node mNode;
|
YAML::Node mNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Reference in a new issue