parse.cpp 1.31 KB
Newer Older
1
2
3
#include "yaml-cpp/node/parse.h"
#include "yaml-cpp/node/node.h"
#include "yaml-cpp/node/impl.h"
4
#include "yaml-cpp/parser.h"
5
#include "nodebuilder.h"
6

7
#include <fstream>
8
9
10
11
#include <sstream>

namespace YAML
{
12
	Node Load(const std::string& input) {
13
		std::stringstream stream(input);
14
		return Load(stream);
15
16
	}
	
17
	Node Load(const char *input) {
18
		std::stringstream stream(input);
19
		return Load(stream);
20
21
	}
	
22
	Node Load(std::istream& input) {
23
		Parser parser(input);
24
		NodeBuilder builder;
25
		if(!parser.HandleNextDocument(builder))
26
			return Node();
27
28
29
		
		return builder.Root();
	}
30

31
32
33
34
35
    Node LoadFile(const std::string& filename) {
        std::ifstream fin(filename.c_str());
        return Load(fin);
    }

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
	std::vector<Node> LoadAll(const std::string& input) {
		std::stringstream stream(input);
		return LoadAll(stream);
	}
	
	std::vector<Node> LoadAll(const char *input) {
		std::stringstream stream(input);
		return LoadAll(stream);
	}
	
	std::vector<Node> LoadAll(std::istream& input) {
		std::vector<Node> docs;
		
		Parser parser(input);
		while(1) {
			NodeBuilder builder;
			if(!parser.HandleNextDocument(builder))
				break;
			docs.push_back(builder.Root());
		}
		
		return docs;
	}
59
60
61
62
63

    std::vector<Node> LoadAllFromFile(const std::string& filename) {
        std::ifstream fin(filename.c_str());
        return LoadAll(fin);
    }
64
}