I am writing a simple C ++ parser that works using a map of pointers to the “triggers” functions in the “handler”, my question is what would be the most “static” and efficient method for implementing map generation and access?
First I looked at a method, for example. Parser::add_handler , which will add a trigger / handler to the parser card, but as far as I know, this will need to be done every time the program starts, while the data is known at compile time. (Although on the positive side, they would need to be executed only once, and not for each instance of Parser.)
Then I thought about using a virtual method, for example. Parser::get_handlers in Parser, which will be implemented in derived classes to return a handler map for this parser. This seems like a more beautiful encapsulated solution, although for each created parsing instance, a virtual function call with at least one call to the parser card generation function will be required.
Using the latter approach seems to be preferable at the moment, but it still leaves a dynamic map display at each execution, is there any way to avoid this?
source share