Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-05-12 09:08:10

0001 #ifndef STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
0002 #define STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
0003 
0004 #if defined(_MSC_VER) ||                                            \
0005     (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
0006      (__GNUC__ >= 4))  // GCC supports "pragma once" correctly since 3.4
0007 #pragma once
0008 #endif
0009 
0010 #include "ATOOLS/YAML/yaml-cpp/mark.h"
0011 #include <cstddef>
0012 #include <deque>
0013 #include <ios>
0014 #include <iostream>
0015 #include <set>
0016 #include <string>
0017 
0018 namespace SHERPA_YAML {
0019 
0020 class StreamCharSource;
0021 
0022 class Stream {
0023  public:
0024   friend class StreamCharSource;
0025 
0026   Stream(std::istream& input);
0027   Stream(const Stream&) = delete;
0028   Stream(Stream&&) = delete;
0029   Stream& operator=(const Stream&) = delete;
0030   Stream& operator=(Stream&&) = delete;
0031   ~Stream();
0032 
0033   operator bool() const;
0034   bool operator!() const { return !static_cast<bool>(*this); }
0035 
0036   char peek() const;
0037   char get();
0038   std::string get(int n);
0039   void eat(int n = 1);
0040 
0041   static char eof() { return 0x04; }
0042 
0043   const Mark mark() const { return m_mark; }
0044   int pos() const { return m_mark.pos; }
0045   int line() const { return m_mark.line; }
0046   int column() const { return m_mark.column; }
0047   void ResetColumn() { m_mark.column = 0; }
0048 
0049  private:
0050   enum CharacterSet { utf8, utf16le, utf16be, utf32le, utf32be };
0051 
0052   std::istream& m_input;
0053   Mark m_mark;
0054 
0055   CharacterSet m_charSet;
0056   mutable std::deque<char> m_readahead;
0057   unsigned char* const m_pPrefetched;
0058   mutable size_t m_nPrefetchedAvailable;
0059   mutable size_t m_nPrefetchedUsed;
0060 
0061   void AdvanceCurrent();
0062   char CharAt(size_t i) const;
0063   bool ReadAheadTo(size_t i) const;
0064   bool _ReadAheadTo(size_t i) const;
0065   void StreamInUtf8() const;
0066   void StreamInUtf16() const;
0067   void StreamInUtf32() const;
0068   unsigned char GetNextByte() const;
0069 };
0070 
0071 // CharAt
0072 // . Unchecked access
0073 inline char Stream::CharAt(size_t i) const { return m_readahead[i]; }
0074 
0075 inline bool Stream::ReadAheadTo(size_t i) const {
0076   if (m_readahead.size() > i)
0077     return true;
0078   return _ReadAheadTo(i);
0079 }
0080 }  // namespace SHERPA_YAML
0081 
0082 #endif  // STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66