mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 20:26:43 +00:00 
			
		
		
		
	Topic range access in InfoCollection
This commit is contained in:
		
							parent
							
								
									0745a86039
								
							
						
					
					
						commit
						982024a328
					
				
					 3 changed files with 48 additions and 1 deletions
				
			
		|  | @ -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() | ||||
|     {} | ||||
|  |  | |||
|  | @ -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); | ||||
| } | ||||
|  | @ -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.
 | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue