0

I have a custom list class capable of storing recursive lists. There is a json file that is parsed during runtime which will contain information about what functions to call on what lists. I am using nlohmann::json library

For example:

class Game{
CustomListElement setup;
}

class CustomListElement{
CustomListElement getElementAt(std::string){
//returns element
   }
CustomListElement upfrom(int start){
//create CustomList from int
   }
}

This is the json:

{
"setup": {
      "game-info": {
            "Rounds": 10,
            "Players": 5
            }
       }
"list": "setup.Rounds.upfrom(1)",
}

I can already parse the first part of the json. So the CustomList setup field in the game class, already stores a map of { "game-info", { {"Rounds", 10}, {"Players", 5} } }. Each of these objects is also of type CustomList and they can be accessed through getElementAt(). But the json is parsed during runtime so I don't know what the names would be further down and what functions I would need to call. These are determined by "list" in the json. So how do I dynamically convert something of the format "setup.Rounds.upfrom(1)" into actual member accesses and calls?

callum arul
  • 159
  • 6
  • If you can control the format of this file, I'd change it to use a pre-parsed expression tree, which will save you a lot of effort. Otherwise, you'll probably find yourself writing a C++ expression parser and writing a lot of "reflective" functionality. – nneonneo Nov 12 '22 at 18:27

0 Answers0