Valhalla Legends Forums Archive | C/C++ Programming | Problems retrieving std::map values (CONFUSING!)

AuthorMessageTime
warz
NOTE: I wrote this thread on another forum, which is why I'm real vague with this. I'm messing around with Skywing's flags union, trying to associate a username, with it's flag union.

This might be a little confusing. Bare with me. I've got a map declared like...

[code]
typedef std::map<std::string, UserAttributes> themap;
themap accessmap;
[/code]

UserAttributes is a union containing a few structs, some functions to modifiy a dword (bitshifting), and the dword being modified. I read a username and an access 'level' from a text file of mine. I need the username to be the std::string value of the map, which is easy. While reading these values from the text file, I place the access level in a non-globally initialized UserAttributes variable. Then, I plug my username string, and the modified UserAttributes union into the map. My function for this is...

[code]
bool readdatabase(std::string filename) {
printchat(false, "Populating user map...");
std::ifstream database(filename.c_str());

if(!database.is_open())
return false;

std::string username, access;
while(!database.eof()) {
database >> username >> access;

UserAttributes accessmanip;
for(int x=0; x != access.length(); x++) {
accessmanip.Set(access[x]);
}
accessmap[username] = accessmanip;
}
database.close();

printchat(false, "OK!\n");
return true;
}
[/code]

all this appears to be done with no errors. Now, my map should contain a list of usernames and their appropriate UserAttributes union, correct? I know it contains the usernames, because when I search the map for them they appear. I don't think the UserAttributes union, though, stays how I modified it when I put it into the map. When I use an iterator to extract the UserAttributes union out of the map, and then use my functions in the union to check the values of the bits that I set prior to placing them in the map, they don't seem to return what I am wanting. Here's how I'm checking the map's contents...

[code]
int main(int argc, char *argv[]) {
readdatabase("users.db");

themap::iterator iter = accessmap.begin();

while(iter != accessmap.end()) {
std::cout << (*iter).first << " has B flag? ";
UserAttributes accessmanip;
accessmanip = (*iter).second;

if(!accessmanip.Check('B'))
std::cout << "nope" << std::endl;
else
std::cout << "yes" << std::endl;

iter++;
}

return (0);
}
[/code]

It's telling me that every user has the 'B' flag, when only one should have it. I geuss my main question is, when I modify my UserAttributes union, then put it in the map, does it retain all the information that it help before it was put in the map?

I guess if you see anything wrong, please point it out

Thanks
March 22, 2006, 5:13 AM
warz
Sovled. Before inserting the UserAttributes union into my map, I went ahead and initialized dwFlags to 0.
March 22, 2006, 4:06 PM

Search