Antares Simulator
Power System Simulator
pre-order.h
1 #pragma once
2 
3 #include <stack>
4 
5 namespace Antares::Expressions::Nodes
6 {
7 // Forward-declaration is enough
8 
9 class Node;
10 
11 // PreOrder Iterator for AST
13 {
14  std::stack<Node*> nodeStack;
15 
16 public:
17  // Iterator type aliases
18  using iterator_category = std::forward_iterator_tag;
19  using value_type = Node;
20  using difference_type = std::ptrdiff_t;
21  using pointer = Node*;
22  using reference = Node&;
23 
24  // Constructor
25  explicit ASTPreOrderIterator(Node* root = nullptr);
26 
27  // Dereference operator
28  reference operator*() const;
29 
30  // Pointer access operator
31  pointer operator->() const;
32 
33  // Increment operator (pre-order traversal)
34  ASTPreOrderIterator& operator++();
35 
36  // Equality comparison
37  bool operator==(const ASTPreOrderIterator& other) const;
38 
39  // Inequality comparison
40  bool operator!=(const ASTPreOrderIterator& other) const;
41 };
42 
43 // AST container class to expose begin/end iterators
44 class AST
45 {
46  Node* root;
47 
48 public:
49  explicit AST(Node* rootNode);
50 
51  // Begin iterator
52  ASTPreOrderIterator begin();
53 
54  // End iterator (indicating traversal is complete)
55  ASTPreOrderIterator end();
56 };
57 
58 // PreOrder Iterator for AST const version
60 {
61  std::stack<const Node*> nodeStack;
62 
63 public:
64  // Iterator type aliases
65  using iterator_category = std::forward_iterator_tag;
66  using value_type = Node;
67  using difference_type = std::ptrdiff_t;
68  using pointer = const Node*;
69  using reference = const Node&;
70 
71  // Constructor
72  explicit ASTPreOrderIteratorConst(const Node* root = nullptr);
73 
74  // Dereference operator
75  reference operator*() const;
76 
77  // Pointer access operator
78  pointer operator->() const;
79 
80  // Increment operator (pre-order traversal)
81  ASTPreOrderIteratorConst& operator++();
82 
83  // Equality comparison
84  bool operator==(const ASTPreOrderIteratorConst& other) const;
85 
86  // Inequality comparison
87  bool operator!=(const ASTPreOrderIteratorConst& other) const;
88 };
89 
90 // AST container class to expose begin/end iterators
91 class ASTconst
92 {
93  const Node* root;
94 
95 public:
96  explicit ASTconst(const Node* rootNode);
97 
98  // Begin iterator
100 
101  // End iterator (indicating traversal is complete)
103 };
104 } // namespace Antares::Expressions::Nodes
Definition: pre-order.h:45
Definition: pre-order.h:92
Base class for nodes in a syntax tree.
Definition: Node.h:30