2013-10-29 12:18:22 +00:00
|
|
|
#ifndef CSM_WOLRD_INFOCOLLECTION_H
|
|
|
|
#define CSM_WOLRD_INFOCOLLECTION_H
|
|
|
|
|
2021-08-01 11:13:47 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
|
2013-10-29 12:18:22 +00:00
|
|
|
#include "collection.hpp"
|
2013-11-01 16:43:45 +00:00
|
|
|
#include "info.hpp"
|
2013-10-29 12:18:22 +00:00
|
|
|
|
2013-10-31 11:16:45 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
2015-03-13 21:09:19 +00:00
|
|
|
struct Dialogue;
|
2013-10-31 11:16:45 +00:00
|
|
|
}
|
|
|
|
|
2021-07-23 06:05:58 +00:00
|
|
|
namespace CSMWorld
|
|
|
|
{
|
|
|
|
template<>
|
|
|
|
void Collection<Info, IdAccessor<Info> >::removeRows (int index, int count);
|
|
|
|
|
|
|
|
template<>
|
|
|
|
void Collection<Info, IdAccessor<Info> >::insertRecord (std::unique_ptr<RecordBase> record,
|
|
|
|
int index, UniversalId::Type type);
|
|
|
|
|
|
|
|
template<>
|
|
|
|
bool Collection<Info, IdAccessor<Info> >::reorderRowsImp (int baseIndex,
|
|
|
|
const std::vector<int>& newOrder);
|
|
|
|
|
2013-11-01 16:43:45 +00:00
|
|
|
class InfoCollection : public Collection<Info, IdAccessor<Info> >
|
2013-10-29 12:18:22 +00:00
|
|
|
{
|
2013-11-08 10:52:30 +00:00
|
|
|
public:
|
|
|
|
|
2021-07-23 04:21:21 +00:00
|
|
|
typedef std::vector<std::unique_ptr<Record<Info> > >::const_iterator RecordConstIterator;
|
2013-11-10 12:00:46 +00:00
|
|
|
typedef std::pair<RecordConstIterator, RecordConstIterator> Range;
|
2013-11-08 10:52:30 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2021-07-23 06:05:58 +00:00
|
|
|
// The general strategy is to keep the records in Collection kept in order (within
|
|
|
|
// a topic group) while the index lookup maps are not ordered. It is assumed that
|
|
|
|
// each topic has a small number of infos, which allows the use of vectors for
|
|
|
|
// iterating through them without too much penalty.
|
|
|
|
//
|
2021-07-23 23:17:48 +00:00
|
|
|
// NOTE: topic string as well as id string are stored in lower case.
|
|
|
|
std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > mInfoIndex;
|
2021-07-23 06:05:58 +00:00
|
|
|
|
2013-11-01 16:43:45 +00:00
|
|
|
void load (const Info& record, bool base);
|
2013-10-29 12:18:22 +00:00
|
|
|
|
2015-03-13 21:09:19 +00:00
|
|
|
int getInfoIndex (const std::string& id, const std::string& topic) const;
|
2013-11-09 10:42:19 +00:00
|
|
|
///< Return index for record \a id or -1 (if not present; deleted records are considered)
|
|
|
|
///
|
|
|
|
/// \param id info ID without topic prefix
|
2021-07-23 06:05:58 +00:00
|
|
|
//
|
|
|
|
/// \attention id and topic are assumed to be in lower case
|
2013-11-09 10:42:19 +00:00
|
|
|
|
2013-10-29 12:18:22 +00:00
|
|
|
public:
|
|
|
|
|
2021-07-23 06:05:58 +00:00
|
|
|
int getInsertIndex (const std::string& id,
|
|
|
|
UniversalId::Type type = UniversalId::Type_None,
|
|
|
|
RecordBase *record = nullptr) const override;
|
2013-11-08 11:16:41 +00:00
|
|
|
///< \param type Will be ignored, unless the collection supports multiple record types
|
2021-07-23 06:05:58 +00:00
|
|
|
///
|
|
|
|
/// Works like getAppendIndex unless an overloaded method uses the record pointer
|
|
|
|
/// to get additional info about the record that results in an alternative index.
|
2013-11-08 11:16:41 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool reorderRows (int baseIndex, const std::vector<int>& newOrder) override;
|
2013-11-14 10:39:14 +00:00
|
|
|
///< Reorder the rows [baseIndex, baseIndex+newOrder.size()) according to the indices
|
|
|
|
/// given in \a newOrder (baseIndex+newOrder[0] specifies the new index of row baseIndex).
|
|
|
|
///
|
|
|
|
/// \return Success?
|
|
|
|
|
2013-10-31 11:16:45 +00:00
|
|
|
void load (ESM::ESMReader& reader, bool base, const ESM::Dialogue& dialogue);
|
2013-11-08 10:52:30 +00:00
|
|
|
|
2013-11-10 12:00:46 +00:00
|
|
|
Range getTopicRange (const std::string& topic) const;
|
2013-11-08 10:52:30 +00:00
|
|
|
///< Return iterators that point to the beginning and past the end of the range for
|
|
|
|
/// the given topic.
|
2015-07-18 17:32:10 +00:00
|
|
|
|
|
|
|
void removeDialogueInfos(const std::string& dialogueId);
|
2021-07-23 06:05:58 +00:00
|
|
|
|
2021-08-01 11:14:05 +00:00
|
|
|
void removeRows (int index, int count) override;
|
2021-07-23 06:05:58 +00:00
|
|
|
|
|
|
|
void appendBlankRecord (const std::string& id,
|
2021-08-01 11:14:05 +00:00
|
|
|
UniversalId::Type type = UniversalId::Type_None) override;
|
2021-07-23 06:05:58 +00:00
|
|
|
|
2021-08-01 11:14:05 +00:00
|
|
|
int searchId (const std::string& id) const override;
|
2021-07-23 06:05:58 +00:00
|
|
|
|
|
|
|
void appendRecord (std::unique_ptr<RecordBase> record,
|
2021-08-01 11:14:05 +00:00
|
|
|
UniversalId::Type type = UniversalId::Type_None) override;
|
2021-07-23 06:05:58 +00:00
|
|
|
|
|
|
|
void insertRecord (std::unique_ptr<RecordBase> record,
|
|
|
|
int index,
|
2021-08-01 11:14:05 +00:00
|
|
|
UniversalId::Type type = UniversalId::Type_None) override;
|
2013-10-29 12:18:22 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-03-11 14:54:45 +00:00
|
|
|
#endif
|