Om
operand.cpp
Go to the documentation of this file.
1 
15 #ifndef Om_Language_Operand_
16 
17  #include "om/language/operand.hpp"
18 
19 #else
20 
21  #include "om/language/literal.hpp"
22  #include "om/language/null.hpp"
23 
24 // MARK: - Om::Language::Operand
25 
26  #define Type_ \
27  Om::Language::Operand
28 
29 // MARK: public (static)
30 
31 inline char const * Type_::GetName() {
33 }
34 
35 // MARK: public (non-static)
36 
37 inline Type_::Operand():
38 thisProgram() {}
39 
40 template <typename TheProgram>
41 inline Type_::Operand(
42  std::auto_ptr<TheProgram> theProgram
43 ):
44 thisProgram(theProgram) {}
45 
46 inline Type_ & Type_::operator =(Operand theOperand) {
47  this->Swap(theOperand);
48  return *this;
49 }
50 
51 inline Om::Language::Program & Type_::operator *() {
52  return (
53  this->thisProgram.IsEmpty() ?
54  Null::Get() :
55  *this->thisProgram
56  );
57 }
58 
59 inline Om::Language::Program const & Type_::operator *() const {
60  return (
61  this->thisProgram.IsEmpty() ?
62  Null::Get() :
63  *this->thisProgram
64  );
65 }
66 
67 inline void Type_::Clear() {
68  this->thisProgram.Clear();
69 }
70 
71 inline bool Type_::Equals(Operand const & theOperand) const {
72  return (
73  this->IsEmpty() ?
74  theOperand.IsEmpty() :
75  *this->GetProgram() == *theOperand.GetProgram()
76  );
77 }
78 
79 inline Om::Language::Program * Type_::GetProgram() {
80  return this->thisProgram.GetValue();
81 }
82 
83 inline Om::Language::Program const * Type_::GetProgram() const {
84  return this->thisProgram.GetValue();
85 }
86 
87 inline bool Type_::IsEmpty() const {
88  return !this->thisProgram;
89 }
90 
91 inline void Type_::ParseElements(Reader & theReader) {
92  if (
93  this->IsEmpty()
94  ) {
95  for (
96  ;
97  ;
98  theReader.Pop()
99  ) {
100  if (!theReader) {
101  return;
102  }
103  assert(Symbol::theEndOperandSymbol != *theReader);
104  switch (*theReader) {
105  default:
106  continue;
108  theReader.Pop();
109  {
110  // Ensure against copy constructor call.
111  Om::Source::Source<CodePoint const> & theCodePointSource = theReader;
112 
113  Reader theOperandReader(theCodePointSource);
114  this->ParseQuotedElements(theOperandReader);
115  }
116  assert(
117  !theReader ||
118  Symbol::theEndOperandSymbol == *theReader
119  );
120  // Fall through.
121  }
122  break;
123  }
124  }
125 
126  for (
127  ;
128  theReader;
129  theReader.Pop()
130  ) {}
131 }
132 
133 inline void Type_::ParseQuotedElements(Reader & theReader) {
134  Literal theLiteral;
135  theLiteral.ParseElements(theReader);
136  this->TakeQuotedProducer(theLiteral);
137 }
138 
139 template <typename TheProgram>
140 inline void Type_::SetProgram(
141  std::auto_ptr<TheProgram> theProgram
142 ) {
143  this->thisProgram.SetValue(theProgram);
144 }
145 
146 inline void Type_::Swap(Operand & theOperand) {
147  this->thisProgram.Swap(theOperand.thisProgram);
148 }
149 
150 inline void Type_::TakeElements(Producer & theProducer) {
151  if (
152  this->IsEmpty()
153  ) {
155  }
156 }
157 
158 inline void Type_::TakeElements(Producer const & theProducer) {
159  if (
160  this->IsEmpty()
161  ) {
163  }
164 }
165 
166 template <typename TheOperand>
167 inline void Type_::TakeOperand(TheOperand & theOperand) {
168  if (
169  this->IsEmpty()
170  ) {
171  this->Take(theOperand);
172  }
173 }
174 
175 template <typename TheOperator>
176 inline void Type_::TakeOperator(TheOperator &) {}
177 
178 template <typename TheProducer>
179 inline void Type_::TakeQuotedProducer(TheProducer & theProducer) {
180  if (
181  this->IsEmpty()
182  ) {
183  this->SetProgram(
184  theProducer.GiveProgram()
185  );
186  }
187 }
188 
189 template <typename TheSeparator>
190 inline void Type_::TakeSeparator(TheSeparator &) {}
191 
192 // MARK: - Om::Language::
193 
194 inline bool Om::Language::operator ==(
195  Type_ const & theFirst,
196  Type_ const & theSecond
197 ) {
198  return theFirst.Equals(theSecond);
199 }
200 
201 inline bool Om::Language::operator !=(
202  Type_ const & theFirst,
203  Type_ const & theSecond
204 ) {
205  return !theFirst.Equals(theSecond);
206 }
207 
208 // MARK: - boost::
209 
210 template <>
211 inline void boost::swap(
212  Type_ & theFirst,
213  Type_ & theSecond
214 ) {
215  theFirst.Swap(theSecond);
216 }
217 
218  #undef Type_
219 
220 #endif
virtual void TakeElements(Producer &)
Takes each Element of the argument.
The Program implementation.
Definition: program.hpp:62
virtual void Clear()=0
Any object that items can be pulled from.
Definition: source.hpp:31
Om header file.
bool operator!=(DefaultAtom< TheImplementation > const &, DefaultAtom< TheImplementation > const &)
bool operator==(DefaultAtom< TheImplementation > const &, DefaultAtom< TheImplementation > const &)
void swap(Om::Language::Expression &, Om::Language::Expression &)
Om header file.
Om header file.
#define Om_Language_Operand_GetName_()
Definition: operand.hpp:40