dimanche 19 août 2018

How to Map Struct members to a string?

In my project, I've to call a 3rd party API which will give the result in the form of a struct (example below).

typedef struct _innerTest
{
    int Status1;
    bool Status2;
    int Status3[];
}InnerTest;

typedef struct _test 
{
    int Status1;
    bool Status2;
    InnerTest InnerStatus;
}Test;

Once I get the results, I have to set these values internally. Each value in the struct will be mapped to a certain string (these strings are required to update the values internally). For example the mapping can be something like below:

Test.Status1                <-->    Status1
Test.Status2                <-->    Status2
Test.InnerStatus.Status1    <-->    Status3
Test.InnerStatus.Status2    <-->    Status4
Test.InnerStatus.Status3[0] <-->    Status5
Test.InnerStatus.Status3[1] <-->    Status6

What would be the best approach to maintain the mapping information. Note that the array size inside the structure can vary. If new status is added for example, I want to just add the mapping information is some xml/config file and the code should work without any changes. I just want some pointers to go forward. (Just FYI, I'm okay with using boost libraries if necessary).

I've tried to explain my problem as simple as possible. Please ask me in comments if more details is required.

Aucun commentaire:

Enregistrer un commentaire