jeudi 23 septembre 2021

How to make a macro that generates a method with a target class's members?

Can a macro be made to generate a method for a target class with its variables? specifically a class method that just gets the target class's member offsets. like in below code, a method named GetOffsets(){} for my usage scenario, either a generated method that returns a list or a void return method that sets to a static list variable called offsets would be fine.

MetaClass(Actor,{
public:
    float integer = 70.0f;
    float floater = 2;
    vec3 vector = vec3(5,3,3);
    std::vector<float> lister({56,3,4,5});
    std::vector<size_t> GetOffset(){
        std::vector<size_t> offsets;
        offsets.Add(offsetof(Actor,integer));
        offsets.Add(offsetof(Actor,floater));
        offsets.Add(offsetof(Actor,vector));
        offsets.Add(offsetof(Actor,lister));
        return offsets;
    }
});

Here above, MetaClass is the macro and Actor is the target class for the macro. as an example. some code or alternate suggestions for would be helpful. this meta/offset information will be used for reflection purposes.





Aucun commentaire:

Enregistrer un commentaire