Om
expression.hpp
Go to the documentation of this file.
1 
29 #ifndef Om_Language_Expression_
30 
31  #define Om_Language_Expression_ \
32  Om::Language::Expression
33 
34  #include "om/language/form.hpp"
35 
36  #ifndef Om_Macro_Precompilation_
37 
38  #include "boost/optional.hpp"
39 
40  #endif
41 
42  #define Om_Language_Expression_GetName_() \
43  "expression"
44 
45 namespace Om {
46 
47  namespace Language {
48 
49  // MARK: - Om::Language::Expression
50 
55  class Expression:
56  public DefaultProgram<Expression> {
57 
58  public: // MARK: public (static)
59 
60  class ElementRange;
61 
66  template <typename ThisForm>
67  class FormRange;
68 
69  static char const * GetName();
70 
71  public: // MARK: public (non-static)
72 
74 
76 
78 
80 
81  void BackPopTerm();
82 
83  template <typename TheOperand>
84  void BackTakeOperand(TheOperand &);
85 
86  template <typename TheOperator>
87  void BackTakeOperator(TheOperator &);
88 
89  template <typename TheProducer>
90  void BackTakeQuotedProducer(TheProducer &);
91 
92  virtual void Clear();
93 
95 
97 
98  void FrontPopTerm();
99 
100  template <typename TheOperand>
101  void FrontTakeOperand(TheOperand &);
102 
103  template <typename TheOperator>
104  void FrontTakeOperator(TheOperator &);
105 
106  template <typename TheProducer>
107  void FrontTakeQuotedProducer(TheProducer &);
108 
109  virtual std::auto_ptr<
111  > GetElementRange() const;
112 
113  virtual void GiveElements(Consumer &);
114 
115  virtual void GiveElements(Consumer &) const;
116 
117  virtual bool IsEmpty() const;
118 
119  virtual void ParseElements(Reader &);
120 
121  virtual void ParseQuotedElements(Reader &);
122 
123  void Swap(Expression &);
124 
126 
127  void TakeElements(Expression const &);
128 
129  virtual void TakeElements(Producer &);
130 
131  virtual void TakeElements(Producer const &);
132 
133  template <typename TheOperand>
134  void TakeOperand(TheOperand &);
135 
136  template <typename TheOperator>
137  void TakeOperator(TheOperator &);
138 
139  template <typename TheProducer>
140  void TakeQuotedProducer(TheProducer &);
141 
142  template <typename TheSeparator>
143  void TakeSeparator(TheSeparator &);
144 
145  private: // MARK: private (static)
146 
147  typedef std::deque<Form> FormDeque;
148 
157  template <typename TheFormIterator>
158  static void GiveElements(
159  Consumer & theConsumer,
160  TheFormIterator theCurrent,
161  TheFormIterator const theEnd
162  );
163 
164  private: // MARK: private (non-static)
165 
167 
169 
171 
172  };
173 
174  // MARK: - Om::Language::Expression::FormRange<Form>
175 
180  template <>
183  Form,
184  FormDeque::iterator
185  > {
186 
187  public: // MARK: public (non-static)
188 
189  explicit FormRange(Expression &);
190 
191  };
192 
193  // MARK: - Om::Language::Expression::FormRange<Form const>
194 
199  template <>
202  Form const,
203  FormDeque::const_iterator
204  > {
205 
206  public: // MARK: public (non-static)
207 
208  explicit FormRange(Expression const &);
209 
210  };
211 
212  // MARK: - Om::Language::Expression::ElementRange
213 
220  Element const,
221  ElementRange
222  > {
223 
224  public: // MARK: public (non-static)
225 
226  explicit ElementRange(Expression const &);
227 
228  virtual bool operator !() const;
229 
230  virtual Element const & operator *() const;
231 
233  Element const,
235  >::Equals;
236 
237  bool Equals(ElementRange const &) const;
238 
239  void End();
240 
241  virtual void Pop();
242 
243  private: // MARK: private (non-static)
244 
249  FormDeque::const_iterator thisFormIterator;
250 
255  FormDeque::const_iterator thisFormEnd;
256 
261  boost::optional<Form::ElementRange> thisFormElementRange;
262 
263  };
264 
265  // MARK: - Om::Language::
266 
268  Expression::ElementRange const &,
270  );
271 
273  Expression::ElementRange const &,
275  );
276 
277  }
278 
279 }
280 
281 namespace boost {
282 
283  // MARK: - boost::
284 
285  template <>
286  void swap(
289  );
290 
291 }
292 
293  #include "om/language/expression.cpp"
294 
295 #endif
An Element taker; takes at the back.
Definition: consumer.hpp:42
A partial implementation of Program.
A Program that contains a single elemental item (or none, when IsEmpty() returns true).
Definition: element.hpp:33
An Expression Element range.
Definition: expression.hpp:222
FormDeque::const_iterator thisFormEnd
The FormDeque end.
Definition: expression.hpp:255
boost::optional< Form::ElementRange > thisFormElementRange
The Element range for the current Form.
Definition: expression.hpp:261
FormDeque::const_iterator thisFormIterator
The FormDeque iterator.
Definition: expression.hpp:249
virtual Element const & operator*() const
bool Equals(ElementRange const &) const
virtual void Pop()
Pops the current item.
An Expression Form range.
Definition: expression.hpp:67
The Expression Program implementation.
Definition: expression.hpp:56
void TakeElements(Expression &)
virtual bool IsEmpty() const
static void GiveElements(Consumer &theConsumer, TheFormIterator theCurrent, TheFormIterator const theEnd)
Expression & operator=(Expression)
void BackTakeOperand(TheOperand &)
virtual void GiveElements(Consumer &)
void TakeSeparator(TheSeparator &)
static char const * GetName()
virtual void TakeElements(Producer const &)
This is an overloaded member function, provided for convenience. It differs from the above function o...
virtual void ParseElements(Reader &)
void TakeElements(Expression const &)
void FrontTakeOperand(TheOperand &)
void FrontTakeQuotedProducer(TheProducer &)
virtual std::auto_ptr< Om::Source::Source< Element const > > GetElementRange() const
void FrontGiveTerm(Consumer &)
void TakeQuotedProducer(TheProducer &)
void FrontGiveForm(Consumer &)
void FrontTakeOperator(TheOperator &)
std::deque< Form > FormDeque
Definition: expression.hpp:147
virtual void TakeElements(Producer &)
Takes each Element of the argument.
void BackTakeOperator(TheOperator &)
void TakeOperator(TheOperator &)
void TakeOperand(TheOperand &)
virtual void GiveElements(Consumer &) const
void BackTakeQuotedProducer(TheProducer &)
void Swap(Expression &)
void BackGiveForm(Consumer &)
void BackGiveTerm(Consumer &)
virtual void ParseQuotedElements(Reader &)
An Operator (which may be empty), followed by zero or more Operand instances.
Definition: form.hpp:33
An Element giver; gives from the front.
Definition: producer.hpp:40
Produces each CodePoint until the end of the Source.
Definition: reader.hpp:37
A range over a collection, starting from the front.
A partial implementation of Source.
Any object that items can be pulled from.
Definition: source.hpp:31
Om source file.
Om header file.
bool operator!=(DefaultAtom< TheImplementation > const &, DefaultAtom< TheImplementation > const &)
bool operator==(DefaultAtom< TheImplementation > const &, DefaultAtom< TheImplementation > const &)
The Om library.
Definition: code_point.hpp:26
void swap(Om::Language::Expression &, Om::Language::Expression &)