STL Map and orxObject_GetName

edited August 2012 in Help request
I made a class which has this map:
std::map<const orxSTRING, int> cellNames;

Now I fill it with values in the constructor:
LogicalLevelEntries::LogicalLevelEntries(){	
	cellNames["EmptyCell"] = 0;
	cellNames["WhiteMouseCell"] = 1;
	cellNames["BlackMouseCell"] = 2;
	cellNames["UnusedCell"] = 3;
}

Then I have a method which prints out content of the map like this:
orxLOG("name: %s mapping: %i", orxObject_GetName(nextCell), cellNames[orxObject_GetName(nextCell)]);

Despite calling different names, map always returns 0. I guess it's a problem with declaring key type - but I have no idea how to set it to make things work properly. How can I fix it?

Comments

  • edited August 2012
    I'm no STL expert but I have the feeling that std::map is going to use the operator== for comparing keys, which means it'll do a basic pointer comparison instead of doing a string comparison.
    My guess is that you'll have to wrap the C/orx strings with a C++ std::string in order for this to work.

    Out of curiosity, why don't you use the config system to store your info instead?
  • edited August 2012
    And a quick example:
    // In config
    [EmptyCell]
    LogicalLevel = 0
    
    [WhiteMouseCell]
    LogicalLevel = 1
    
    ...
    
    // In code
    orxConfig_PushSection(orxObject_GetName(nextCell));
    orxLOG("name: %s mapping: %i", orxObject_GetName(nextCell), orxConfig_GetS32("LogicalLevel"));
    orxConfig_PopSection();
    
  • edited August 2012
    Didn't really know I could do that (on the second thought.. I surely read about that in some tutorial). Thanks for the tip - it works great! :)
  • edited August 2012
    Hi xZPFxBarteq, I previously stored my map info in arrays but I am moving to the config myself (hence my other post in this section).

    But I'll be doing another tutorial shortly to explain the "official" config way of doing it.
Sign In or Register to comment.