For the analyzer that I am developing, I am parsing the event log. In the log, each line is an event that makes it easy to analyze the file line by line. Events that are logged have a string identifier at the beginning, which is constructed as follows:
X_Y_Z
X always the same and can be parsed as a class with 8 members, since it has 8 arguments.
Y can be 6 different types, all of which have a different number of parameters that can be interpreted differently depending on the type of Y Creating a class for each of these 6 types is trivial; since they are just string s, int and bool s.
Z can be more than 20 different things, all with a different number of parameters that can be interpreted in different ways. Creating a class for these 20+ types is also trivial; since they are just string s, int and bool s.
Thus, an event class can be defined as follows:
template<typename Y, typename Z> struct Event { DateTime timestamp; X base; Y prefix; Z suffix; }
This would allow us to build any possible combination of events at compile time.
The problem is that the log file is parsed at runtime, and I would like to be able to compose these classes at runtime, depending on what I need. In addition, I would like to avoid throws where I can.
It is important to note that I need to iterate over these arranged events after the parsing is complete, as a second pass.
What will be the most elegant way to achieve this?
Change One solution I was thinking about would be to use std::variant and keep Y and Z as an identifier based on an integer in the event class. It may work, but I'm looking for something more elegant than std::variant with 20 arguments.