jeudi 25 février 2021

Is it possible to detect if a class has a member with a certain type/return type without knowing the member's name?

I would like to detect if a certain class has member variables/functions of a specific type/return type, without knowing the name of these variables (there is no fixed format of naming them).

for example:

struct Wheel{
    int wheel_size;
}

struct Bike{
    private:
    Wheel weel_1;
    Wheel weel_2;

    public:
    Wheel get_wheel_1();
    Wheel get_wheel_2();
}

Is it possible to determine if Bike has a member of type Wheel or a function of return type Wheel without knowing the names of these members?

Context: I am working on an open source autopilot project. For communication messages, we need to set timestamps for synchronization purposes (Code for setting the timestamp for messages is specified here)

Sometimes these messages have nested messages and the timestamp of each nested message should be updated as well. So I wanted to check if a message has a nested message and if so, I should update the timestamp of both the outer and the inner message/messages.

Note: The C++ code of the messages is auto-generated from a message definition file.

Aucun commentaire:

Enregistrer un commentaire