stream.h 862 Bytes
Newer Older
1
2
3
4
5
6
7
#pragma once

#include <ios>
#include <string>

namespace YAML
{
8
9
10
11
12
13
14
15
16
17
18
19
20
	// a simple buffer wrapper that knows how big it is
	struct Buffer {
		Buffer(char *b, int s): buffer(b), size(s) {}

		operator bool() const { return size > 0; }
		bool operator !() const { return !static_cast <bool> (*this); }
		char operator [] (int i) const { return buffer[i]; }
		const Buffer operator + (int offset) const { return Buffer(buffer + offset, size - offset); }

		char *buffer;
		int size;
	};

21
	class Stream
22
	{
23
24
25
	public:
		Stream(std::istream& input);
		~Stream();
26

27
28
		operator bool() const;
		bool operator !() const { return !static_cast <bool>(*this); }
29

30
		const Buffer current() const { return Buffer(buffer + pos, size - pos); }
31
32
33
34
35
		char peek();
		char get();
		std::string get(int n);
		void eat(int n = 1);

36
37
38
39
		int pos, line, column, size;
	
	private:
		char *buffer;
40
41
	};
}