diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index a4cdec4eac..1eee36ae97 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -51,6 +51,10 @@ namespace CSMWorld Collection (const Collection&); Collection& operator= (const Collection&); + protected: + + const std::map& getIdMap() const; + public: Collection(); @@ -128,6 +132,12 @@ namespace CSMWorld ///< \attention This function must not change the ID. }; + template + const std::map& Collection::getIdMap() const + { + return mIndex; + } + template Collection::Collection() {} diff --git a/apps/opencs/model/world/infocollection.cpp b/apps/opencs/model/world/infocollection.cpp index 1be186f760..215354f593 100644 --- a/apps/opencs/model/world/infocollection.cpp +++ b/apps/opencs/model/world/infocollection.cpp @@ -4,6 +4,8 @@ #include #include +#include + void CSMWorld::InfoCollection::load (const Info& record, bool base) { int index = searchId (record.mId); @@ -34,7 +36,8 @@ void CSMWorld::InfoCollection::load (const Info& record, bool base) void CSMWorld::InfoCollection::load (ESM::ESMReader& reader, bool base, const ESM::Dialogue& dialogue) { /// \todo put records into proper order - std::string id = dialogue.mId + "#" + reader.getHNOString ("INAM"); + std::string id = Misc::StringUtils::lowerCase (dialogue.mId) + "#" + + reader.getHNOString ("INAM"); if (reader.isNextSub ("DELE")) { @@ -71,3 +74,26 @@ void CSMWorld::InfoCollection::load (ESM::ESMReader& reader, bool base, const ES load (record, base); } } + +std::pair + CSMWorld::InfoCollection::getTopicRange (const std::string& topic) const +{ + std::string topic2 = Misc::StringUtils::lowerCase (topic); + + MapConstIterator begin = getIdMap().lower_bound (topic2); + + // Skip invalid records: The beginning of a topic string could be identical to another topic + // string. + for (; begin!=getIdMap().end(); ++begin) + if (getRecord (begin->second).get().mTopicId==topic) + break; + + // Find end + MapConstIterator end = begin; + + for (; end!=getIdMap().end(); ++end) + if (getRecord (end->second).get().mTopicId!=topic) + break; + + return std::make_pair (begin, end); +} \ No newline at end of file diff --git a/apps/opencs/model/world/infocollection.hpp b/apps/opencs/model/world/infocollection.hpp index 5faf61a8c7..f92e63e81d 100644 --- a/apps/opencs/model/world/infocollection.hpp +++ b/apps/opencs/model/world/infocollection.hpp @@ -13,11 +13,22 @@ namespace CSMWorld { class InfoCollection : public Collection > { + public: + + typedef std::map::const_iterator MapConstIterator; + + private: + void load (const Info& record, bool base); public: void load (ESM::ESMReader& reader, bool base, const ESM::Dialogue& dialogue); + + std::pair getTopicRange (const std::string& topic) + const; + ///< Return iterators that point to the beginning and past the end of the range for + /// the given topic. }; }