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 (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.
What I'm trying to accomplish is something like the code below. This isn't a functional code, it's just to clearify how I want the compare() parameter to work. check if the input is similar to the key, and if the map entry has a value.active of true, I want the comp() to return true.
bool comp (const std::string a, const std::string b) const
{
return (a == b && this.second.active);
}
Again, a few have complained about this piece of code so let me say it like this: thats psuedo code, not real code.
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://pastebin.com/1uj40Fw8
Any suggestions? ^^,
SOLUTION
add a extra map holder:
std::map<std::string, entry> entries, activeEntries;
After a map entry is approved by the program rules to be displayed, add it to the activeEntries map:
activeEntries.insert(i);
Then use std::map::find on the activeEntries map to locate the correct user choice, in the entire menu. Also more efficient for larger menus.