Om
equals_operation.cpp
Go to the documentation of this file.
1 
15 #ifndef Om_Language_Operation_EqualsOperation_
16 
18 
19  #ifdef Om_Macro_Test_
20 
21  #include "om/language/system.hpp"
22 
23  #ifndef Om_Macro_Precompilation_
24 
25  #include "boost/test/unit_test.hpp"
26 
27  #endif
28 
29 namespace Om {
30 
31  namespace Language {
32 
33  namespace Operation {
34 
35  BOOST_AUTO_TEST_SUITE(EqualsOperationTest)
36 
37  BOOST_AUTO_TEST_CASE(DefinitionTest) {
38  BOOST_CHECK_EQUAL(
39  "{=}",
40  System::Get().Evaluate("drop find {=} system")
41  );
42  }
43 
44  BOOST_AUTO_TEST_CASE(GeneralTest) {
45  BOOST_CHECK_EQUAL(
46  "{{A}}",
47  System::Get().Evaluate("= {A} {A}")
48  );
49 
50  BOOST_CHECK_EQUAL(
51  "{}",
52  System::Get().Evaluate("= {A} {Not A}")
53  );
54 
55  BOOST_CHECK_EQUAL(
56  "{{}}",
57  System::Get().Evaluate("= {} {}")
58  );
59 
60  BOOST_CHECK_EQUAL(
61  "{}",
62  System::Get().Evaluate("= {} {Not empty}")
63  );
64  }
65 
66  BOOST_AUTO_TEST_SUITE_END()
67 
68  }
69 
70  }
71 
72 }
73 
74  #endif
75 
76 #else
77 
79 
80 // MARK: - Om::Language::Operation::EqualsOperation
81 
82  #define Type_ \
83  Om::Language::Operation::EqualsOperation
84 
85 // MARK: public (static)
86 
87 inline char const * Type_::GetName() {
89 }
90 
91 template <typename TheEqualsOperation>
92 inline void Type_::GiveElements(
93  TheEqualsOperation & theEqualsOperation,
94  Consumer & theConsumer
95 ) {
96  theConsumer.TakeElement(
97  GetOperator()
98  );
99  if (
100  !theEqualsOperation.thisOperand.IsEmpty()
101  ) {
102  theConsumer.TakeElement(theEqualsOperation.thisOperand);
103  }
104 }
105 
106 // MARK: public (non-static)
107 
108 inline Type_::EqualsOperation():
109 thisOperand() {}
110 
111 template <typename TheOperand>
112 inline bool Type_::TakeOperand(
113  Evaluation & theEvaluation,
114  TheOperand & theOperand
115 ) {
116  assert(
117  !theOperand.IsEmpty()
118  );
119  if (
120  this->thisOperand.IsEmpty()
121  ) {
122  this->thisOperand.Take(theOperand);
123  return false;
124  }
125  Expression theExpression;
126  if (this->thisOperand == theOperand) {
127  theExpression.TakeOperand(this->thisOperand);
128  }
129  theEvaluation.TakeQuotedProducer(theExpression);
130  return true;
131 }
132 
133 template <typename TheProducer>
134 inline bool Type_::TakeQuotedProducer(
135  Evaluation & theEvaluation,
136  TheProducer & theProducer
137 ) {
138  if (
139  this->thisOperand.IsEmpty()
140  ) {
141  this->thisOperand.SetProgram(
142  theProducer.GiveProgram()
143  );
144  return false;
145  }
146  Expression theExpression;
147  if (
148  this->IsMatch(theProducer)
149  ) {
150  theExpression.TakeOperand(this->thisOperand);
151  }
152  theEvaluation.TakeQuotedProducer(theExpression);
153  return true;
154 }
155 
156 // MARK: private (non-static)
157 
158 template <typename TheProducer>
159 inline bool Type_::IsMatch(TheProducer & theProducer) const {
160  assert(
161  this->thisOperand.GetProgram()
162  );
163  Program const & theProgram = *this->thisOperand.GetProgram();
164  Program const * const theProducerProgram = dynamic_cast<Program const *>(&theProducer);
165  if (theProducerProgram) {
166  return *theProducerProgram == theProgram;
167  }
168  Literal theProducerLiteral;
169  theProducerLiteral.TakeElements(theProducer);
170  return theProducerLiteral.Equals(theProgram);
171 }
172 
173  #undef Type_
174 
175 #endif
static System & Get()
Om header file.
#define Om_Language_Operation_EqualsOperation_GetName_()
Om header file.
The Om library.
Definition: code_point.hpp:26
Om header file.