I have a std::map variable that contains a std::string as its first parameter and a struct for its second.
struct entry {
std::string state; // works like an url eg. "/login" shows login
std::string description; // menu entry description eg. "login here"
int minAuth; // maximum user authorization level
int maxAuth; // minimum user authorization level
void (*fptr)(); //function to be called on match
bool active = false; // true if this is one of the options displayed
};
std::map<std::string, entry> entries;
What I need to check is the first parameters value and the second value of entry.active in order to correctly display the menu entries. I'm using an active attribute to make sure that if there are other entries with the same std::string (this is the command to start the function entry.fptr), they won't have the same active state.
Explenation for the entry.active attribute:
eg. imagine two different pages; usersPanel and viewImage. Both of these have a command called "download", however they both have different functions. One downloads a log of users, and the other downloads an image. (this is just an example).
I would prefer to have a compare function that checks that the first parameter matches a given input, and that the entry.active is true.
Something like this perhaps?
bool comp (const std::string a, const std::string b) const
{
return (a == b && this.second.active);
}
My second way to handle this would to have a temporary std::map for all the currently active menu entries, but I'm hoping I won't need to add an additional std::map list. The comp() would be so much cleaner.
Pastebin code: http://ift.tt/1MM36Dn
Any suggestions? ^^,
Aucun commentaire:
Enregistrer un commentaire