2009-07-30 02:27:20 +04:00
|
|
|
#ifndef STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
|
|
|
|
#define STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
|
|
|
|
|
2014-03-22 21:49:16 +04:00
|
|
|
#if defined(_MSC_VER) || \
|
|
|
|
|
(defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
|
|
|
|
|
(__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
2011-03-02 09:11:41 +03:00
|
|
|
#pragma once
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-10-18 11:05:53 +04:00
|
|
|
#include "yaml-cpp/noncopyable.h"
|
2009-07-10 07:10:03 +04:00
|
|
|
#include <cstddef>
|
|
|
|
|
|
2014-03-22 21:49:16 +04:00
|
|
|
namespace YAML {
|
|
|
|
|
class StreamCharSource {
|
|
|
|
|
public:
|
2016-11-26 02:54:50 +03:00
|
|
|
StreamCharSource(const Stream& stream) : m_offset(0), m_stream(stream) {
|
|
|
|
|
if (m_stream.ReadAheadTo(0)){
|
|
|
|
|
m_char = m_stream.peek();
|
|
|
|
|
} else {
|
|
|
|
|
m_char = Stream::eof();
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-03-22 21:49:16 +04:00
|
|
|
~StreamCharSource() {}
|
|
|
|
|
|
2016-11-26 02:54:50 +03:00
|
|
|
inline operator bool() const { return m_char != Stream::eof(); }
|
|
|
|
|
|
2014-03-22 21:49:16 +04:00
|
|
|
char operator[](std::size_t i) const { return m_stream.CharAt(m_offset + i); }
|
2016-11-26 02:54:50 +03:00
|
|
|
|
|
|
|
|
char get() const { return m_char; }
|
|
|
|
|
|
2014-03-22 21:49:16 +04:00
|
|
|
bool operator!() const { return !static_cast<bool>(*this); }
|
|
|
|
|
|
2016-11-26 02:54:50 +03:00
|
|
|
const StreamCharSource operator+(int i) const {
|
|
|
|
|
return StreamCharSource(
|
|
|
|
|
*this, (static_cast<int>(m_offset) + i >= 0) ? m_offset + 1 : 0);
|
|
|
|
|
}
|
2014-03-22 21:49:16 +04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::size_t m_offset;
|
|
|
|
|
const Stream& m_stream;
|
2016-11-26 02:54:50 +03:00
|
|
|
char m_char;
|
2014-03-22 21:49:16 +04:00
|
|
|
|
|
|
|
|
StreamCharSource& operator=(const StreamCharSource&); // non-assignable
|
|
|
|
|
|
2016-11-26 02:54:50 +03:00
|
|
|
StreamCharSource(const StreamCharSource& source, size_t offset)
|
|
|
|
|
: m_offset(offset), m_stream(source.m_stream) {
|
2014-03-22 21:49:16 +04:00
|
|
|
|
2016-11-26 02:54:50 +03:00
|
|
|
if (m_stream.ReadAheadTo(m_offset)) {
|
|
|
|
|
m_char = m_stream.CharAt(m_offset);
|
|
|
|
|
} else {
|
|
|
|
|
m_char = Stream::eof();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2009-07-10 07:10:03 +04:00
|
|
|
}
|
2009-07-30 02:27:20 +04:00
|
|
|
|
2014-03-22 21:49:16 +04:00
|
|
|
#endif // STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|