1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 22:23:51 +00:00

improved record searching

This commit is contained in:
Marc Zinnschlag 2010-09-12 09:44:12 +02:00
parent 0414d7f862
commit 9a2f128f58

View file

@ -49,10 +49,14 @@ namespace ESMS
// Find the given object ID, or return NULL if not found. // Find the given object ID, or return NULL if not found.
const X* search(const std::string &id) const const X* search(const std::string &id) const
{ {
std::string id2 = toLower (id); std::string id2 = toLower (id);
if(list.find(id2) == list.end())
return NULL; typename MapType::const_iterator iter = list.find (id2);
return &list.find(id2)->second;
if (iter == list.end())
return NULL;
return &iter->second;
} }
// Find the given object ID (throws an exception if not found) // Find the given object ID (throws an exception if not found)
@ -87,10 +91,13 @@ namespace ESMS
// Find the given object ID, or return NULL if not found. // Find the given object ID, or return NULL if not found.
const X* search(const std::string &id) const const X* search(const std::string &id) const
{ {
std::string id2 = toLower (id); std::string id2 = toLower (id);
if(list.find(id2) == list.end())
return NULL; typename MapType::const_iterator iter = list.find (id2);
return &list.find(id2)->second;
if (iter == list.end())
return NULL;
return &iter->second;
} }
// Find the given object ID (throws an exception if not found) // Find the given object ID (throws an exception if not found)
@ -129,10 +136,14 @@ namespace ESMS
// Find the given object ID, or return NULL if not found. // Find the given object ID, or return NULL if not found.
const X* search(const std::string &id) const const X* search(const std::string &id) const
{ {
std::string id2 = toLower (id); std::string id2 = toLower (id);
if(list.find(id2) == list.end())
return NULL; typename MapType::const_iterator iter = list.find (id2);
return &list.find(id2)->second;
if (iter == list.end())
return NULL;
return &iter->second;
} }
// Find the given object ID (throws an exception if not found) // Find the given object ID (throws an exception if not found)
@ -288,10 +299,14 @@ namespace ESMS
// Find the given object ID, or return NULL if not found. // Find the given object ID, or return NULL if not found.
const X* search(const std::string &id) const const X* search(const std::string &id) const
{ {
std::string id2 = toLower (id); std::string id2 = toLower (id);
if(list.find(id2) == list.end())
return NULL; typename MapType::const_iterator iter = list.find (id2);
return &list.find(id2)->second;
if (iter == list.end())
return NULL;
return &iter->second;
} }
// Find the given object ID (throws an exception if not found) // Find the given object ID (throws an exception if not found)
@ -331,10 +346,12 @@ namespace ESMS
// Find the given object ID, or return NULL if not found. // Find the given object ID, or return NULL if not found.
const X* search (int id) const const X* search (int id) const
{ {
if (list.find (id) == list.end()) typename MapType::const_iterator iter = list.find (id);
if (iter == list.end())
return NULL; return NULL;
return &list.find(id)->second; return &iter->second;
} }
// Find the given object ID (throws an exception if not found) // Find the given object ID (throws an exception if not found)