1#ifndef STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
2#define STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
3
4#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
5#pragma once
6#endif
7
8
9#include "yaml-cpp/noncopyable.h"
10#include <cstddef>
11
12namespace YAML
13{
14	class StreamCharSource
15	{
16	public:
17		StreamCharSource(const Stream& stream): m_offset(0), m_stream(stream) {}
18		StreamCharSource(const StreamCharSource& source): m_offset(source.m_offset), m_stream(source.m_stream) {}
19		~StreamCharSource() {}
20
21		operator bool() const;
22		char operator [] (std::size_t i) const { return m_stream.CharAt(m_offset + i); }
23		bool operator !() const { return !static_cast<bool>(*this); }
24
25		const StreamCharSource operator + (int i) const;
26
27	private:
28		std::size_t m_offset;
29		const Stream& m_stream;
30
31		StreamCharSource& operator = (const StreamCharSource&); // non-assignable
32	};
33
34	inline StreamCharSource::operator bool() const {
35		return m_stream.ReadAheadTo(m_offset);
36	}
37
38	inline const StreamCharSource StreamCharSource::operator + (int i) const {
39		StreamCharSource source(*this);
40		if(static_cast<int> (source.m_offset) + i >= 0)
41			source.m_offset += i;
42		else
43			source.m_offset = 0;
44		return source;
45	}
46}
47
48#endif // STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
49