Reputation: 11
I don't know what type on question i am asking.but i only need suggestion or idea to find the way.
I have many structure with large number of members like below
typedef struct _Bank0
{
unsigned char main_control_char;
unsigned short input_port_short;
:
:
}Pack Bank0;
typedef struct _Bank1
{
unsigned char ddr3_control_char;
unsigned char ddl_control_char;
:
:
}Pack Bank1;
I want to write a test function for this register bank, if i give bank number (that is structure name) it should display all the register in that bank.
i just have to avoid repeat programing for testing register, i am trying in following way
select register bank= Bank1(* user will enter this value) //
//now i want to show all register name in bank 1 for example//
ddr3_control_char
ddl_control_char
after this i want to send data to the selected register. can any one suggest me any idea.i just don't want to copy paste register name again because the length of my code will be to more so to avoid it i want suggestion.
Upvotes: 0
Views: 107
Reputation: 2161
You can implement this functionality for every Bank
type individually and then use inheritance, e.g.
using ValueType = size_t;
using Dump = std::unordered_map<std::string, Value_type>;
struct Bank {
virtual Dump dump() const = 0;
};
struct Bank0 : public Bank {
Dump dump() const override {
return Dump();
}
};
struct Bank1 : public Bank {
Dump dump() const override {
return Dump();
}
};
Upvotes: 1