Om
environment.cpp
Go to the documentation of this file.
1 
15 #ifndef Om_Language_Environment_
16 
18 
19 #else
20 
21 // MARK: - Om::Language::Environment
22 
23  #define Type_ \
24  Om::Language::Environment
25 
26 // MARK: public (non-static)
27 
28 inline Type_::Environment():
29 thisTranslatorVector() {}
30 
31 inline void Type_::GiveElements(Consumer & theConsumer) const {
32  if (
33  !this->IsEmpty()
34  ) {
35  typedef TranslatorVector::const_iterator Iterator;
36  Iterator const theEnd = this->thisTranslatorVector.end();
37  for (
38  Iterator theCurrent = this->thisTranslatorVector.begin();
39  ;
40  theConsumer.TakeElement(
41  Separator::GetLineSeparator()
42  )
43  ) {
44  assert(*theCurrent);
45  Translator const & theTranslator = **theCurrent;
46  assert(
47  !theTranslator.IsEmpty()
48  );
49  theTranslator.GiveElements(theConsumer);
50  if (theEnd == ++theCurrent) {
51  return;
52  }
53  }
54  }
55 }
56 
57 inline bool Type_::IsEmpty() const {
58  return this->thisTranslatorVector.empty();
59 }
60 
61 inline void Type_::Push(Translator const & theTranslator) {
62  Translator const * theTranslatorPointer = &theTranslator;
63  for (
64  std::stack<Translator const *> theStack;
65  ;
66  theStack.pop()
67  ) {
68  assert(theTranslatorPointer);
69 
70  if (
71  Environment const * const theEnvironment = dynamic_cast<Environment const *>(theTranslatorPointer)
72  ) {
73  typedef TranslatorVector::const_reverse_iterator Iterator;
74  Iterator const theEnd = theEnvironment->thisTranslatorVector.rend();
75  for (
76  Iterator theCurrent = theEnvironment->thisTranslatorVector.rbegin();
77  theEnd != theCurrent;
78  ++theCurrent
79  ) {
80  assert(
81  *theCurrent &&
82  !(*theCurrent)->IsEmpty()
83  );
84  theStack.push(*theCurrent);
85  }
86  } else if (
87  this->IsEmpty() ||
88  this->thisTranslatorVector.back() != theTranslatorPointer
89  ) {
90  this->thisTranslatorVector.push_back(theTranslatorPointer);
91  }
92 
93  if (
94  theStack.empty()
95  ) {
96  return;
97  }
98 
99  theTranslatorPointer = theStack.top();
100  }
101 }
102 
103 inline bool Type_::Translate(
104  Evaluation & theEvaluation,
105  Operator const & theOperator
106 ) const {
107  typedef TranslatorVector::const_reverse_iterator Iterator;
108  Iterator const theEnd = this->thisTranslatorVector.rend();
109  for (
110  Iterator theCurrent = this->thisTranslatorVector.rbegin();
111  theEnd != theCurrent;
112  ++theCurrent
113  ) {
114  if (
115  (*theCurrent)->Translate(
116  theEvaluation,
117  theOperator
118  )
119  ) {
120  return true;
121  }
122  }
123  return false;
124 }
125 
126  #undef Type_
127 
128 #endif
Om header file.