Skip to content

Commit 2fc3638

Browse files
committed
implements AND/OR operations on the expression_tree_op_node class
1 parent ef6d3d1 commit 2fc3638

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

include/attwoodn/expression_tree.hpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,66 @@ namespace attwoodn::expression_tree {
145145
return false;
146146
}
147147

148+
/**
149+
* Performs an AND operation with an expression_tree_leaf_node to create a heap-allocated pointer
150+
* to a new expression_tree_op_node. The returned expression_tree_op_node becomes the parent of both this node
151+
* and the other node that was AND'ed with this node. This node becomes the left child. The other node becomes
152+
* the right child.
153+
*/
154+
template<typename OtherOp, typename OtherCompValue, typename OtherLeafNode,
155+
std::enable_if<std::is_same<OtherLeafNode, expression_tree_leaf_node<Obj, OtherOp, OtherCompValue>>::value>* = nullptr>
156+
expression_tree_op_node<Obj, this_type, OtherLeafNode>* AND (OtherLeafNode* other) {
157+
auto* op_node = new expression_tree_op_node<Obj, this_type, OtherLeafNode>(boolean_op::AND);
158+
op_node->set_left(this);
159+
op_node->set_right(other);
160+
return op_node;
161+
}
162+
163+
/**
164+
* Performs an OR operation with an expression_tree_leaf_node to create a heap-allocated pointer
165+
* to a new expression_tree_op_node. The returned expression_tree_op_node becomes the parent of both this node
166+
* and the other node that was OR'ed with this node. This node becomes the left child. The other node becomes
167+
* the right child.
168+
*/
169+
template<typename OtherOp, typename OtherCompValue, typename OtherLeafNode,
170+
std::enable_if<std::is_same<OtherLeafNode, expression_tree_leaf_node<Obj, OtherOp, OtherCompValue>>::value>* = nullptr>
171+
expression_tree_op_node<Obj, this_type, OtherLeafNode>* OR (OtherLeafNode* other) {
172+
auto* op_node = new expression_tree_op_node<Obj, this_type, OtherLeafNode>(boolean_op::OR);
173+
op_node->set_left(this);
174+
op_node->set_right(other);
175+
return op_node;
176+
}
177+
178+
/**
179+
* Performs an AND operation with another expression_tree_op_node to create a heap-allocated pointer
180+
* to a new expression_tree_op_node. The returned expression_tree_op_node becomes the parent of both this node
181+
* and the other node that was AND'ed with this node. This node becomes the left child. The other node becomes
182+
* the right child.
183+
*/
184+
template<typename OtherLeftChild, typename OtherRightChild, typename OtherOpNode,
185+
std::enable_if<std::is_same<OtherOpNode, expression_tree_op_node<Obj, OtherLeftChild, OtherRightChild>>::value>* = nullptr>
186+
expression_tree_op_node<Obj, this_type, OtherOpNode>* AND (OtherOpNode* other) {
187+
auto* op_node = new expression_tree_op_node<Obj, this_type, OtherOpNode>(boolean_op::AND);
188+
op_node->set_left(this);
189+
op_node->set_right(other);
190+
return op_node;
191+
}
192+
193+
/**
194+
* Performs an OR operation with another expression_tree_op_node to create a heap-allocated pointer
195+
* to a new expression_tree_op_node. The returned expression_tree_op_node becomes the parent of both this node
196+
* and the other node that was OR'ed with this node. This node becomes the left child. The other node becomes
197+
* the right child.
198+
*/
199+
template<typename OtherLeftChild, typename OtherRightChild, typename OtherOpNode,
200+
std::enable_if<std::is_same<OtherOpNode, expression_tree_op_node<Obj, OtherLeftChild, OtherRightChild>>::value>* = nullptr>
201+
expression_tree_op_node<Obj, this_type, OtherOpNode>* OR (OtherOpNode* other) {
202+
auto* op_node = new expression_tree_op_node<Obj, this_type, OtherOpNode>(boolean_op::OR);
203+
op_node->set_left(this);
204+
op_node->set_right(other);
205+
return op_node;
206+
}
207+
148208
private:
149209
boolean_op bool_op_;
150210
LeftChild* left_ { nullptr };

0 commit comments

Comments
 (0)