Om
pair_operation.cpp
Go to the documentation of this file.
1 
15 #ifndef Om_Language_Operation_PairOperation_
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(PairOperationTest)
34 
35  BOOST_AUTO_TEST_CASE(DefinitionTest) {
36  BOOST_CHECK_EQUAL(
37  "{pair}",
38  System::Get().Evaluate("drop find {pair} system")
39  );
40  }
41 
42  BOOST_AUTO_TEST_CASE(GeneralTest) {
43  BOOST_CHECK_EQUAL(
44  (
45  "{1{2}\n"
46  "3{4{5}6}}"
47  ),
48  System::Get().Evaluate("pair {1{2}3}{4{5}6}")
49  );
50 
51  BOOST_CHECK_EQUAL(
52  "{1{2}{{5}6}}",
53  System::Get().Evaluate("pair {1{2}}{{5}6}")
54  );
55 
56  BOOST_CHECK_EQUAL(
57  "{{{5}6}}",
58  System::Get().Evaluate("pair {}{{5}6}")
59  );
60 
61  BOOST_CHECK_EQUAL(
62  (
63  "{{5}\n"
64  "6{}}"
65  ),
66  System::Get().Evaluate("pair {{5}6}{}")
67  );
68 
69  BOOST_CHECK_EQUAL(
70  "{{2}{3}}",
71  System::Get().Evaluate("pair {{2}}{3}")
72  );
73 
74  BOOST_CHECK_EQUAL(
75  "{{2}{3}}",
76  System::Get().Evaluate("pair quote{2}{3}")
77  );
78 
79  BOOST_CHECK_EQUAL(
80  "{2{{3}}}",
81  System::Get().Evaluate("pair{2}quote{3}")
82  );
83  }
84 
85  BOOST_AUTO_TEST_SUITE_END()
86 
87  }
88 
89  }
90 
91 }
92 
93  #endif
94 
95 #else
96 
98 
99 // MARK: - Om::Language::Operation::PairOperation
100 
101  #define Type_ \
102  Om::Language::Operation::PairOperation
103 
104 // MARK: public (static)
105 
106 inline char const * Type_::GetName() {
108 }
109 
110 template <typename ThePairOperation>
111 inline void Type_::GiveElements(
112  ThePairOperation & thePairOperation,
113  Consumer & theConsumer
114 ) {
115  theConsumer.TakeElement(
116  GetOperator()
117  );
118  if (
119  !thePairOperation.thisExpression.IsEmpty()
120  ) {
121  theConsumer.TakeQuotedElements(thePairOperation.thisExpression);
122  }
123 }
124 
125 // MARK: public (non-static)
126 
127 inline Type_::PairOperation():
128 thisExpression() {}
129 
130 template <typename TheOperand>
131 inline bool Type_::TakeOperand(
132  Evaluation & theEvaluation,
133  TheOperand & theOperand
134 ) {
135  assert(
136  !theOperand.IsEmpty()
137  );
138  if (
139  this->thisExpression.IsEmpty()
140  ) {
141  this->thisExpression.TakeElements(*theOperand);
142  if (
143  this->thisExpression.IsEmpty()
144  ) {
145  QuoteOperation::Give(theEvaluation);
146  return true;
147  }
148  return false;
149  }
150  this->thisExpression.TakeOperand(theOperand);
151  theEvaluation.TakeQuotedProducer(this->thisExpression);
152  return true;
153 }
154 
155 template <typename TheProducer>
156 inline bool Type_::TakeQuotedProducer(
157  Evaluation & theEvaluation,
158  TheProducer & theProducer
159 ) {
160  if (
161  this->thisExpression.IsEmpty()
162  ) {
163  this->thisExpression.TakeElements(theProducer);
164  if (
165  this->thisExpression.IsEmpty()
166  ) {
167  QuoteOperation::Give(theEvaluation);
168  return true;
169  }
170  return false;
171  }
172  this->thisExpression.TakeQuotedProducer(theProducer);
173  theEvaluation.TakeQuotedProducer(this->thisExpression);
174  return true;
175 }
176 
177  #undef Type_
178 
179 #endif
static System & Get()
The Om library.
Definition: code_point.hpp:26
std::auto_ptr< TheGiveable > Give(TheGiveable &)
Calls Move on the object.
Om header file.
#define Om_Language_Operation_PairOperation_GetName_()
Om header file.