summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/console_cmds.cpp10
-rw-r--r--src/core/smallvec_type.hpp2
-rw-r--r--src/fios.cpp10
-rw-r--r--src/fios.h91
-rw-r--r--src/fios_gui.cpp4
5 files changed, 102 insertions, 15 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 67f3f6098..7db151d77 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -378,7 +378,7 @@ DEF_CONSOLE_CMD(ConLoad)
IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
}
- FiosFreeSavegameList();
+ _fios_items.Clear();
return true;
}
@@ -402,7 +402,7 @@ DEF_CONSOLE_CMD(ConRemove)
IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
}
- FiosFreeSavegameList();
+ _fios_items.Clear();
return true;
}
@@ -421,7 +421,7 @@ DEF_CONSOLE_CMD(ConListFiles)
IConsolePrintF(CC_DEFAULT, "%d) %s", i, _fios_items[i].title);
}
- FiosFreeSavegameList();
+ _fios_items.Clear();
return true;
}
@@ -448,7 +448,7 @@ DEF_CONSOLE_CMD(ConChangeDirectory)
IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
}
- FiosFreeSavegameList();
+ _fios_items.Clear();
return true;
}
@@ -463,7 +463,7 @@ DEF_CONSOLE_CMD(ConPrintWorkingDirectory)
/* XXX - Workaround for broken file handling */
FiosGetSavegameList(SLD_LOAD_GAME);
- FiosFreeSavegameList();
+ _fios_items.Clear();
FiosGetDescText(&path, NULL);
IConsolePrint(CC_DEFAULT, path);
diff --git a/src/core/smallvec_type.hpp b/src/core/smallvec_type.hpp
index 62de176a5..8676265d2 100644
--- a/src/core/smallvec_type.hpp
+++ b/src/core/smallvec_type.hpp
@@ -256,6 +256,8 @@ public:
/**
* Get the number of items in the list.
+ *
+ * @return The number of items in the list.
*/
inline uint Length() const
{
diff --git a/src/fios.cpp b/src/fios.cpp
index 631c88bf6..e929596f9 100644
--- a/src/fios.cpp
+++ b/src/fios.cpp
@@ -29,7 +29,7 @@
#include "safeguards.h"
/* Variables to display file lists */
-SmallVector<FiosItem, 32> _fios_items;
+FileList _fios_items;
static char *_fios_path;
static const char *_fios_path_last;
SortingBits _savegame_sort_order = SORT_BY_DATE | SORT_DESCENDING;
@@ -64,11 +64,9 @@ int CDECL CompareFiosItems(const FiosItem *da, const FiosItem *db)
return r;
}
-/** Free the list of savegames. */
-void FiosFreeSavegameList()
+FileList::~FileList()
{
- _fios_items.Clear();
- _fios_items.Compact();
+ this->Clear();
}
/**
@@ -336,7 +334,7 @@ static void FiosGetFileList(SaveLoadDialogMode mode, fios_getlist_callback_proc
{
SortingBits order = _savegame_sort_order;
_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
- QSortT(_fios_items.Begin(), _fios_items.Length(), CompareFiosItems);
+ QSortT(_fios_items.files.Begin(), _fios_items.files.Length(), CompareFiosItems);
_savegame_sort_order = order;
}
diff --git a/src/fios.h b/src/fios.h
index 4ccd1f192..0a6d3f95d 100644
--- a/src/fios.h
+++ b/src/fios.h
@@ -115,6 +115,94 @@ struct FiosItem {
char name[MAX_PATH];
};
+/** List of file information. */
+class FileList {
+public:
+ ~FileList();
+
+ /**
+ * Construct a new entry in the file list.
+ * @return Pointer to the new items to be initialized.
+ */
+ inline FiosItem *Append()
+ {
+ return this->files.Append();
+ }
+
+ /**
+ * Get the number of files in the list.
+ * @return The number of files stored in the list.
+ */
+ inline uint Length() const
+ {
+ return this->files.Length();
+ }
+
+ /**
+ * Get a pointer to the first file information.
+ * @return Address of the first file information.
+ */
+ inline const FiosItem *Begin() const
+ {
+ return this->files.Begin();
+ }
+
+ /**
+ * Get a pointer behind the last file information.
+ * @return Address behind the last file information.
+ */
+ inline const FiosItem *End() const
+ {
+ return this->files.End();
+ }
+
+ /**
+ * Get a pointer to the indicated file information. File information must exist.
+ * @return Address of the indicated existing file information.
+ */
+ inline const FiosItem *Get(uint index) const
+ {
+ return this->files.Get(index);
+ }
+
+ /**
+ * Get a pointer to the indicated file information. File information must exist.
+ * @return Address of the indicated existing file information.
+ */
+ inline FiosItem *Get(uint index)
+ {
+ return this->files.Get(index);
+ }
+
+ inline const FiosItem &operator[](uint index) const
+ {
+ return this->files[index];
+ }
+
+ /**
+ * Get a reference to the indicated file information. File information must exist.
+ * @return The requested file information.
+ */
+ inline FiosItem &operator[](uint index)
+ {
+ return this->files[index];
+ }
+
+ /** Remove all items from the list. */
+ inline void Clear()
+ {
+ this->files.Clear();
+ }
+
+ /** Compact the list down to the smallest block size boundary. */
+ inline void Compact()
+ {
+ this->files.Compact();
+ }
+
+ SmallVector<FiosItem, 32> files; ///< The list of files.
+};
+
enum SortingBits {
SORT_ASCENDING = 0,
SORT_DESCENDING = 1,
@@ -124,7 +212,7 @@ enum SortingBits {
DECLARE_ENUM_AS_BIT_SET(SortingBits)
/* Variables to display file lists */
-extern SmallVector<FiosItem, 32> _fios_items;
+extern FileList _fios_items;
extern SaveLoadDialogMode _saveload_mode;
extern SortingBits _savegame_sort_order;
@@ -134,7 +222,6 @@ void FiosGetSavegameList(SaveLoadDialogMode mode);
void FiosGetScenarioList(SaveLoadDialogMode mode);
void FiosGetHeightmapList(SaveLoadDialogMode mode);
-void FiosFreeSavegameList();
const char *FiosBrowseTo(const FiosItem *item);
StringID FiosGetDescText(const char **path, uint64 *total_free);
diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp
index 50a6711c6..b01954c55 100644
--- a/src/fios_gui.cpp
+++ b/src/fios_gui.cpp
@@ -196,7 +196,7 @@ const TextColour _fios_colours[] = {
void BuildFileList(SaveLoadDialogMode mode)
{
_fios_path_changed = true;
- FiosFreeSavegameList();
+ _fios_items.Clear();
switch (mode) {
case SLD_LOAD_SCENARIO:
@@ -327,7 +327,7 @@ public:
if (!_networking && _game_mode != GM_EDITOR && _game_mode != GM_MENU) {
DoCommandP(0, PM_PAUSED_SAVELOAD, 0, CMD_PAUSE);
}
- FiosFreeSavegameList();
+ _fios_items.Clear();
}
virtual void DrawWidget(const Rect &r, int widget) const