Om
reader.cpp
Go to the documentation of this file.
1 
15 #ifndef Om_Language_Reader_
16 
17  #include "om/language/reader.hpp"
18 
19 #else
20 
24 
25 // MARK: - Om::Language::Reader
26 
27  #define Type_ \
28  Om::Language::Reader
29 
30 // MARK: public (non-static)
31 
32 inline Type_::Reader(
33  Om::Source::Source<CodePoint const> & theCodePointSource
34 ):
35 thisCodePointSource(theCodePointSource),
36 thisDepth(),
37 thisIsEncoded() {}
38 
39 inline Om::CodePoint const & Type_::operator *() const {
40  assert(
41  !this->operator !()
42  );
43  return *this->thisCodePointSource;
44 }
45 
46 inline bool Type_::operator !() const {
47  return (
48  !this->thisCodePointSource ||
49  (
50  !this->thisDepth &&
51  !this->thisIsEncoded &&
52  Symbol::theEndOperandSymbol == *this->thisCodePointSource
53  )
54  );
55 }
56 
57 inline bool Type_::Equals(Reader const & theReader) const {
58  assert(
59  this->thisCodePointSource != theReader.thisCodePointSource ||
60  this->thisDepth == theReader.thisDepth
61  );
62  return this->thisCodePointSource == theReader.thisCodePointSource;
63 }
64 
65 inline void Type_::Pop() {
66  assert(this->thisCodePointSource);
67  switch (*this->thisCodePointSource) {
69  if (this->thisIsEncoded) {
70  this->thisIsEncoded = false;
71  } else {
72  if (
73  static_cast<size_t>(-1) == this->thisDepth
74  ) {
75  throw std::overflow_error("Operand overflow.");
76  }
77  ++this->thisDepth;
78  }
79  break;
81  if (this->thisIsEncoded) {
82  this->thisIsEncoded = false;
83  } else {
84  assert(this->thisDepth);
85  --this->thisDepth;
86  }
87  break;
89  this->thisIsEncoded = !this->thisIsEncoded;
90  break;
91  default:
92  this->thisIsEncoded = false;
93  // Fall through.
94  }
95  this->thisCodePointSource.Pop();
96 }
97 
98 // MARK: - Om::Language::
99 
100 inline bool Om::Language::operator ==(
101  Type_ const & theFirst,
102  Type_ const & theSecond
103 ) {
104  return theFirst.Equals(theSecond);
105 }
106 
107 inline bool Om::Language::operator !=(
108  Type_ const & theFirst,
109  Type_ const & theSecond
110 ) {
111  return !theFirst.Equals(theSecond);
112 }
113 
114  #undef Type_
115 
116 #endif
Any object that items can be pulled from.
Definition: source.hpp:31
bool operator!=(DefaultAtom< TheImplementation > const &, DefaultAtom< TheImplementation > const &)
bool operator==(DefaultAtom< TheImplementation > const &, DefaultAtom< TheImplementation > const &)
boost::locale::utf::code_point CodePoint
A UTF-8 code point.
Definition: code_point.hpp:32
Om header file.
Om header file.
Om header file.
Om header file.