From 80000866fe5d7c928bc8b213cf996de00a73b735 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 26 Jul 2010 11:40:03 +0200 Subject: [PATCH] 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) --- components/esm_store/reclists.hpp | 40 ++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/components/esm_store/reclists.hpp b/components/esm_store/reclists.hpp index ba099da94a..5763dc6f9f 100644 --- a/components/esm_store/reclists.hpp +++ b/components/esm_store/reclists.hpp @@ -7,6 +7,7 @@ #include #include #include +#include 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(); } };