3 keys ordered map in C++
I have a 3 component vector struct called Vector3 with 3 int representing
X, Y and Z. For each 3D point (I have more or less 200-300 different 3D
points) I have a string.
What I want to do is to have a data structure that checks if there is a
string for that location. I wanted to use a std::map and I made this code
without good results:
The error it has is that It just runs the else part once, and keeps
returning the same string over and over.
My Vector3 class is the one in Ogre3D:
http://www.ogre3d.org/docs/api/html/classOgre_1_1Vector3.html
String WorldGenerator::createPlatformBorder(Vector3 size)
{
static std::map<Vector3, String> generatedBorders;
if (generatedBorders.find(size) != generatedBorders.end())
{
return generatedBorders[size];
}
else
{
String blockName = requestNewPlatformBorderName();
generatedBorders.insert(std::pair<Vector3, String>(size, blockName));
// some logic
return blockName;
}
}
Could you help me out, please?
Note that the function requestNewPlatformBorderName() works perfectly
fine, so the bug isn't there. Here is the code for it:
String requestNewPlatformBorderName()
{
static int counter = 0;
return StringConverter::toString(++counter) + "-platform-border";
}
No comments:
Post a Comment