parse.cpp 723 Bytes
Newer Older
1
#include "yaml-cpp/yaml.h"
2
3
#include <fstream>
#include <iostream>
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <vector>

struct Params {
	bool hasFile;
	std::string fileName;
};

Params ParseArgs(int argc, char **argv) {
	Params p;

	std::vector<std::string> args(argv + 1, argv + argc);
	
	return p;
}
18
19
20

int main(int argc, char **argv)
{
21
22
	Params p = ParseArgs(argc, argv);

23
24
25
26
27
	std::ifstream fin;
	if(argc > 1)
		fin.open(argv[1]);
	
	std::istream& input = (argc > 1 ? fin : std::cin);
28
	try {
29
		YAML::Parser parser(input);
30
31
		YAML::Node doc;
		while(parser.GetNextDocument(doc)) {
32
33
34
//			YAML::Emitter emitter;
//			emitter << doc;
//			std::cout << emitter.c_str() << "\n";
35
		}
36
	} catch(const YAML::Exception& e) {
37
		std::cerr << e.what() << "\n";
38
39
40
	}
	return 0;
}