streamcharsource.h (1577B)
1 #ifndef STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 #define STREAMCHARSOURCE_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/noexcept.h" 11 #include "stream.h" 12 #include <cstddef> 13 14 namespace YAML { 15 16 class StreamCharSource { 17 public: 18 StreamCharSource(const Stream& stream) : m_offset(0), m_stream(stream) {} 19 StreamCharSource(const StreamCharSource& source) = default; 20 StreamCharSource(StreamCharSource&&) YAML_CPP_NOEXCEPT = default; 21 StreamCharSource& operator=(const StreamCharSource&) = delete; 22 StreamCharSource& operator=(StreamCharSource&&) = delete; 23 ~StreamCharSource() = default; 24 25 operator bool() const; 26 char operator[](std::size_t i) const { return m_stream.CharAt(m_offset + i); } 27 bool operator!() const { return !static_cast<bool>(*this); } 28 29 const StreamCharSource operator+(int i) const; 30 31 private: 32 std::size_t m_offset; 33 const Stream& m_stream; 34 }; 35 36 inline StreamCharSource::operator bool() const { 37 return m_stream.ReadAheadTo(m_offset); 38 } 39 40 inline const StreamCharSource StreamCharSource::operator+(int i) const { 41 StreamCharSource source(*this); 42 if (static_cast<int>(source.m_offset) + i >= 0) 43 source.m_offset += static_cast<std::size_t>(i); 44 else 45 source.m_offset = 0; 46 return source; 47 } 48 } // namespace YAML 49 50 #endif // STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66