Dynamically Filling A Tuple/An Openframeworks BaseObject

I don’t know if there is a better way of doing this but heres the problem. The program needs to read an XML settings file that a person can change which loads certain data types into a container of some kind.

First, do I have other options than a Tuple since an array, vector etc can only load similar data types. To further complicate things the tuple can be comprised of many different elements in different orders and needs to be globally accessible. Take for example it could be 5 vectors of strings, or a string, an ofVideoPlayer, an ofVideoGrabber, etc… I know that I would have to use templates which thankfully in c++11 they added variadic templates that make this concept possible. Still I am not even sure this is possible in C. I know it could certainly be done in Python but thats not really what I am looking for.

I did have a thought that came from this dilemma. Could we make the objects in openframeworks derive from a base object? that way one would be able to fill a vector with any data type from openframeworks assuming one set it up like vector which should allow you to pass in any object that extends the base class so you could have a vector with ofImages and ofPixels and ofVideoPlayers. It certainly complicates things if you try to do the same function on every object in the vector but it could make it easier than having to check many different variables.

If you are trying to create a heterogeneous collection, you might try looking at Poco::Any or Poco::DynamicAny

For a more thorough discussion of “Any” -style classes, including the Poco options and those available in boost, etc, see the articles / slides below.

Part 1
Part 2
Slides

By the way, Poco::JSON (and I perhaps Poco::XML) uses these Poco::Any and Poco::DynamicAny extensively for serialization.

Well that certainly is easier than having to set up templates and tuples. Awesome thanks Chris. Colleen Ludwig told me to get in contact with you since I am moving to Chicago for my masters at DePaul, perhaps our paths will cross again soon.

For sure @DomAmato! Say hi to Colleen and come and visit us in the openLab @ SAIC. We’ve got a lot of openFrameworks fun cooking these days (e.g. https://github.com/olab-io/ofSketch) and will be having some workshops and meetups this summer and fall. If you’re in chicago, keep an eye on http://talk.olab.io as well. Let me know when you’re in town!