1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-18 13:12:50 +00:00

Topic range access in InfoCollection

This commit is contained in:
Marc Zinnschlag 2013-11-08 11:52:30 +01:00
parent 0745a86039
commit 982024a328
3 changed files with 48 additions and 1 deletions

View File

@ -51,6 +51,10 @@ namespace CSMWorld
Collection (const Collection&);
Collection& operator= (const Collection&);
protected:
const std::map<std::string, int>& getIdMap() const;
public:
Collection();
@ -128,6 +132,12 @@ namespace CSMWorld
///< \attention This function must not change the ID.
};
template<typename ESXRecordT, typename IdAccessorT>
const std::map<std::string, int>& Collection<ESXRecordT, IdAccessorT>::getIdMap() const
{
return mIndex;
}
template<typename ESXRecordT, typename IdAccessorT>
Collection<ESXRecordT, IdAccessorT>::Collection()
{}

View File

@ -4,6 +4,8 @@
#include <components/esm/esmreader.hpp>
#include <components/esm/loaddial.hpp>
#include <components/misc/stringops.hpp>
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::MapConstIterator, CSMWorld::InfoCollection::MapConstIterator>
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);
}

View File

@ -13,11 +13,22 @@ namespace CSMWorld
{
class InfoCollection : public Collection<Info, IdAccessor<Info> >
{
public:
typedef std::map<std::string, int>::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<MapConstIterator, MapConstIterator> getTopicRange (const std::string& topic)
const;
///< Return iterators that point to the beginning and past the end of the range for
/// the given topic.
};
}