mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-09 03:39:14 +00:00
split reclists find function into find and search functions (search can be used to check if an object does not exist, while find would see this as an error situation and would throw an exception)
This commit is contained in:
parent
61d09c4768
commit
80000866fe
@ -7,6 +7,7 @@
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <assert.h>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace ESMS
|
||||
{
|
||||
@ -45,13 +46,24 @@ namespace ESMS
|
||||
}
|
||||
|
||||
// Find the given object ID, or return NULL if not found.
|
||||
const X* find(const std::string &id) const
|
||||
const X* search(const std::string &id) const
|
||||
{
|
||||
std::string id2 = toLower (id);
|
||||
if(list.find(id2) == list.end())
|
||||
return NULL;
|
||||
return &list.find(id2)->second;
|
||||
}
|
||||
|
||||
// Find the given object ID (throws an exception if not found)
|
||||
const X* find(const std::string &id) const
|
||||
{
|
||||
const X *object = search (id);
|
||||
|
||||
if (!object)
|
||||
throw std::runtime_error ("object " + id + " not found");
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
int getSize() { return list.size(); }
|
||||
};
|
||||
@ -76,7 +88,7 @@ namespace ESMS
|
||||
}
|
||||
|
||||
// Find the given object ID, or return NULL if not found.
|
||||
const X* find(const std::string &id) const
|
||||
const X* search(const std::string &id) const
|
||||
{
|
||||
std::string id2 = toLower (id);
|
||||
if(list.find(id2) == list.end())
|
||||
@ -84,6 +96,17 @@ namespace ESMS
|
||||
return &list.find(id2)->second;
|
||||
}
|
||||
|
||||
// Find the given object ID (throws an exception if not found)
|
||||
const X* find(const std::string &id) const
|
||||
{
|
||||
const X *object = search (id);
|
||||
|
||||
if (!object)
|
||||
throw std::runtime_error ("object " + id + " not found");
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
int getSize() { return list.size(); }
|
||||
};
|
||||
|
||||
@ -177,7 +200,7 @@ namespace ESMS
|
||||
}
|
||||
|
||||
// Find the given object ID, or return NULL if not found.
|
||||
const X* find(const std::string &id) const
|
||||
const X* search(const std::string &id) const
|
||||
{
|
||||
std::string id2 = toLower (id);
|
||||
if(list.find(id2) == list.end())
|
||||
@ -185,6 +208,17 @@ namespace ESMS
|
||||
return &list.find(id2)->second;
|
||||
}
|
||||
|
||||
// Find the given object ID (throws an exception if not found)
|
||||
const X* find(const std::string &id) const
|
||||
{
|
||||
const X *object = search (id);
|
||||
|
||||
if (!object)
|
||||
throw std::runtime_error ("object " + id + " not found");
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
int getSize() { return list.size(); }
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user