00001 #ifndef STRINGSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 00002 #define STRINGSOURCE_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 <cstddef> 00010 00011 namespace YAML_PM 00012 { 00013 class StringCharSource 00014 { 00015 public: 00016 StringCharSource(const char *str, std::size_t size): m_str(str), m_size(size), m_offset(0) {} 00017 00018 operator bool() const { return m_offset < m_size; } 00019 char operator [] (std::size_t i) const { return m_str[m_offset + i]; } 00020 bool operator !() const { return !static_cast<bool>(*this); } 00021 00022 const StringCharSource operator + (int i) const { 00023 StringCharSource source(*this); 00024 if(static_cast<int> (source.m_offset) + i >= 0) 00025 source.m_offset += i; 00026 else 00027 source.m_offset = 0; 00028 return source; 00029 } 00030 00031 StringCharSource& operator ++ () { 00032 ++m_offset; 00033 return *this; 00034 } 00035 00036 StringCharSource& operator += (std::size_t offset) { 00037 m_offset += offset; 00038 return *this; 00039 } 00040 private: 00041 const char *m_str; 00042 std::size_t m_size; 00043 std::size_t m_offset; 00044 }; 00045 } 00046 00047 #endif // STRINGSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66