Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #ifndef STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66
0002 #define STREAMCHARSOURCE_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/noexcept.h"
0011 #include "stream.h"
0012 #include <cstddef>
0013 
0014 namespace SHERPA_YAML {
0015 
0016 class StreamCharSource {
0017  public:
0018   StreamCharSource(const Stream& stream) : m_offset(0), m_stream(stream) {}
0019   StreamCharSource(const StreamCharSource& source) = default;
0020   StreamCharSource(StreamCharSource&&) YAML_CPP_NOEXCEPT = default;
0021   StreamCharSource& operator=(const StreamCharSource&) = delete;
0022   StreamCharSource& operator=(StreamCharSource&&) = delete;
0023   ~StreamCharSource() = default;
0024 
0025   operator bool() const;
0026   char operator[](std::size_t i) const { return m_stream.CharAt(m_offset + i); }
0027   bool operator!() const { return !static_cast<bool>(*this); }
0028 
0029   const StreamCharSource operator+(int i) const;
0030 
0031  private:
0032   std::size_t m_offset;
0033   const Stream& m_stream;
0034 };
0035 
0036 inline StreamCharSource::operator bool() const {
0037   return m_stream.ReadAheadTo(m_offset);
0038 }
0039 
0040 inline const StreamCharSource StreamCharSource::operator+(int i) const {
0041   StreamCharSource source(*this);
0042   if (static_cast<int>(source.m_offset) + i >= 0)
0043     source.m_offset += static_cast<std::size_t>(i);
0044   else
0045     source.m_offset = 0;
0046   return source;
0047 }
0048 }  // namespace SHERPA_YAML
0049 
0050 #endif  // STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66