billyquith / ponder

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

Property value by index shortcuts #14

Closed iwbnwif closed 8 years ago

iwbnwif commented 8 years ago

The shortcut UserObject::get(const std::string & property) is provided as a shortcut for object.getClass().property(name).get(object).

Would it be possible to provide an equivalent for indexed access to properties, i.e. UserObject::get(const size_t index)?

Justification: this helps when iterating over all properties in a class instance.

Probably it would be good to provide the set equivalent for completeness.

iwbnwif commented 8 years ago

Another related enhancement might be to expose the property lists, at least sorted by position. This will allow the use of range-based-for to iterate through the properties (and possibly functions if there is a use case for that).

For example:

int i = 0; for (const ponder::Property& prop : metaclass.propertyList())
{
        std::cout << "Field " << i++ << " is: " << prop.name() << std::endl;

        // Check for width and hidden tags.
        if (prop.hasTag("width"))
            std::cout << "Field " << prop.name() << " has width: " << prop.tag("width") << std::endl;
}   
billyquith commented 8 years ago

In 1.1 branch: Access by index added. Property and function iterators added.