Om
singleton_source.cpp
Go to the documentation of this file.
1 
15 #ifndef Om_Source_SingletonSource_
16 
18 
19 #else
20 
21 // MARK: - Om::Source::SingletonSource
22 
23  #define Template_ \
24  template <typename ThisItem>
25 
26  #define Type_ \
27  Om::Source::SingletonSource<ThisItem>
28 
29 // MARK: public (non-static)
30 
31 Template_
32 inline Type_::SingletonSource():
33 thisItem() {}
34 
35 Template_
36 inline Type_::SingletonSource(ThisItem & theItem):
37 thisItem(&theItem) {}
38 
39 Template_
40 inline Type_ & Type_::operator =(SingletonSource theSingletonSource) {
41  this->Swap(theSingletonSource);
42  return *this;
43 }
44 
45 Template_
46 inline bool Type_::operator !() const {
47  return !this->thisItem;
48 }
49 
50 Template_
51 inline ThisItem & Type_::operator *() const {
52  assert(this->thisItem);
53  return *this->thisItem;
54 }
55 
56 Template_
57 inline bool Type_::Equals(SingletonSource const & theSingletonSource) const {
58  return this->thisItem == theSingletonSource.thisItem;
59 }
60 
61 Template_
62 inline void Type_::Pop() {
63  assert(this->thisItem);
64  this->thisItem = 0;
65 }
66 
67 Template_
68 inline void Type_::Swap(SingletonSource & theSingletonSource) {
70  this->thisItem,
71  theSingletonSource.thisItem
72  );
73 }
74 
75  #undef Type_
76  #undef Template_
77 
78 // MARK: - Om::Source::
79 
80  #define Template_ \
81  template <typename TheItem>
82 
83  #define Type_ \
84  Om::Source::SingletonSource<TheItem>
85 
86 Template_
87 inline bool Om::Source::operator ==(
88  Type_ const & theFirst,
89  Type_ const & theSecond
90 ) {
91  return theFirst.Equals(theSecond);
92 }
93 
94 Template_
95 inline bool Om::Source::operator !=(
96  Type_ const & theFirst,
97  Type_ const & theSecond
98 ) {
99  return !theFirst.Equals(theSecond);
100 }
101 
102 // MARK: - boost::
103 
104 Template_
105 inline void boost::swap(
106  Type_ & theFirst,
107  Type_ & theSecond
108 ) {
109  theFirst.Swap(theSecond);
110 }
111 
112  #undef Type_
113  #undef Template_
114 
115 #endif
bool operator==(CodePointSource< TheCodeUnitIterator > const &, CodePointSource< TheCodeUnitIterator > const &)
bool operator!=(CodePointSource< TheCodeUnitIterator > const &, CodePointSource< TheCodeUnitIterator > const &)
void swap(Om::Language::Expression &, Om::Language::Expression &)
Om header file.