streamcharsource.h
Go to the documentation of this file.
1 #ifndef STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
2 #define STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
3 
4 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
5 #pragma once
6 #endif
7 
8 
10 #include <cstddef>
11 
12 namespace YAML_PM
13 {
15  {
16  public:
17  StreamCharSource(const Stream& stream): m_offset(0), m_stream(stream) {}
20 
21  operator bool() const;
22  char operator [] (std::size_t i) const { return m_stream.CharAt(m_offset + i); }
23  bool operator !() const { return !static_cast<bool>(*this); }
24 
25  const StreamCharSource operator + (int i) const;
26 
27  private:
28  std::size_t m_offset;
29  const Stream& m_stream;
30 
31  StreamCharSource& operator = (const StreamCharSource&); // non-assignable
32  };
33 
34  inline StreamCharSource::operator bool() const {
35  return m_stream.ReadAheadTo(m_offset);
36  }
37 
38  inline const StreamCharSource StreamCharSource::operator + (int i) const {
39  StreamCharSource source(*this);
40  if(static_cast<int> (source.m_offset) + i >= 0)
41  source.m_offset += i;
42  else
43  source.m_offset = 0;
44  return source;
45  }
46 }
47 
48 #endif // STREAMCHARSOURCE_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
YAML_PM::StreamCharSource::operator+
const StreamCharSource operator+(int i) const
Definition: streamcharsource.h:38
YAML_PM::Stream::CharAt
char CharAt(size_t i) const
Definition: stream.h:68
YAML_PM
Definition: aliasmanager.h:11
YAML_PM::StreamCharSource
Definition: streamcharsource.h:14
YAML_PM::StreamCharSource::operator!
bool operator!() const
Definition: streamcharsource.h:23
YAML_PM::StreamCharSource::StreamCharSource
StreamCharSource(const StreamCharSource &source)
Definition: streamcharsource.h:18
YAML_PM::StreamCharSource::~StreamCharSource
~StreamCharSource()
Definition: streamcharsource.h:19
YAML_PM::StreamCharSource::m_stream
const Stream & m_stream
Definition: streamcharsource.h:29
YAML_PM::StreamCharSource::m_offset
std::size_t m_offset
Definition: streamcharsource.h:28
noncopyable.h
YAML_PM::StreamCharSource::operator=
StreamCharSource & operator=(const StreamCharSource &)
YAML_PM::Stream
Definition: stream.h:20
YAML_PM::StreamCharSource::operator[]
char operator[](std::size_t i) const
Definition: streamcharsource.h:22
YAML_PM::StreamCharSource::StreamCharSource
StreamCharSource(const Stream &stream)
Definition: streamcharsource.h:17


mp2p_icp
Author(s):
autogenerated on Fri Dec 20 2024 03:46:00