Skip to content

Commit 9e4e4cb

Browse files
committed
creates initial README
1 parent b6d1a9f commit 9e4e4cb

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<div align="center">
2+
# CPP Expression Tree
3+
4+
Header-only C++14 library for creating and evaluating logical expression trees.
5+
6+
Inspired by m-peko/booleval.
7+
</div>
8+
9+
<br/>
10+
11+
This project is under development and is subject to change. Project contributions and issue reports are welcome. The more the merrier!
12+
( ... well, hopefully not too many bug reports)
13+
14+
## Table of Contents
15+
16+
* [A Quick Example](#a-quick-example)
17+
* [Types of Expression Tree Nodes](#types-of-expression-tree-nodes)
18+
* [Expression Tree Leaf Nodes](#expression-tree-leaf-nodes)
19+
* [Expression Tree Op Nodes](#expression-tree-op-nodes)
20+
* [Logical Operators](#logical-operators)
21+
* [Boolean Operators](#boolean-operators)
22+
* [Using this Library](#using-this-library)
23+
* [Compilation](#compilation)
24+
* [Running the Unit Tests](#running-the-unit-tests)
25+
26+
## A Quick Example
27+
28+
```cpp
29+
// some code here
30+
// imagine we have some class struct whatever ...
31+
// we can create an expression_tree for evaluating the contents of instances of this struct class whatever
32+
```
33+
34+
Below is a tree diagram showing the content of the expression_tree that was created in the example code above:
35+
36+
<p align="center">
37+
<img src="docs/booleval-tree.png"/>
38+
</p>
39+
40+
## Types of Expression Tree Nodes
41+
42+
There are two types of expression tree nodes: leaf nodes and op nodes.
43+
44+
### Expression Tree Leaf Nodes
45+
46+
Expression tree leaf nodes contain individual, actionable expressions against which a class/struct instance is evaluated. Expression tree leaf nodes are only ever found at the extremities of the expression tree.
47+
48+
### Expression Tree Op Nodes
49+
50+
Expression tree op nodes contain a boolean operation (AND/OR) and have references to a left child node and a right child node. The child nodes may be expression tree leaf nodes, expression tree op nodes, or a permutation of the two. Expression tree op nodes are only ever found in the inner part of the tree. An expression tree op node is always a parent node and it always has two child nodes.
51+
52+
## Logical Operators
53+
54+
There are several logical operator functions defined in the namespace `attwoodn::expression_tree::op`, which can be used to create individual expressions within the tree. The included operators are:
55+
* equals
56+
* not_equals
57+
* less_than
58+
* greater_than
59+
60+
Users of the library can also easily define their own logical operators and use them when creating expressions. Here is an example of how a user might create their own operator functions and use them in an expression:
61+
62+
```cpp
63+
// some code here
64+
// is_pointer functions: always returns false (value parameters), always returns true (pointer parameters)
65+
```
66+
67+
## Boolean Operators
68+
69+
Boolean operators are used to chain individual expression tree nodes together. There are two boolean operators that can be used: `AND` and `OR`. These boolean operators are accessible via function calls on the expression nodes. Calling these functions generates a new expression tree node which becomes the parent of the nodes on either side of the boolean operator
70+
71+
```cpp
72+
// some code here
73+
// shows how nodes are chained with AND and OR functions
74+
```
75+
76+
A complex expression tree can be created by calling these functions to chain multiple expression tree nodes together.
77+
78+
## Using this Library
79+
80+
To include this library in your project, simply copy the content of the `include` directory into the `include` directory of your project. That's it! Now where did I put that Staples "Easy" button...?
81+
82+
## Compiling
83+
84+
First, clone the git repository and navigate into the local copy. Once you're there, run the following commands:
85+
86+
```
87+
mkdir build && cd build
88+
cmake ..
89+
make
90+
```
91+
92+
### Running the Unit Tests
93+
94+
After cloning and compiling the project, navigate to the build directory that was created. Enable the `BUILD_TESTING` CMake flag if it is not already enabled. Finally, run:
95+
96+
`ctest .`
97+
98+
This will execute the unit tests and provide a pass/fail indication for each one.

0 commit comments

Comments
 (0)