Om
default_program.cpp
Go to the documentation of this file.
1 
15 #ifndef Om_Language_DefaultProgram_
16 
18 
19 #else
20 
21  #include "om/language/element.hpp"
22  #include "om/source/source.hpp"
23 
24  #ifndef Om_Macro_Precompilation_
25 
26  #include <typeinfo>
27 
28  #endif
29 
30 // MARK: - Om::Language::DefaultProgram
31 
32  #define Template_ \
33  template < \
34  typename ThisImplementation, \
35  typename ThisInterface \
36  >
37 
38  #define Type_ \
39  Om::Language::DefaultProgram< \
40  ThisImplementation, \
41  ThisInterface \
42  >
43 
44 // MARK: public (non-static)
45 
46 Template_
47 inline Type_::~DefaultProgram() {}
48 
53 Template_
54 inline bool Type_::Equals(Program const & theProgram) const {
55  typedef Om::Source::Source<Element const> ElementSource;
56 
57  std::auto_ptr<ElementSource> theRange = this->GetElementRange();
58  assert(
59  theRange.get()
60  );
61 
62  std::auto_ptr<ElementSource> theOtherRange = theProgram.GetElementRange();
63  assert(
64  theOtherRange.get()
65  );
66 
67  for (
68  ;
69  ;
70  ) {
71  bool const theRangeHasNext = *theRange;
72  bool const theOtherRangeHasNext = *theOtherRange;
73  if (
74  !theRangeHasNext ||
75  !theOtherRangeHasNext
76  ) {
77  return theRangeHasNext == theOtherRangeHasNext;
78  }
79  if (**theRange != **theOtherRange) {
80  return false;
81  }
82  theRange->Pop();
83  theOtherRange->Pop();
84  }
85 }
86 
87 Template_
88 inline void Type_::TakeElements(Producer & theProducer) {
89  this->TakeProducer<ThisImplementation>(theProducer);
90 }
91 
92 Template_
93 inline void Type_::TakeElements(Producer const & theProducer) {
94  this->TakeProducer<ThisImplementation const>(theProducer);
95 }
96 
97 // MARK: private (non-static)
98 
99 Template_
100 template <
101  typename TheCast,
102  typename TheProducer
103 >
104 inline void Type_::TakeProducer(TheProducer & theProducer) {
105  assert(
106  dynamic_cast<ThisImplementation *>(this)
107  );
108  assert(
109  typeid(TheCast) == typeid(ThisImplementation)
110  );
111  if (
112  typeid(TheCast) == typeid(theProducer) &&
113  this->IsEmpty()
114  ) {
115  this->Take(
116  static_cast<TheCast &>(theProducer)
117  );
118  } else {
119  theProducer.GiveElements(*this);
120  }
121 }
122 
123  #undef Type_
124  #undef Template_
125 
126 #endif
Any object that items can be pulled from.
Definition: source.hpp:31
Om header file.
Om header file.
Om header file.