summaryrefslogtreecommitdiff
path: root/src/fileio_type.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/fileio_type.h')
-rw-r--r--src/fileio_type.h80
1 files changed, 68 insertions, 12 deletions
diff --git a/src/fileio_type.h b/src/fileio_type.h
index 20df8cd05..4fae7b392 100644
--- a/src/fileio_type.h
+++ b/src/fileio_type.h
@@ -22,6 +22,27 @@ enum AbstractFileType {
FT_HEIGHTMAP, ///< heightmap file
FT_INVALID = 7, ///< Invalid or unknown file type.
+ FT_NUMBITS = 3, ///< Number of bits required for storing a #AbstractFileType value.
+ FT_MASK = (1 << FT_NUMBITS) - 1, ///< Bitmask for extracting an abstract file type.
+};
+
+/** Kinds of files in each #AbstractFileType. */
+enum DetailedFileType {
+ /* Save game and scenario files. */
+ DFT_OLD_GAME_FILE, ///< Old save game or scenario file.
+ DFT_GAME_FILE, ///< Save game or scenario file.
+
+ /* Heightmap files. */
+ DFT_HEIGHTMAP_BMP, ///< BMP file.
+ DFT_HEIGHTMAP_PNG, ///< PNG file.
+
+ /* fios 'files' */
+ DFT_FIOS_DRIVE, ///< A drive (letter) entry.
+ DFT_FIOS_PARENT, ///< A parent directory entry.
+ DFT_FIOS_DIR, ///< A directory entry.
+ DFT_FIOS_DIRECT, ///< Direct filename.
+
+ DFT_INVALID = 255, ///< Unknown or invalid file.
};
/** Operation performed on the file. */
@@ -30,21 +51,56 @@ enum FileOperation {
FOP_SAVE, ///< File is being saved.
};
-/** Elements of a file system that are recognized. */
+/**
+ * Construct an enum value for #FiosType as a combination of an abstract and a detailed file type.
+ * @param abstract Abstract file type (one of #AbstractFileType).
+ * @param detailed Detailed file type (one of #DetailedFileType).
+ */
+#define MAKE_FIOS_TYPE(abstract, detailed) ((abstract) | ((detailed) << FT_NUMBITS))
+
+/**
+ * Elements of a file system that are recognized.
+ * Values are a combination of #AbstractFileType and #DetailedFileType.
+ * @see GetAbstractFileType GetDetailedFileType
+ */
enum FiosType {
- FIOS_TYPE_DRIVE,
- FIOS_TYPE_PARENT,
- FIOS_TYPE_DIR,
- FIOS_TYPE_FILE,
- FIOS_TYPE_OLDFILE,
- FIOS_TYPE_SCENARIO,
- FIOS_TYPE_OLD_SCENARIO,
- FIOS_TYPE_DIRECT,
- FIOS_TYPE_PNG,
- FIOS_TYPE_BMP,
- FIOS_TYPE_INVALID = 255,
+ FIOS_TYPE_DRIVE = MAKE_FIOS_TYPE(FT_NONE, DFT_FIOS_DRIVE),
+ FIOS_TYPE_PARENT = MAKE_FIOS_TYPE(FT_NONE, DFT_FIOS_PARENT),
+ FIOS_TYPE_DIR = MAKE_FIOS_TYPE(FT_NONE, DFT_FIOS_DIR),
+ FIOS_TYPE_DIRECT = MAKE_FIOS_TYPE(FT_NONE, DFT_FIOS_DIRECT),
+
+ FIOS_TYPE_FILE = MAKE_FIOS_TYPE(FT_SAVEGAME, DFT_GAME_FILE),
+ FIOS_TYPE_OLDFILE = MAKE_FIOS_TYPE(FT_SAVEGAME, DFT_OLD_GAME_FILE),
+ FIOS_TYPE_SCENARIO = MAKE_FIOS_TYPE(FT_SCENARIO, DFT_GAME_FILE),
+ FIOS_TYPE_OLD_SCENARIO = MAKE_FIOS_TYPE(FT_SCENARIO, DFT_OLD_GAME_FILE),
+ FIOS_TYPE_PNG = MAKE_FIOS_TYPE(FT_HEIGHTMAP, DFT_HEIGHTMAP_PNG),
+ FIOS_TYPE_BMP = MAKE_FIOS_TYPE(FT_HEIGHTMAP, DFT_HEIGHTMAP_BMP),
+
+ FIOS_TYPE_INVALID = MAKE_FIOS_TYPE(FT_INVALID, DFT_INVALID),
};
+#undef MAKE_FIOS_TYPE
+
+/**
+ * Extract the abstract file type from a #FiosType.
+ * @param fios_type Type to query.
+ * @return The Abstract file type of the \a fios_type.
+ */
+inline AbstractFileType GetAbstractFileType(FiosType fios_type)
+{
+ return static_cast<AbstractFileType>(fios_type & FT_MASK);
+}
+
+/**
+ * Extract the detailed file type from a #FiosType.
+ * @param fios_type Type to query.
+ * @return The Detailed file type of the \a fios_type.
+ */
+inline DetailedFileType GetDetailedFileType(FiosType fios_type)
+{
+ return static_cast<DetailedFileType>(fios_type >> FT_NUMBITS);
+}
+
/**
* The different kinds of subdirectories OpenTTD uses
*/