BCS
BCS

Reputation: 78625

How to store state on a node for a visitor pattern?

I have an architecture that uses the visitor pattern to implement a number of passes over a tree (an AST as it happens). In one of the passes I need to associate some data with a node (nodeX) and then from some point below it get my data from a reference to the nodeX. I want to do this in a way that doesn't push the implementation of the visitor/pass into the tree nodes.

Is there some neat way to make that work?

Ideas:

Upvotes: 1

Views: 433

Answers (1)

mr grumpy
mr grumpy

Reputation: 1563

The hash_map sounds like the best way to me. The visitor would own it.

Upvotes: 1

Related Questions