(svn r25652) -Fix: Improve text caret movement for complex scripts.
[openttd/fttd.git] / src / newgrf_storage.cpp
blobac91a122f4341ab3284a34a90ac82340cdfae873
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file newgrf_storage.cpp Functionality related to the temporary and persistent storage arrays for NewGRFs. */
12 #include "stdafx.h"
13 #include "newgrf_storage.h"
14 #include "core/pool_func.hpp"
15 #include <set>
17 PersistentStoragePool _persistent_storage_pool("PersistentStorage");
18 INSTANTIATE_POOL_METHODS(PersistentStorage)
20 /** The changed storage arrays */
21 static std::set<BaseStorageArray*> *_changed_storage_arrays = new std::set<BaseStorageArray*>;
23 /**
24 * Remove references to use.
26 BaseStorageArray::~BaseStorageArray()
28 _changed_storage_arrays->erase(this);
31 /**
32 * Add the changed storage array to the list of changed arrays.
33 * This is done so we only have to revert/save the changed
34 * arrays, which saves quite a few clears, etc. after callbacks.
35 * @param storage the array that has changed
37 void AddChangedStorage(BaseStorageArray *storage)
39 _changed_storage_arrays->insert(storage);
42 /**
43 * Clear the changes made since the last #ClearStorageChanges.
44 * This is done for *all* storages that have been registered to with
45 * #AddChangedStorage since the previous #ClearStorageChanges.
47 * This can be done in two ways:
48 * - saving the changes permanently
49 * - reverting to the previous version
50 * @param keep_changes do we save or revert the changes since the last #ClearChanges?
52 void ClearStorageChanges(bool keep_changes)
54 /* Loop over all changes arrays */
55 for (std::set<BaseStorageArray*>::iterator it = _changed_storage_arrays->begin(); it != _changed_storage_arrays->end(); it++) {
56 (*it)->ClearChanges(keep_changes);
59 /* And then clear that array */
60 _changed_storage_arrays->clear();