ExpressionTreeNode.h 5.02 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef LEPTON_EXPRESSION_TREE_NODE_H_
#define LEPTON_EXPRESSION_TREE_NODE_H_

/* -------------------------------------------------------------------------- *
 *                                   Lepton                                   *
 * -------------------------------------------------------------------------- *
 * This is part of the Lepton expression parser originating from              *
 * Simbios, the NIH National Center for Physics-Based Simulation of           *
 * Biological Structures at Stanford, funded under the NIH Roadmap for        *
 * Medical Research, grant U54 GM072970. See https://simtk.org.               *
 *                                                                            *
 * Portions copyright (c) 2009 Stanford University and the Authors.           *
 * Authors: Peter Eastman                                                     *
 * Contributors:                                                              *
 *                                                                            *
 * Permission is hereby granted, free of charge, to any person obtaining a    *
 * copy of this software and associated documentation files (the "Software"), *
 * to deal in the Software without restriction, including without limitation  *
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
 * and/or sell copies of the Software, and to permit persons to whom the      *
 * Software is furnished to do so, subject to the following conditions:       *
 *                                                                            *
 * The above copyright notice and this permission notice shall be included in *
 * all copies or substantial portions of the Software.                        *
 *                                                                            *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
 * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
 * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
 * -------------------------------------------------------------------------- */

#include "windowsIncludes.h"
#include <string>
#include <vector>

namespace Lepton {

class Operation;

43
44
45
46
47
48
49
/**
 * This class represents a node in the abstract syntax tree representation of an expression.
 * Each node is defined by an Operation and a set of children.  When the expression is
 * evaluated, each child is first evaluated in order, then the resulting values are passed
 * as the arguments to the Operation's evaluate() method.
 */

50
51
class LEPTON_EXPORT ExpressionTreeNode {
public:
52
53
54
55
56
57
58
    /**
     * Create a new ExpressionTreeNode.
     *
     * @param operation    the operation for this node.  The ExpressionTreeNode takes over ownership
     *                     of this object, and deletes it when the node is itself deleted.
     * @param children     the children of this node
     */
59
    ExpressionTreeNode(Operation* operation, const std::vector<ExpressionTreeNode>& children);
60
61
62
63
64
65
66
67
    /**
     * Create a new ExpressionTreeNode with two children.
     *
     * @param operation    the operation for this node.  The ExpressionTreeNode takes over ownership
     *                     of this object, and deletes it when the node is itself deleted.
     * @param child1       the first child of this node
     * @param child2       the second child of this node
     */
68
    ExpressionTreeNode(Operation* operation, const ExpressionTreeNode& child1, const ExpressionTreeNode& child2);
69
70
71
72
73
74
75
    /**
     * Create a new ExpressionTreeNode with one child.
     *
     * @param operation    the operation for this node.  The ExpressionTreeNode takes over ownership
     *                     of this object, and deletes it when the node is itself deleted.
     * @param child        the child of this node
     */
76
    ExpressionTreeNode(Operation* operation, const ExpressionTreeNode& child);
77
78
79
80
81
82
    /**
     * Create a new ExpressionTreeNode with no children.
     *
     * @param operation    the operation for this node.  The ExpressionTreeNode takes over ownership
     *                     of this object, and deletes it when the node is itself deleted.
     */
83
84
85
86
87
    ExpressionTreeNode(Operation* operation);
    ExpressionTreeNode(const ExpressionTreeNode& node);
    ExpressionTreeNode();
    ~ExpressionTreeNode();
    ExpressionTreeNode& operator=(const ExpressionTreeNode& node);
88
89
90
    /**
     * Get the Operation performed by this node.
     */
91
    const Operation& getOperation() const;
92
93
94
    /**
     * Get this node's child nodes.
     */
95
96
97
98
99
100
101
102
103
    const std::vector<ExpressionTreeNode>& getChildren() const;
private:
    Operation* operation;
    std::vector<ExpressionTreeNode> children;
};

} // namespace Lepton

#endif /*LEPTON_EXPRESSION_TREE_NODE_H_*/