(svn r10762) -Codechange: Change enum StringIDEnum { to static const StringID = for
authorpeter1138
Fri, 03 Aug 2007 09:08:49 +0000
changeset 7393 f3d27c82fec3
parent 7392 0964cfefbe64
child 7394 baec3551d2d3
(svn r10762) -Codechange: Change enum StringIDEnum { to static const StringID = for
each STR_ entry. This avoids the need for a cast to StringID in some
places and thus better type-safety.
src/command.h
src/openttd.cpp
src/openttd.h
src/strgen/strgen.cpp
src/strings.cpp
--- a/src/command.h	Fri Aug 03 02:21:10 2007 +0000
+++ b/src/command.h	Fri Aug 03 09:08:49 2007 +0000
@@ -195,9 +195,9 @@
 static inline bool CmdFailed(CommandCost cost) { return cost.Failed(); }
 static inline bool CmdSucceeded(CommandCost cost) { return cost.Succeeded(); }
 
-static const CommandCost CMD_ERROR = CommandCost((StringID)INVALID_STRING_ID);
+static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID);
 
-#define return_cmd_error(errcode) do { return CommandCost((StringID)(errcode)); } while (0)
+#define return_cmd_error(errcode) do { return CommandCost(errcode); } while (0)
 
 /* command.cpp */
 typedef void CommandCallback(bool success, TileIndex tile, uint32 p1, uint32 p2);
--- a/src/openttd.cpp	Fri Aug 03 02:21:10 2007 +0000
+++ b/src/openttd.cpp	Fri Aug 03 09:08:49 2007 +0000
@@ -5,7 +5,6 @@
 #include "stdafx.h"
 #define VARDEF
 #include "string.h"
-#include "table/strings.h"
 #include "debug.h"
 #include "driver.h"
 #include "saveload.h"
@@ -15,6 +14,7 @@
 #include "helpers.hpp"
 
 #include "openttd.h"
+#include "table/strings.h"
 #include "strings.h"
 #include "bridge_map.h"
 #include "functions.h"
--- a/src/openttd.h	Fri Aug 03 02:21:10 2007 +0000
+++ b/src/openttd.h	Fri Aug 03 09:08:49 2007 +0000
@@ -51,7 +51,7 @@
 typedef uint16 EngineID;
 typedef uint16 UnitID;
 typedef uint16 StringID;
-#define INVALID_STRING_ID 0xFFFF
+static const StringID INVALID_STRING_ID = 0xFFFF;
 
 typedef EngineID *EngineList; ///< engine list type placeholder acceptable for C code (see helpers.cpp)
 
--- a/src/strgen/strgen.cpp	Fri Aug 03 02:21:10 2007 +0000
+++ b/src/strgen/strgen.cpp	Fri Aug 03 09:08:49 2007 +0000
@@ -1019,19 +1019,20 @@
 	out = fopen("tmp.xxx", "w");
 	if (out == NULL) fatal("can't open tmp.xxx");
 
-	fprintf(out, "enum StringIdEnum {");
+	fprintf(out, "/* This file is automatically generated. Do not modify */\n\n");
+	fprintf(out, "#ifndef TABLE_STRINGS_H\n");
+	fprintf(out, "#define TABLE_STRINGS_H\n");
 
 	lastgrp = 0;
 
 	for (i = 0; i != lengthof(_strings); i++) {
 		if (_strings[i] != NULL) {
-			fprintf(out, next == i ? "\t%s,\n" : "\n\t%s = 0x%X,\n", _strings[i]->name, i);
+			if (next != i) fprintf(out, "\n");
+			fprintf(out, "static const StringID %s = 0x%X;\n", _strings[i]->name, i);
 			next = i + 1;
 		}
 	}
 
-	fprintf(out, "};\n");
-
 	fprintf(out,
 		"\nenum {\n"
 		"\tLANGUAGE_PACK_IDENT = 0x474E414C, // Big Endian value for 'LANG' (LE is 0x 4C 41 4E 47)\n"
@@ -1039,6 +1040,8 @@
 		"};\n", (uint)_hash
 	);
 
+	fprintf(out, "\n#endif /* TABLE_STRINGS_H */\n");
+
 	fclose(out);
 
 	if (CompareFiles("tmp.xxx", filename)) {
--- a/src/strings.cpp	Fri Aug 03 02:21:10 2007 +0000
+++ b/src/strings.cpp	Fri Aug 03 09:08:49 2007 +0000
@@ -696,7 +696,7 @@
 				 *   8bit   - cargo type
 				 *   16-bit - cargo count */
 				CargoID cargo = GetInt32(&argv);
-				StringID cargo_str = (cargo == CT_INVALID) ? (StringID)STR_8838_N_A : GetCargo(cargo)->quantifier;
+				StringID cargo_str = (cargo == CT_INVALID) ? STR_8838_N_A : GetCargo(cargo)->quantifier;
 				buff = GetStringWithArgs(buff, cargo_str, argv++, last);
 				break;
 			}
@@ -852,7 +852,7 @@
 				assert(g->IsValid());
 
 				args[0] = g->index;
-				buff = GetStringWithArgs(buff, IsCustomName(g->string_id) ? g->string_id : (StringID)STR_GROUP_NAME_FORMAT, args, last);
+				buff = GetStringWithArgs(buff, IsCustomName(g->string_id) ? g->string_id : STR_GROUP_NAME_FORMAT, args, last);
 
 				break;
 			}