billyquith / ponder

C++ reflection library with Lua binding, and JSON and XML serialisation.
http://billyquith.github.io/ponder/
Other
633 stars 92 forks source link

Access ArrayProperty element type #102

Closed MrFloopy closed 5 years ago

MrFloopy commented 5 years ago

Hi,

If I register a std::vector of pointers to some base class, I can access those elements and correctly query the class of any element in the array.

Is there any way to find the base class ponder::Class structure of the array through ponder?

billyquith commented 5 years ago

Is there any way to find the base class ponder::Class structure of the array through ponder?

I'm not quite sure what you mean. The "base class"? Do you mean the Class that owns the std::vector member?

The std::vector would be an array property and you can't get the container class from the property. This question hasn't been asked before. Currently I guess you'd have to iterate through the classes and find the property.

MrFloopy commented 5 years ago

Thank you for replying. Loving Ponder so far.

It might help if I explain what I want to do:

I register a class property which is a std::vector<base*> object.

Now, I have lots of things that are derived from base and the array can hold a pointer to any of them.

I want to be able to query the array property to somehow determine that it is an array of "base" objects, so I can search through the other registered classes to create a list of possible classes that could be created and placed as an element in the std::vector.

The problem is, I can't find a way to determine the ponder::Class object for the base class in the array. It would appear that the array itself can't be referenced as a ponder::UserObject from which I could obtain the Class reference.

billyquith commented 5 years ago

Thank you for replying. Loving Ponder so far.

Thanks! I'm working on V3 at the moment.

I want to be able to query the array property to somehow determine that it is an array of "base" objects,

Don't you know that from the name of the property? If not, you could use tags to mark things up, and then see what has the tag you require. In V3 you can add arbitrary metadata to any type, which should make things easier.

MrFloopy commented 5 years ago

I don't know from the name of the property as the object could have been registered in a plugin by someone else, so can't assume that knowledge?

I have worked around it with tags for now.

billyquith commented 5 years ago

I don't know from the name of the property as the object could have been registered in a plugin by someone else, so can't assume that knowledge?

I guess it would be nice to be able to query the Class API by type, or be able to enquire type information from the members.

I have worked around it with tags for now.

That should work quite well. I have added metadata to V3, which is name-string value pairs, and you can have an arbitrary number. So these could be used for tags, or other data. I was also thinking of allowing them to be registered and unregistered when they are created, so the user system could be notified.

I'm trying to get a V3 alpha version out. I'll try and do that in the next couple of weeks.