billyquith / ponder

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

Change ponder::Type to enum class #26

Closed billyquith closed 8 years ago

billyquith commented 8 years ago
enum Type
{
    noType,     ///< No type has been defined yet
    boolType,   ///< Boolean type (bool)
    intType,    ///< Integer types (unsigned/signed char short int long)
    realType,   ///< Real types (float, double)
    stringType, ///< String types (char*, std::string)
    enumType,   ///< Enumerated types
    arrayType,  ///< Array types (std::vector, std::list, T[])
    userType    ///< User-defined classes
};

to:

enum class Type
{
    none,   ///< No type has been defined yet
    bool,   ///< Boolean type (bool)
    int,    ///< Integer types (unsigned/signed char short int long)
    real,   ///< Real types (float, double)
    string, ///< String types (char*, std::string)
    enum,   ///< Enumerated types
    array,  ///< Array types (std::vector, std::list, T[])
    user    ///< User-defined classes
};
iwbnwif commented 8 years ago

Is there any way of making this extensible?

I don't think it is possible, but thought I would ask the question.

One of the problems I have come up against is having multiple "user" types. It would be really nice if ponder::Value::type returned which user type it contains.

billyquith commented 8 years ago

Well you get can get the class information from a UserObject?

iwbnwif commented 8 years ago

Sorry for the slow response.

Actually, I forgot exactly the situation where I had problems with this, but I think it was something like:

... iterate through all members of a ponder::Class ...

switch (thisClass.property(i).type())
{
    case ponder::stringType:
        doSomething ();
        break;

    case ponder::userType:
        doSomethingElse ();
        break;
}

I think I was missing a way to get the class of the userType for a given property.

billyquith commented 8 years ago

The property is abstract/generic. There is a ClassVisitor which uses the visitor pattern to allow you to get the details.

iwbnwif commented 8 years ago

Sorry, this was my mistake (again).

Thank you for your hint, I can see from the ClassVisitorexample that there is a ponder::UserProperty::getClass() method which I can use to get at least the string identification for the class.

billyquith commented 8 years ago

Don't worry about it. There are some aspects of this API that seem quite complicated. Perhaps look at the docs and see if they can be improved.