Om
list.cpp
Go to the documentation of this file.
1 
15 #ifndef Om_List_
16 
17  #include "om/list.hpp"
18 
19 #else
20 
21 // MARK: - Om::List
22 
23  #define Template_ \
24  template <typename ThisValue>
25 
26  #define Type_ \
27  Om::List<ThisValue>
28 
29 // MARK: public (non-static)
30 
31 Template_
32 inline Type_::List():
33 thisNodeArray() {
34  this->Clear();
35 }
36 
37 Template_
38 inline void Type_::Clear() {
39  this->thisNodeArray[theFrontNodeIndex] = 0;
40  this->thisNodeArray[theBackNodeIndex] = 0;
41 }
42 
43 Template_
44 inline typename Type_::Node * Type_::GetNode(NodeIndex const theNodeIndex) {
45  return this->thisNodeArray[theNodeIndex];
46 }
47 
48 Template_
49 inline typename Type_::Node const * Type_::GetNode(NodeIndex const theNodeIndex) const {
50  return this->thisNodeArray[theNodeIndex];
51 }
52 
53 Template_
54 inline bool Type_::IsEmpty() const {
55  assert(
56  !this->thisNodeArray[theFrontNodeIndex] == !this->thisNodeArray[theBackNodeIndex]
57  );
58  return !this->thisNodeArray[theFrontNodeIndex];
59 }
60 
61 Template_
62 inline void Type_::LinkNode(
63  NodeIndex const theNodeIndex,
64  Node & theNode
65 ) {
66  Node * const theLinkedNode = this->thisNodeArray[theNodeIndex];
67  theNode.thisNodeArray[theNodeIndex] = 0;
68  theNode.thisNodeArray[!theNodeIndex] = theLinkedNode;
69  if (theLinkedNode) {
70  theLinkedNode->thisNodeArray[theNodeIndex] = &theNode;
71  } else {
72  assert(
73  !this->thisNodeArray[!theNodeIndex]
74  );
75  this->thisNodeArray[!theNodeIndex] = &theNode;
76  }
77  this->thisNodeArray[theNodeIndex] = &theNode;
78 }
79 
80 Template_
81 inline void Type_::RelinkNode(
82  NodeIndex const theNodeIndex,
83  Node & theNode
84 ) {
85  if (
86  Node * const theNearNode = theNode.thisNodeArray[theNodeIndex]
87  ) {
88  Node * const theFarNode = theNode.thisNodeArray[!theNodeIndex];
89  theNearNode->thisNodeArray[!theNodeIndex] = theFarNode;
90  if (theFarNode) {
91  theFarNode->thisNodeArray[theNodeIndex] = theNearNode;
92  } else {
93  assert(
94  this->thisNodeArray[!theNodeIndex] == &theNode
95  );
96  this->thisNodeArray[!theNodeIndex] = theNearNode;
97  }
98 
99  this->LinkNode(
100  theNodeIndex,
101  theNode
102  );
103  }
104 }
105 
106 Template_
107 inline void Type_::Swap(List & theList) {
108  boost::swap(
109  this->thisNodeArray[theFrontNodeIndex],
110  theList.thisNodeArray[theFrontNodeIndex]
111  );
112  boost::swap(
113  this->thisNodeArray[theBackNodeIndex],
114  theList.thisNodeArray[theBackNodeIndex]
115  );
116 }
117 
118 Template_
119 inline typename Type_::Node * Type_::UnlinkNode(NodeIndex const theNodeIndex) {
120  if (
121  Node * const theNode = this->thisNodeArray[theNodeIndex]
122  ) {
123  assert(
124  this->thisNodeArray[!theNodeIndex] &&
125  !theNode->thisNodeArray[theNodeIndex]
126  );
127 
128  Node * const theFarNode = theNode->thisNodeArray[!theNodeIndex];
129  if (theFarNode) {
130  theFarNode->thisNodeArray[theNodeIndex] = 0;
131  } else {
132  assert(
133  this->thisNodeArray[!theNodeIndex] == theNode
134  );
135  this->thisNodeArray[!theNodeIndex] = 0;
136  }
137  this->thisNodeArray[theNodeIndex] = theFarNode;
138 
139  return theNode;
140  }
141  return 0;
142 }
143 
144  #undef Type_
145  #undef Template_
146 
147 // MARK: - Om::List::Node
148 
149  #define Template_ \
150  template <typename ThisValue>
151 
152  #define Type_ \
153  Om::List<ThisValue>::Node
154 
155 // MARK: public (non-static)
156 
157 Template_
158 inline Type_::Node():
159 thisNodeArray(),
160 thisValue() {
161  this->thisNodeArray[theFrontNodeIndex] = 0;
162  this->thisNodeArray[theBackNodeIndex] = 0;
163 }
164 
165 Template_
166 inline typename Type_ * Type_::GetNode(NodeIndex const theNodeIndex) {
167  return this->thisNodeArray[theNodeIndex];
168 }
169 
170 Template_
171 inline typename Type_ const * Type_::GetNode(NodeIndex const theNodeIndex) const {
172  return this->thisNodeArray[theNodeIndex];
173 }
174 
175 Template_
176 inline ThisValue & Type_::GetValue() {
177  return this->thisValue;
178 }
179 
180 Template_
181 inline ThisValue const & Type_::GetValue() const {
182  return this->thisValue;
183 }
184 
185  #undef Type_
186  #undef Template_
187 
188 #endif
Om header file.
void swap(Om::Language::Expression &, Om::Language::Expression &)