Om
fill_operation.cpp
Go to the documentation of this file.
1 
15 #ifndef Om_Language_Operation_FillOperation_
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(FillOperationTest)
34 
35  BOOST_AUTO_TEST_CASE(DefinitionTest) {
36  BOOST_CHECK_EQUAL(
37  "{fill}",
38  System::Get().Evaluate("drop find {fill} system")
39  );
40  }
41 
42  BOOST_AUTO_TEST_CASE(GeneralTest) {
43  BOOST_CHECK_EQUAL(
44  (
45  "{"
46  "a{A}\n"
47  "b{B}\n"
48  "c{C}"
49  "}{Unused}"
50  ),
51  System::Get().Evaluate("fill{a b{B} c}{A}{C}{Unused}")
52  );
53 
54  BOOST_CHECK_EQUAL(
55  "{}{A}{B}",
56  System::Get().Evaluate("fill{}{A}{B}")
57  );
58 
59  BOOST_CHECK_EQUAL(
60  "{{Used}}{A}{B}",
61  System::Get().Evaluate("fill{{Used}}{A}{B}")
62  );
63  }
64 
65  BOOST_AUTO_TEST_CASE(EarlyTerminationTest) {
66  BOOST_CHECK_EQUAL(
67  (
68  "fill{"
69  "a{A}\n"
70  "b{B}\n"
71  "c"
72  "}"
73  ),
74  System::Get().Evaluate("fill{a b{B} c}{A}}{C}{Unused}")
75  );
76 
77  BOOST_CHECK_EQUAL(
78  "fill",
79  System::Get().Evaluate("fill}")
80  );
81  }
82 
83  BOOST_AUTO_TEST_SUITE_END()
84 
85  }
86 
87  }
88 
89 }
90 
91  #endif
92 
93 #else
94 
95  #ifndef Om_Macro_Precompilation_
96 
97  #include "boost/utility/in_place_factory.hpp"
98 
99  #endif
100 
101 // MARK: - Om::Language::Operation::FillOperation
102 
103  #define Type_ \
104  Om::Language::Operation::FillOperation
105 
106 // MARK: public (static)
107 
108 inline char const * Type_::GetName() {
110 }
111 
112 template <typename TheFillOperation>
113 inline void Type_::GiveElements(
114  TheFillOperation & theFillOperation,
115  Consumer & theConsumer
116 ) {
117  theConsumer.TakeElement(
118  GetOperator()
119  );
120  if (theFillOperation.thisFormRange) {
121  theConsumer.TakeQuotedElements(theFillOperation.thisExpression);
122  }
123 }
124 
125 // MARK: public (non-static)
126 
127 inline Type_::FillOperation():
128 thisExpression(),
129 thisFormRange() {}
130 
131 template <typename TheOperand>
132 inline bool Type_::TakeOperand(
133  Evaluation & theEvaluation,
134  TheOperand & theOperand
135 ) {
136  assert(
137  !theOperand.IsEmpty()
138  );
139  return this->TakeQuotedProducer(
140  theEvaluation,
141  *theOperand.GetProgram()
142  );
143 }
144 
145 template <typename TheProducer>
146 inline bool Type_::TakeQuotedProducer(
147  Evaluation & theEvaluation,
148  TheProducer & theProducer
149 ) {
150  if (this->thisFormRange) {
151  FormRange & theFormRange = *this->thisFormRange;
152  assert(
153  theFormRange &&
154  !this->thisExpression.IsEmpty()
155  );
156  assert(
157  !Form::OperandRange<Operand const>(*theFormRange) &&
158  "The Form should have no Operands."
159  );
160  theFormRange->BackTakeQuotedProducer(theProducer);
161  theFormRange.Pop();
162  } else {
163  this->thisExpression.TakeElements(theProducer);
164  this->thisFormRange = boost::in_place(
165  boost::ref(this->thisExpression)
166  );
167  }
168  assert(this->thisFormRange);
169 
170  // Find the next Form with no Operands and return false, or return true if none.
171  for (
172  FormRange & theFormRange = *this->thisFormRange;
173  theFormRange;
174  theFormRange.Pop()
175  ) {
176  if (
177  !Form::OperandRange<Operand const>(*theFormRange)
178  ) {
179  return false;
180  }
181  }
182  theEvaluation.TakeQuotedProducer(this->thisExpression);
183  return true;
184 }
185 
186  #undef Type_
187 
188 #endif
static System & Get()
Om header file.
#define Om_Language_Operation_FillOperation_GetName_()
The Om library.
Definition: code_point.hpp:26