You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ExpressionTreeNode.h 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #ifndef LEPTON_EXPRESSION_TREE_NODE_H_
  2. #define LEPTON_EXPRESSION_TREE_NODE_H_
  3. /* -------------------------------------------------------------------------- *
  4. * Lepton *
  5. * -------------------------------------------------------------------------- *
  6. * This is part of the Lepton expression parser originating from *
  7. * Simbios, the NIH National Center for Physics-Based Simulation of *
  8. * Biological Structures at Stanford, funded under the NIH Roadmap for *
  9. * Medical Research, grant U54 GM072970. See https://simtk.org. *
  10. * *
  11. * Portions copyright (c) 2009 Stanford University and the Authors. *
  12. * Authors: Peter Eastman *
  13. * Contributors: *
  14. * *
  15. * Permission is hereby granted, free of charge, to any person obtaining a *
  16. * copy of this software and associated documentation files (the "Software"), *
  17. * to deal in the Software without restriction, including without limitation *
  18. * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
  19. * and/or sell copies of the Software, and to permit persons to whom the *
  20. * Software is furnished to do so, subject to the following conditions: *
  21. * *
  22. * The above copyright notice and this permission notice shall be included in *
  23. * all copies or substantial portions of the Software. *
  24. * *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
  26. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
  27. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
  28. * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
  29. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
  30. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
  31. * USE OR OTHER DEALINGS IN THE SOFTWARE. *
  32. * -------------------------------------------------------------------------- */
  33. #include "windowsIncludes.h"
  34. #include <string>
  35. #include <vector>
  36. namespace Lepton
  37. {
  38. class Operation;
  39. /**
  40. * This class represents a node in the abstract syntax tree representation of an expression.
  41. * Each node is defined by an Operation and a set of children. When the expression is
  42. * evaluated, each child is first evaluated in order, then the resulting values are passed
  43. * as the arguments to the Operation's evaluate() method.
  44. */
  45. class LEPTON_EXPORT ExpressionTreeNode
  46. {
  47. public:
  48. /**
  49. * Create a new ExpressionTreeNode.
  50. *
  51. * @param operation the operation for this node. The ExpressionTreeNode takes over ownership
  52. * of this object, and deletes it when the node is itself deleted.
  53. * @param children the children of this node
  54. */
  55. ExpressionTreeNode(Operation* operation, const std::vector<ExpressionTreeNode>& children);
  56. /**
  57. * Create a new ExpressionTreeNode with two children.
  58. *
  59. * @param operation the operation for this node. The ExpressionTreeNode takes over ownership
  60. * of this object, and deletes it when the node is itself deleted.
  61. * @param child1 the first child of this node
  62. * @param child2 the second child of this node
  63. */
  64. ExpressionTreeNode(Operation* operation, const ExpressionTreeNode& child1, const ExpressionTreeNode& child2);
  65. /**
  66. * Create a new ExpressionTreeNode with one child.
  67. *
  68. * @param operation the operation for this node. The ExpressionTreeNode takes over ownership
  69. * of this object, and deletes it when the node is itself deleted.
  70. * @param child the child of this node
  71. */
  72. ExpressionTreeNode(Operation* operation, const ExpressionTreeNode& child);
  73. /**
  74. * Create a new ExpressionTreeNode with no children.
  75. *
  76. * @param operation the operation for this node. The ExpressionTreeNode takes over ownership
  77. * of this object, and deletes it when the node is itself deleted.
  78. */
  79. ExpressionTreeNode(Operation* operation);
  80. ExpressionTreeNode(const ExpressionTreeNode& node);
  81. ExpressionTreeNode();
  82. ~ExpressionTreeNode();
  83. bool operator==(const ExpressionTreeNode& node) const;
  84. bool operator!=(const ExpressionTreeNode& node) const;
  85. ExpressionTreeNode& operator=(const ExpressionTreeNode& node);
  86. /**
  87. * Get the Operation performed by this node.
  88. */
  89. const Operation& getOperation() const;
  90. /**
  91. * Get this node's child nodes.
  92. */
  93. const std::vector<ExpressionTreeNode>& getChildren() const;
  94. private:
  95. Operation* operation = nullptr;
  96. std::vector<ExpressionTreeNode> children;
  97. };
  98. } // namespace Lepton
  99. #endif /*LEPTON_EXPRESSION_TREE_NODE_H_*/