1 #ifndef STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
2 #define STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
4 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
9 #include "yaml-cpp/noncopyable.h"
10 #include "yaml-cpp/mark.h"
20 class Stream
: private noncopyable
23 friend class StreamCharSource
;
25 Stream(std::istream
& input
);
28 operator bool() const;
29 bool operator !() const { return !static_cast <bool>(*this); }
33 std::string
get(int n
);
36 static char eof() { return 0x04; }
38 const Mark
mark() const { return m_mark
; }
39 int pos() const { return m_mark
.pos
; }
40 int line() const { return m_mark
.line
; }
41 int column() const { return m_mark
.column
; }
42 void ResetColumn() { m_mark
.column
= 0; }
45 enum CharacterSet
{utf8
, utf16le
, utf16be
, utf32le
, utf32be
};
47 std::istream
& m_input
;
50 CharacterSet m_charSet
;
51 mutable std::deque
<char> m_readahead
;
52 unsigned char* const m_pPrefetched
;
53 mutable size_t m_nPrefetchedAvailable
;
54 mutable size_t m_nPrefetchedUsed
;
56 void AdvanceCurrent();
57 char CharAt(size_t i
) const;
58 bool ReadAheadTo(size_t i
) const;
59 bool _ReadAheadTo(size_t i
) const;
60 void StreamInUtf8() const;
61 void StreamInUtf16() const;
62 void StreamInUtf32() const;
63 unsigned char GetNextByte() const;
68 inline char Stream::CharAt(size_t i
) const {
69 return m_readahead
[i
];
72 inline bool Stream::ReadAheadTo(size_t i
) const {
73 if(m_readahead
.size() > i
)
75 return _ReadAheadTo(i
);
79 #endif // STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66