load() method for records with string id

This commit is contained in:
greye 2012-10-26 22:46:24 +04:00
parent 5ac54d1fff
commit ce91c5636d

View file

@ -184,7 +184,9 @@ namespace MWWorld
std::vector<T *> mShared;
public:
Store() {}
Store()
: mComp(false)
{}
Store(bool ci)
: mComp(ci)
@ -217,6 +219,31 @@ namespace MWWorld
return ptr;
}
void load(ESM::ESMReader &esm, const std::string &id) {
// reduce size of allocated memory to copy
mData.push_back(T());
// some records requires id before loading
// make sure that string case is the same across container
if (mComp.isCaseInsensitive()) {
mData.back().mId = id;
} else {
mData.back().mId = lowerCase(id);
}
mData.back().load(esm);
// allow records to overwrite id on loading
if (!mComp.isCaseInsensitive()) {
std::string &s = mData.back().mId;
std::transform(
s.begin(),
s.end(),
s.begin(),
(int (*)(int)) std::tolower
);
}
}
void setUp() {
std::sort(mData.begin(), mData.end(), mComp);