1 #ifndef STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 #define STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 4 #if defined(_MSC_VER) || \ 5 (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 #pragma once 8 #endif 9 10 #include "yaml-cpp/noncopyable.h" 11 #include "yaml-cpp/mark.h" 12 #include <cstddef> 13 #include <deque> 14 #include <ios> 15 #include <iostream> 16 #include <set> 17 #include <string> 18 19 namespace YAML { 20 class Stream : private noncopyable { 21 public: 22 friend class StreamCharSource; 23 24 Stream(std::istream& input); 25 ~Stream(); 26 27 operator bool() const; 28 bool operator!() const { return !static_cast<bool>(*this); } 29 30 char peek() const; 31 char get(); 32 std::string get(int n); 33 void eat(int n = 1); 34 eof()35 static char eof() { return 0x04; } 36 mark()37 const Mark mark() const { return m_mark; } pos()38 int pos() const { return m_mark.pos; } line()39 int line() const { return m_mark.line; } column()40 int column() const { return m_mark.column; } ResetColumn()41 void ResetColumn() { m_mark.column = 0; } 42 43 private: 44 enum CharacterSet { utf8, utf16le, utf16be, utf32le, utf32be }; 45 46 std::istream& m_input; 47 Mark m_mark; 48 49 CharacterSet m_charSet; 50 mutable std::deque<char> m_readahead; 51 unsigned char* const m_pPrefetched; 52 mutable size_t m_nPrefetchedAvailable; 53 mutable size_t m_nPrefetchedUsed; 54 55 void AdvanceCurrent(); 56 char CharAt(size_t i) const; 57 bool ReadAheadTo(size_t i) const; 58 bool _ReadAheadTo(size_t i) const; 59 void StreamInUtf8() const; 60 void StreamInUtf16() const; 61 void StreamInUtf32() const; 62 unsigned char GetNextByte() const; 63 }; 64 65 // CharAt 66 // . Unchecked access CharAt(size_t i)67inline char Stream::CharAt(size_t i) const { return m_readahead[i]; } 68 ReadAheadTo(size_t i)69inline bool Stream::ReadAheadTo(size_t i) const { 70 if (m_readahead.size() > i) 71 return true; 72 return _ReadAheadTo(i); 73 } 74 } 75 76 #endif // STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66 77