Om
swap_operation.cpp
Go to the documentation of this file.
1 
15 #ifndef Om_Language_Operation_SwapOperation_
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(SwapOperationTest)
34 
35  BOOST_AUTO_TEST_CASE(DefinitionTest) {
36  BOOST_CHECK_EQUAL(
37  "{swap}",
38  System::Get().Evaluate("drop find {swap} system")
39  );
40  }
41 
42  BOOST_AUTO_TEST_CASE(SimpleTest) {
43  BOOST_CHECK_EQUAL(
44  "{4{5}6}{1{2}3}",
45  System::Get().Evaluate("swap {1{2}3}{4{5}6}")
46  );
47  }
48 
49  BOOST_AUTO_TEST_SUITE_END()
50 
51  }
52 
53  }
54 
55 }
56 
57  #endif
58 
59 #else
60 
61  #include "om/language/literal.hpp"
62 
63 // MARK: - Om::Language::Operation::SwapOperation
64 
65  #define Type_ \
66  Om::Language::Operation::SwapOperation
67 
68 // MARK: public (static)
69 
70 inline char const * Type_::GetName() {
72 }
73 
74 template <typename TheSwapOperation>
75 inline void Type_::GiveElements(
76  TheSwapOperation & theSwapOperation,
77  Consumer & theConsumer
78 ) {
79  theConsumer.TakeElement(
80  GetOperator()
81  );
82  if (
83  !theSwapOperation.thisOperand.IsEmpty()
84  ) {
85  theConsumer.TakeElement(theSwapOperation.thisOperand);
86  }
87 }
88 
89 // MARK: public (non-static)
90 
91 inline Type_::SwapOperation():
92 thisOperand() {}
93 
94 template <typename TheOperand>
95 inline bool Type_::TakeOperand(
96  Evaluation & theEvaluation,
97  TheOperand & theOperand
98 ) {
99  assert(
100  !theOperand.IsEmpty()
101  );
102  if (
103  this->thisOperand.IsEmpty()
104  ) {
105  this->thisOperand.Take(theOperand);
106  return false;
107  }
108  theEvaluation.TakeOperand(this->thisOperand);
109  theEvaluation.TakeOperand(theOperand);
110  return true;
111 }
112 
113 template <typename TheProducer>
114 inline bool Type_::TakeQuotedProducer(
115  Evaluation & theEvaluation,
116  TheProducer & theProducer
117 ) {
118  if (
119  this->thisOperand.IsEmpty()
120  ) {
121  this->thisOperand.SetProgram(
122  theProducer.GiveProgram()
123  );
124  return false;
125  }
126  theEvaluation.TakeOperand(this->thisOperand);
127  theEvaluation.TakeQuotedProducer(theProducer);
128  return true;
129 }
130 
131  #undef Type_
132 
133 #endif
static System & Get()
Om header file.
The Om library.
Definition: code_point.hpp:26
Om header file.
#define Om_Language_Operation_SwapOperation_GetName_()