@@ -70,9 +70,9 @@ namespace attwoodn::expression_tree {
7070 * @brief The base class representing all expression tree nodes.
7171 */
7272 template <typename Obj>
73- class expression_tree_node_base {
73+ class expression_tree_node {
7474 public:
75- virtual ~expression_tree_node_base () {};
75+ virtual ~expression_tree_node () {};
7676
7777 /* *
7878 * @brief Evaluates the given object to determine if it satisfies the expressions defined in this node and all child nodes.
@@ -91,7 +91,7 @@ namespace attwoodn::expression_tree {
9191 * child node, as well as the boolean operation to be performed (e.g. left child AND right child, or left child OR right child).
9292 */
9393 template <typename Obj, typename LeftChild, typename RightChild>
94- class expression_tree_op_node : public expression_tree_node_base <Obj> {
94+ class expression_tree_op_node : public expression_tree_node <Obj> {
9595 public:
9696 using this_type = expression_tree_op_node<Obj, LeftChild, RightChild>;
9797
@@ -152,12 +152,12 @@ namespace attwoodn::expression_tree {
152152 };
153153
154154 /* *
155- * @brief Represents leaf nodes of the tree. These nodes contain a reference to a member variable or member function of the
156- * given Obj type, the requested logical operation to be performed (e.g. equals, greater_than, etc.), and the
155+ * @brief Represents leaf nodes of the tree. These nodes contain: a reference to a member variable or member function of the
156+ * given Obj type; the requested logical operation to be performed (e.g. equals, greater_than, etc.); and the
157157 * value to compare to the given member variable or member function of an Obj instance.
158158 */
159159 template <typename Obj, typename Op, typename CompValue>
160- class expression_tree_leaf_node : public expression_tree_node_base <Obj> {
160+ class expression_tree_leaf_node : public expression_tree_node <Obj> {
161161 public:
162162 using this_type = expression_tree_leaf_node<Obj, Op, CompValue>;
163163
@@ -207,6 +207,66 @@ namespace attwoodn::expression_tree {
207207 return logical_op_ (actual_value, comp_value_);
208208 }
209209
210+ /* *
211+ * Performs an AND operation with another expression_tree_leaf_node to create a heap-allocated pointer
212+ * to a new expression_tree_op_node. The returned expression_tree_op_node becomes the parent of both this node
213+ * and the other node that was AND'ed with this node. This node becomes the left child. The other node becomes
214+ * the right child.
215+ */
216+ template <typename OtherOp, typename OtherCompValue, typename OtherLeafNode,
217+ std::enable_if<std::is_same<OtherLeafNode, expression_tree_leaf_node<Obj, OtherOp, OtherCompValue>>::value>* = nullptr >
218+ expression_tree_op_node<Obj, this_type, OtherLeafNode>* AND (OtherLeafNode* other) {
219+ auto * op_node = new expression_tree_op_node<Obj, this_type, OtherLeafNode>(boolean_op::AND);
220+ op_node->set_left (this );
221+ op_node->set_right (other);
222+ return op_node;
223+ }
224+
225+ /* *
226+ * Performs an OR operation with another expression_tree_leaf_node to create a heap-allocated pointer
227+ * to a new expression_tree_op_node. The returned expression_tree_op_node becomes the parent of both this node
228+ * and the other node that was OR'ed with this node. This node becomes the left child. The other node becomes
229+ * the right child.
230+ */
231+ template <typename OtherOp, typename OtherCompValue, typename OtherLeafNode,
232+ std::enable_if<std::is_same<OtherLeafNode, expression_tree_leaf_node<Obj, OtherOp, OtherCompValue>>::value>* = nullptr >
233+ expression_tree_op_node<Obj, this_type, OtherLeafNode>* OR (OtherLeafNode* other) {
234+ auto * op_node = new expression_tree_op_node<Obj, this_type, OtherLeafNode>(boolean_op::OR);
235+ op_node->set_left (this );
236+ op_node->set_right (other);
237+ return op_node;
238+ }
239+
240+ /* *
241+ * Performs an AND operation with an expression_tree_op_node to create a heap-allocated pointer
242+ * to a new expression_tree_op_node. The returned expression_tree_op_node becomes the parent of both this node
243+ * and the other node that was AND'ed with this node. This node becomes the left child. The other node becomes
244+ * the right child.
245+ */
246+ template <typename OtherLeftChild, typename OtherRightChild, typename OtherOpNode,
247+ std::enable_if<std::is_same<OtherOpNode, expression_tree_op_node<Obj, OtherLeftChild, OtherRightChild>>::value>* = nullptr >
248+ expression_tree_op_node<Obj, this_type, OtherOpNode>* AND (OtherOpNode* other) {
249+ auto * op_node = new expression_tree_op_node<Obj, this_type, OtherOpNode>(boolean_op::AND);
250+ op_node->set_left (this );
251+ op_node->set_right (other);
252+ return op_node;
253+ }
254+
255+ /* *
256+ * Performs an OR operation with an expression_tree_op_node to create a heap-allocated pointer
257+ * to a new expression_tree_op_node. The returned expression_tree_op_node becomes the parent of both this node
258+ * and the other node that was OR'ed with this node. This node becomes the left child. The other node becomes
259+ * the right child.
260+ */
261+ template <typename OtherLeftChild, typename OtherRightChild, typename OtherOpNode,
262+ std::enable_if<std::is_same<OtherOpNode, expression_tree_op_node<Obj, OtherLeftChild, OtherRightChild>>::value>* = nullptr >
263+ expression_tree_op_node<Obj, this_type, OtherOpNode>* OR (OtherOpNode* other) {
264+ auto * op_node = new expression_tree_op_node<Obj, this_type, OtherOpNode>(boolean_op::OR);
265+ op_node->set_left (this );
266+ op_node->set_right (other);
267+ return op_node;
268+ }
269+
210270 private:
211271 CompValue (Obj::* member_func_)() const = nullptr ;
212272 const CompValue Obj::* member_var_ = nullptr ;
@@ -236,7 +296,7 @@ namespace attwoodn::expression_tree {
236296 }
237297
238298 /* *
239- * Makes an expression tree leaf node for comparing a class/struct's const member function return values
299+ * Makes an expression tree leaf node for comparing the return value from a class/struct's const member function
240300 */
241301 template <typename Obj, typename CompValue, typename Op = typename type_id<bool (*)(CompValue, CompValue)>::type>
242302 node::expression_tree_leaf_node<Obj, Op, CompValue>* make_expr ( CompValue (Obj::* member_func)() const , Op op, CompValue comp_value ) {
0 commit comments