Om
find_operation.cpp
Go to the documentation of this file.
1 
15 #ifndef Om_Language_Operation_FindOperation_
16 
18 
19  #ifdef Om_Macro_Test_
20 
21  #ifndef Om_Macro_Precompilation_
22 
23  #include "boost/test/unit_test.hpp"
24 
25  #endif
26 
27 namespace Om {
28 
29  namespace Language {
30 
31  namespace Operation {
32 
33  BOOST_AUTO_TEST_SUITE(FindOperationTest)
34 
35  BOOST_AUTO_TEST_CASE(DefinitionTest) {
36  BOOST_CHECK_EQUAL(
37  "{find}",
38  System::Get().Evaluate("drop find {find} system")
39  );
40  }
41 
42  BOOST_AUTO_TEST_CASE(SimpleTest) {
43  BOOST_CHECK_EQUAL(
44  (
45  "{"
46  "b{B}\n"
47  "a{A}"
48  "}{a{A}}"
49  ),
50  System::Get().Evaluate("find {a}{b{B} a{A}}")
51  );
52 
53  BOOST_CHECK_EQUAL(
54  (
55  "{"
56  "b{B}\n"
57  "a{A}"
58  "}{a{A}}"
59  ),
60  System::Get().Evaluate("find {a}lexicon{b{B} a{A}}")
61  );
62 
63  BOOST_CHECK_EQUAL(
64  "{}{}",
65  System::Get().Evaluate("find {a}lexicon{}")
66  );
67 
68  BOOST_CHECK_EQUAL(
69  (
70  "{"
71  "b{B}\n"
72  "a{A}"
73  "}{}"
74  ),
75  System::Get().Evaluate("find {c}{b{B} a{A}}")
76  );
77 
78  BOOST_CHECK_EQUAL(
79  (
80  "{"
81  "b{B}\n"
82  "a{A}\n"
83  "{C}"
84  "}{}"
85  ),
86  System::Get().Evaluate("find {c}{b{B} a{A} {C}}")
87  );
88 
89  BOOST_CHECK_EQUAL(
90  (
91  "{"
92  "b{B}\n"
93  "a{A}\n"
94  "{C}"
95  "}{{C}}"
96  ),
97  System::Get().Evaluate("find {}{b{B} a{A} {C}}")
98  );
99 
100  BOOST_CHECK_EQUAL(
101  (
102  "{"
103  "b{B}\n"
104  "a{A}\n"
105  "c"
106  "}{c}"
107  ),
108  System::Get().Evaluate("find {c}{b{B} a{A} c}")
109  );
110 
111  BOOST_CHECK_EQUAL(
112  (
113  "{"
114  "b{B}\n"
115  "a{A}\n"
116  "c{}"
117  "}{c{}}"
118  ),
119  System::Get().Evaluate("find {c}{b{B} a{A} c{}}")
120  );
121  }
122 
123  BOOST_AUTO_TEST_SUITE_END()
124 
125  }
126 
127  }
128 
129 }
130 
131  #endif
132 
133 #else
134 
135  #include "om/language/lexicon.hpp"
136 
137  #ifndef Om_Macro_Precompilation_
138 
139  #include "boost/utility/in_place_factory.hpp"
140 
141  #endif
142 
143 // MARK: - Om::Language::Operation::FindOperation
144 
145  #define Type_ \
146  Om::Language::Operation::FindOperation
147 
148 // MARK: public (static)
149 
150 inline char const * Type_::GetName() {
152 }
153 
154 template <typename TheFindOperation>
155 inline void Type_::GiveElements(
156  TheFindOperation & theFindOperation,
157  Consumer & theConsumer
158 ) {
159  theConsumer.TakeElement(
160  GetOperator()
161  );
162  if (theFindOperation.thisOperator) {
163  theConsumer.TakeQuotedElements(*theFindOperation.thisOperator);
164  }
165 }
166 
167 // MARK: public (non-static)
168 
169 inline Type_::FindOperation():
170 thisOperator() {}
171 
172 template <typename TheOperand>
173 inline bool Type_::TakeOperand(
174  Evaluation & theEvaluation,
175  TheOperand & theOperand
176 ) {
177  assert(
178  !theOperand.IsEmpty()
179  );
180  return this->TakeQuotedProducer(
181  theEvaluation,
182  *theOperand.GetProgram()
183  );
184 }
185 
186 template <typename TheProducer>
187 inline bool Type_::TakeQuotedProducer(
188  Evaluation & theEvaluation,
189  TheProducer & theProducer
190 ) {
191  if (this->thisOperator) {
192  Lexicon theLexicon;
193  theLexicon.TakeElements(theProducer);
194 
195  Expression theExpression;
196  theLexicon.Find(*this->thisOperator).GiveElements(theExpression);
197 
198  theEvaluation.TakeQuotedProducer(theExpression);
199  theEvaluation.TakeQuotedProducer(theLexicon);
200  return true;
201  }
202  this->thisOperator = boost::in_place();
203  assert(this->thisOperator);
204  this->thisOperator->TakeElements(theProducer);
205  return false;
206 }
207 
208  #undef Type_
209 
210 #endif
static System & Get()
Om header file.
#define Om_Language_Operation_FindOperation_GetName_()
Om header file.
The Om library.
Definition: code_point.hpp:26