1 #ifndef CSM_WOLRD_COLLECTION_H
2 #define CSM_WOLRD_COLLECTION_H
22 template<
typename ESXRecordT>
25 std::string&
getId (ESXRecordT& record);
27 const std::string
getId (
const ESXRecordT& record)
const;
30 template<
typename ESXRecordT>
36 template<
typename ESXRecordT>
43 template<
typename ESXRecordT,
typename IdAccessorT = IdAccessor<ESXRecordT> >
62 const std::map<std::string, int>&
getIdMap()
const;
64 const std::vector<Record<ESXRecordT> >&
getRecords()
const;
66 bool reorderRowsImp (
int baseIndex,
const std::vector<int>& newOrder);
78 void add (
const ESXRecordT& record);
83 virtual std::string
getId (
int index)
const;
85 virtual int getIndex (
const std::string&
id)
const;
89 virtual QVariant
getData (
int index,
int column)
const;
91 virtual void setData (
int index,
int column,
const QVariant& data);
101 virtual void removeRows (
int index,
int count) ;
107 virtual void cloneRecord(
const std::string& origin,
108 const std::string& destination,
111 virtual int searchId (
const std::string&
id)
const;
133 virtual std::vector<std::string>
getIds (
bool listDeleted =
true)
const;
147 virtual bool reorderRows (
int baseIndex,
const std::vector<int>& newOrder);
161 template<
typename ESXRecordT,
typename IdAccessorT>
167 template<
typename ESXRecordT,
typename IdAccessorT>
173 template<
typename ESXRecordT,
typename IdAccessorT>
175 const std::vector<int>& newOrder)
177 if (!newOrder.empty())
179 int size =
static_cast<int> (newOrder.size());
182 std::vector<int>
test (newOrder);
183 std::sort (test.begin(), test.end());
184 if (*test.begin()!=0 || *--test.end()!=size-1)
188 std::vector<Record<ESXRecordT> > buffer (size);
190 for (
int i=0; i<size; ++i)
192 buffer[newOrder[i]] = mRecords [baseIndex+i];
193 buffer[newOrder[i]].setModified (buffer[newOrder[i]].
get());
196 std::copy (buffer.begin(), buffer.end(), mRecords.begin()+baseIndex);
199 for (std::map<std::string, int>::iterator iter (mIndex.begin()); iter!=mIndex.end();
201 if (iter->second>=baseIndex && iter->second<baseIndex+size)
202 iter->second = newOrder.at (iter->second-baseIndex)+baseIndex;
208 template<
typename ESXRecordT,
typename IdAccessorT>
210 const std::string& destination,
214 copy.
mModified = getRecord(origin).get();
216 copy.
get().mId = destination;
218 insertRecord(copy, getAppendIndex(destination, type));
221 template<
typename ESXRecordT,
typename IdAccessorT>
225 template<
typename ESXRecordT,
typename IdAccessorT>
228 for (
typename std::vector<
Column<ESXRecordT> *>::iterator iter (mColumns.begin()); iter!=mColumns.end(); ++iter)
232 template<
typename ESXRecordT,
typename IdAccessorT>
237 std::map<std::string, int>::iterator iter = mIndex.find (
id);
239 if (iter==mIndex.end())
245 insertRecord (record2, getAppendIndex (
id));
249 mRecords[iter->second].setModified (record);
253 template<
typename ESXRecordT,
typename IdAccessorT>
256 return mRecords.size();
259 template<
typename ESXRecordT,
typename IdAccessorT>
262 return IdAccessorT().getId (mRecords.at (index).get());
265 template<
typename ESXRecordT,
typename IdAccessorT>
271 throw std::runtime_error (
"invalid ID: " +
id);
276 template<
typename ESXRecordT,
typename IdAccessorT>
279 return mColumns.size();
282 template<
typename ESXRecordT,
typename IdAccessorT>
285 return mColumns.at (column)->get (mRecords.at (index));
288 template<
typename ESXRecordT,
typename IdAccessorT>
291 return mColumns.at (column)->set (mRecords.at (index), data);
294 template<
typename ESXRecordT,
typename IdAccessorT>
297 return *mColumns.at (column);
300 template<
typename ESXRecordT,
typename IdAccessorT>
303 if (column < 0 || column >= static_cast<int>(mColumns.size()))
304 throw std::runtime_error(
"column index out of range");
306 return mColumns.at (column);
309 template<
typename ESXRecordT,
typename IdAccessorT>
312 mColumns.push_back (column);
315 template<
typename ESXRecordT,
typename IdAccessorT>
318 for (
typename std::vector<
Record<ESXRecordT> >::iterator iter (mRecords.begin()); iter!=mRecords.end(); ++iter)
324 template<
typename ESXRecordT,
typename IdAccessorT>
329 while (i<static_cast<int> (mRecords.size()))
331 if (mRecords[i].isErased())
338 template<
typename ESXRecordT,
typename IdAccessorT>
341 mRecords.erase (mRecords.begin()+index, mRecords.begin()+index+count);
343 typename std::map<std::string, int>::iterator iter = mIndex.begin();
345 while (iter!=mIndex.end())
347 if (iter->second>=index)
349 if (iter->second>=index+count)
351 iter->second -= count;
356 mIndex.erase (iter++);
364 template<
typename ESXRecordT,
typename IdAccessorT>
369 IdAccessorT().getId (record) = id;
376 insertRecord (record2, getAppendIndex (
id, type), type);
379 template<
typename ESXRecordT,
typename IdAccessorT>
384 std::map<std::string, int>::const_iterator iter = mIndex.find (id2);
386 if (iter==mIndex.end())
392 template<
typename ESXRecordT,
typename IdAccessorT>
398 template<
typename ESXRecordT,
typename IdAccessorT>
402 insertRecord (record,
403 getAppendIndex (IdAccessorT().
getId (
407 template<
typename ESXRecordT,
typename IdAccessorT>
411 return static_cast<int> (mRecords.size());
414 template<
typename ESXRecordT,
typename IdAccessorT>
417 std::vector<std::string> ids;
419 for (
typename std::map<std::string, int>::const_iterator iter = mIndex.begin();
420 iter!=mIndex.end(); ++iter)
422 if (listDeleted || !mRecords[iter->second].isDeleted())
423 ids.push_back (IdAccessorT().
getId (mRecords[iter->second].get()));
429 template<
typename ESXRecordT,
typename IdAccessorT>
432 int index = getIndex (
id);
433 return mRecords.at (index);
436 template<
typename ESXRecordT,
typename IdAccessorT>
439 return mRecords.at (index);
442 template<
typename ESXRecordT,
typename IdAccessorT>
446 if (index<0 || index>static_cast<int> (mRecords.size()))
447 throw std::runtime_error (
"index out of range");
451 mRecords.insert (mRecords.begin()+index, record2);
453 if (index<static_cast<int> (mRecords.size())-1)
455 for (std::map<std::string, int>::iterator iter (mIndex.begin()); iter!=mIndex.end();
457 if (iter->second>=index)
462 record2.
get())), index));
465 template<
typename ESXRecordT,
typename IdAccessorT>
470 throw std::runtime_error (
"attempt to change the ID of a record");
472 mRecords.at (index) = record;
475 template<
typename ESXRecordT,
typename IdAccessorT>
virtual bool reorderRows(int baseIndex, const std::vector< int > &newOrder)
Definition: collection.hpp:476
virtual std::string getId(int index) const
Definition: collection.hpp:260
virtual void appendBlankRecord(const std::string &id, UniversalId::Type type=UniversalId::Type_None)
Definition: collection.hpp:365
Collection & operator=(const Collection &)
int getId(const std::string &name)
Will return -1 for an invalid name.
Definition: columns.cpp:377
State mState
Definition: record.hpp:19
Collection()
Definition: collection.hpp:222
const std::vector< Record< ESXRecordT > > & getRecords() const
Definition: collection.hpp:168
Definition: columnbase.hpp:167
static std::string lowerCase(const std::string &in)
Returns lower case copy of input string.
Definition: stringops.hpp:103
Type
Definition: universalid.hpp:40
bool reorderRowsImp(int baseIndex, const std::vector< int > &newOrder)
Definition: collection.hpp:174
void addColumn(Column< ESXRecordT > *column)
Definition: collection.hpp:310
std::vector< Record< ESXRecordT > > mRecords
Definition: collection.hpp:52
Single-type record collection.
Definition: collection.hpp:44
virtual int searchId(const std::string &id) const
Definition: collection.hpp:380
virtual const Record< ESXRecordT > & getRecord(const std::string &id) const
Definition: collection.hpp:430
const std::map< std::string, int > & getIdMap() const
Definition: collection.hpp:162
virtual int getIndex(const std::string &id) const
Definition: collection.hpp:266
virtual ~Collection()
Definition: collection.hpp:226
std::string & getId(ESXRecordT &record)
Definition: collection.hpp:31
virtual int getAppendIndex(const std::string &id, UniversalId::Type type=UniversalId::Type_None) const
Definition: collection.hpp:408
virtual int getColumns() const
Definition: collection.hpp:277
MWWorld::Ptr searchId(MWWorld::CellRefList< T > &list, const std::string &id, MWWorld::ContainerStore *store)
Definition: containerstore.cpp:42
virtual void replace(int index, const RecordBase &record)
Definition: collection.hpp:393
Definition: nestedcolumnadapter.hpp:11
std::map< std::string, int > mIndex
Definition: collection.hpp:53
Definition: columnbase.hpp:185
void setRecord(int index, const Record< ESXRecordT > &record)
Definition: collection.hpp:466
Definition: record.hpp:14
virtual void insertRecord(const RecordBase &record, int index, UniversalId::Type type=UniversalId::Type_None)
Definition: collection.hpp:443
virtual const ColumnBase & getColumn(int column) const
Definition: collection.hpp:295
virtual void purge()
Remove records that are flagged as erased.
Definition: collection.hpp:325
ESXRecordT mModified
Definition: record.hpp:41
void add(const ESXRecordT &record)
Add a new record (modified)
Definition: collection.hpp:233
virtual void setData(int index, int column, const QVariant &data)
Definition: collection.hpp:289
virtual void removeRows(int index, int count)
< Merge modified into base.
Definition: collection.hpp:339
virtual void merge()
Merge modified into base.
Definition: collection.hpp:316
const ESXRecordT & get() const
Throws an exception, if the record is deleted.
Definition: record.hpp:106
Definition: columnbase.hpp:15
Base class for record collections.
Definition: collectionbase.hpp:23
virtual int getSize() const
Definition: collection.hpp:254
void test(const MWWorld::Ptr &actor, int &compiled, int &total, const Compiler::Extensions *extensions, int warningsMode)
Definition: scripttest.cpp:27
virtual void cloneRecord(const std::string &origin, const std::string &destination, const UniversalId::Type type)
Definition: collection.hpp:209
virtual std::vector< std::string > getIds(bool listDeleted=true) const
Definition: collection.hpp:415
Access to ID field in records.
Definition: collection.hpp:23
NestableColumn * getNestableColumn(int column) const
Definition: collection.hpp:301
Definition: universalid.hpp:42
ESXRecordT ESXRecord
Definition: collection.hpp:48
virtual QVariant getData(int index, int column) const
Definition: collection.hpp:283
std::vector< Column< ESXRecordT > * > mColumns
Definition: collection.hpp:54
virtual void appendRecord(const RecordBase &record, UniversalId::Type type=UniversalId::Type_None)
Definition: collection.hpp:399