mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +00:00
Replaced the queue of Token pointers with values.
We were getting memory leaks (as told by the CRT detectors, which I also added), and there's really no reason (as long as we're careful) to use pointers there.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include "parser.h"
|
||||
#include "yaml.h"
|
||||
#include "tests.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@@ -9,85 +9,29 @@
|
||||
#pragma comment(lib, "yamlcpp.lib")
|
||||
#endif
|
||||
|
||||
struct Vec3 {
|
||||
float x, y, z;
|
||||
|
||||
friend std::ostream& operator << (std::ostream& out, const Vec3& v) {
|
||||
out << v.x << " " << v.y << " " << v.z;
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
void operator >> (const YAML::Node& node, Vec3& v)
|
||||
void run()
|
||||
{
|
||||
node[0] >> v.x;
|
||||
node[1] >> v.y;
|
||||
node[2] >> v.z;
|
||||
}
|
||||
std::ifstream fin("yaml-reader/tests/test.yaml");
|
||||
|
||||
struct Room {
|
||||
std::string name;
|
||||
Vec3 pos, size;
|
||||
float height;
|
||||
try {
|
||||
YAML::Parser parser(fin);
|
||||
if(!parser)
|
||||
return;
|
||||
|
||||
friend std::ostream& operator << (std::ostream& out, const Room& room) {
|
||||
out << "Name: " << room.name << std::endl;
|
||||
out << "Pos: " << room.pos << std::endl;
|
||||
out << "Size: " << room.size << std::endl;
|
||||
out << "Height: " << room.height << std::endl;
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
void operator >> (const YAML::Node& node, Room& room)
|
||||
{
|
||||
node["name"] >> room.name;
|
||||
node["pos"] >> room.pos;
|
||||
node["size"] >> room.size;
|
||||
node["height"] >> room.height;
|
||||
}
|
||||
|
||||
struct Level {
|
||||
std::vector <Room> rooms;
|
||||
|
||||
friend std::ostream& operator << (std::ostream& out, const Level& level) {
|
||||
for(unsigned i=0;i<level.rooms.size();i++) {
|
||||
out << level.rooms[i];
|
||||
out << "---------------------------------------\n";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
void operator >> (const YAML::Node& node, Level& level)
|
||||
{
|
||||
const YAML::Node& rooms = node["rooms"];
|
||||
for(unsigned i=0;i<rooms.size();i++) {
|
||||
Room room;
|
||||
rooms[i] >> room;
|
||||
level.rooms.push_back(room);
|
||||
YAML::Node doc;
|
||||
parser.GetNextDocument(doc);
|
||||
std::cout << doc;
|
||||
} catch(YAML::Exception&) {
|
||||
std::cout << "Error parsing the yaml!\n";
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
YAML::Test::RunAll();
|
||||
|
||||
//std::ifstream fin("test.yaml");
|
||||
|
||||
//try {
|
||||
// YAML::Parser parser(fin);
|
||||
// if(!parser)
|
||||
// return 0;
|
||||
|
||||
// YAML::Node doc;
|
||||
// parser.GetNextDocument(doc);
|
||||
// std::cout << doc;
|
||||
//} catch(YAML::Exception&) {
|
||||
// std::cout << "Error parsing the yaml!\n";
|
||||
//}
|
||||
{
|
||||
_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
|
||||
Test::RunAll();
|
||||
run();
|
||||
|
||||
getchar();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user