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

#include <ios>
#include <string>

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

		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); }
16
		Buffer& operator ++ () { ++buffer; --size; return *this; }
17

18
		const char *buffer;
19
20
21
		int size;
	};

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

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

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

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