How can I do this?
If possible, record the data type with the object. Perhaps overkill, but take a look at SQLite and try storing your data as a TEXT
entry for the type and a BLOB
for the binary data. This will allow you to determine the type by simply querying the database for it.
I have not used Eigen before, but if you have no other choice (perhaps you have a lot of existing binary data) try creating several matrices of different types and attempt to fit the data to them. If that works, you could create an object with pointers to these data types as members, a member for what type the matrix is, and just ask the object for the reference when needed.
What can I give into my function, so that upon its return, there will be an Eigen matrix of the binary data?
You should give the function at least
- location of the binary data
- type of the binary data (if possible)
- a pointer to reference the Eigen matrix (or object containing it!)
Is it maybe possible to declare a generic matrix, like Eigen::PlainObjectBase Data; that will remain without instantiation and be instantiated inside the function?
Yes, ideally you'll be able to create a pointer and just reference it elsewhere.
You can use a class to contain your matrix and just reference your class elsewhere. You won't be able to use templating such as Eigen::PlainObjectBase
during runtime without unpleasant hacks. If you're a masochist, you could even pre-allocate "enough space" and determine what you've stuffed into it.