You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[Types of Expression Tree Nodes](#types-of-expression-tree-nodes)
15
16
*[Expression Tree Leaf Nodes](#expression-tree-leaf-nodes)
16
17
*[Expression Tree Op Nodes](#expression-tree-op-nodes)
@@ -31,9 +32,54 @@ This project is under development and is subject to change. Project contribution
31
32
Below is a tree diagram showing the content of the expression_tree that was created in the example code above:
32
33
33
34
<palign="center">
34
-
<img src="docs/booleval-tree.png"/>
35
+
<img src="docs/expression-tree.png"/>
35
36
</p>
36
37
38
+
## Creating Expression Trees
39
+
40
+
The expression_tree class is a templated, RAII container class that takes ownership of user-defined expressions. The template parameter of expression_tree is the type of object that the expression_tree can evaluate. The template parameter of expression_tree cannot be a primitive type, like `int` or `char`.
41
+
42
+
An expression_tree cannot be default constructed - it must be initialized with an expression. Users can easily and intuitively define expressions using one of the `make_expr` helper functions found in the namespace `attwoodn::expression_tree`.
43
+
44
+
`make_expr` generates heap-allocated pointers to expression tree nodes and returns them. As such, the returned expression tree node pointers should be managed carefully. If the returned pointers are not wrapped in an expression_tree or a smart pointer, they will need to be explicitly `delete`d by the calling code.
45
+
46
+
Here are some examples of how you might handle the return value from one of the `make_expr` helper functions:
47
+
```cpp
48
+
#include<attwoodn/expression_tree.hpp>
49
+
50
+
usingnamespaceattwoodn::expression_tree;
51
+
52
+
struct my_type {
53
+
int my_int = 5;
54
+
bool my_bool = true;
55
+
};
56
+
57
+
...
58
+
59
+
// The heap-allocated expression node pointer returned by make_expr becomes owned by the expression_tree
60
+
expression_tree<my_type> expr_tree_raw {
61
+
make_expr(&my_type::my_bool, op::equals, true)
62
+
};
63
+
64
+
...
65
+
66
+
// The heap-allocated expression node pointer returned by make_expr becomes owned by the unique_ptr
0 commit comments