(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.
This commit is contained in:
peter1138 2007-08-03 09:08:49 +00:00
parent d6c915e6a6
commit 616eb4134e
5 changed files with 13 additions and 10 deletions

View File

@ -195,9 +195,9 @@ struct Command {
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);

View File

@ -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"

View File

@ -51,7 +51,7 @@ struct PalSpriteID {
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)

View File

@ -1019,19 +1019,20 @@ static void WriteStringsH(const char *filename)
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 @@ static void WriteStringsH(const char *filename)
"};\n", (uint)_hash
);
fprintf(out, "\n#endif /* TABLE_STRINGS_H */\n");
fclose(out);
if (CompareFiles("tmp.xxx", filename)) {

View File

@ -696,7 +696,7 @@ static char* FormatString(char* buff, const char* str, const int64* argv, uint c
* 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 @@ static char* FormatString(char* buff, const char* str, const int64* argv, uint c
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;
}