00001 #ifndef STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 00002 #define STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 00003 00004 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 00005 #pragma once 00006 #endif 00007 00008 00009 #include "yaml-cpp-pm/noncopyable.h" 00010 #include <cstddef> 00011 00012 namespace YAML_PM 00013 { 00014 class StreamCharSource 00015 { 00016 public: 00017 StreamCharSource(const Stream& stream): m_offset(0), m_stream(stream) {} 00018 StreamCharSource(const StreamCharSource& source): m_offset(source.m_offset), m_stream(source.m_stream) {} 00019 ~StreamCharSource() {} 00020 00021 operator bool() const; 00022 char operator [] (std::size_t i) const { return m_stream.CharAt(m_offset + i); } 00023 bool operator !() const { return !static_cast<bool>(*this); } 00024 00025 const StreamCharSource operator + (int i) const; 00026 00027 private: 00028 std::size_t m_offset; 00029 const Stream& m_stream; 00030 00031 StreamCharSource& operator = (const StreamCharSource&); // non-assignable 00032 }; 00033 00034 inline StreamCharSource::operator bool() const { 00035 return m_stream.ReadAheadTo(m_offset); 00036 } 00037 00038 inline const StreamCharSource StreamCharSource::operator + (int i) const { 00039 StreamCharSource source(*this); 00040 if(static_cast<int> (source.m_offset) + i >= 0) 00041 source.m_offset += i; 00042 else 00043 source.m_offset = 0; 00044 return source; 00045 } 00046 } 00047 00048 #endif // STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66